mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-21 20:18:57 +08:00
fix: delete harm catalog settings for gemini (#8829)
This commit is contained in:
parent
bb781764b8
commit
0603359e2d
@ -9,8 +9,8 @@ import google.ai.generativelanguage as glm
|
|||||||
import google.generativeai as genai
|
import google.generativeai as genai
|
||||||
import requests
|
import requests
|
||||||
from google.api_core import exceptions
|
from google.api_core import exceptions
|
||||||
from google.generativeai import client
|
from google.generativeai.client import _ClientManager
|
||||||
from google.generativeai.types import ContentType, GenerateContentResponse, HarmBlockThreshold, HarmCategory
|
from google.generativeai.types import ContentType, GenerateContentResponse
|
||||||
from google.generativeai.types.content_types import to_part
|
from google.generativeai.types.content_types import to_part
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
@ -200,24 +200,16 @@ class GoogleLargeLanguageModel(LargeLanguageModel):
|
|||||||
history.append(content)
|
history.append(content)
|
||||||
|
|
||||||
# Create a new ClientManager with tenant's API key
|
# Create a new ClientManager with tenant's API key
|
||||||
new_client_manager = client._ClientManager()
|
new_client_manager = _ClientManager()
|
||||||
new_client_manager.configure(api_key=credentials["google_api_key"])
|
new_client_manager.configure(api_key=credentials["google_api_key"])
|
||||||
new_custom_client = new_client_manager.make_client("generative")
|
new_custom_client = new_client_manager.make_client("generative")
|
||||||
|
|
||||||
google_model._client = new_custom_client
|
google_model._client = new_custom_client
|
||||||
|
|
||||||
safety_settings = {
|
|
||||||
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
|
|
||||||
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
|
|
||||||
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
|
|
||||||
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
|
|
||||||
}
|
|
||||||
|
|
||||||
response = google_model.generate_content(
|
response = google_model.generate_content(
|
||||||
contents=history,
|
contents=history,
|
||||||
generation_config=genai.types.GenerationConfig(**config_kwargs),
|
generation_config=genai.types.GenerationConfig(**config_kwargs),
|
||||||
stream=stream,
|
stream=stream,
|
||||||
safety_settings=safety_settings,
|
|
||||||
tools=self._convert_tools_to_glm_tool(tools) if tools else None,
|
tools=self._convert_tools_to_glm_tool(tools) if tools else None,
|
||||||
request_options={"timeout": 600},
|
request_options={"timeout": 600},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user