Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

enforce utf-8 encoding for provider response (#1973)

Chenhe Gu344821ed357e
diff --git a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py
index 338c655110c..b92b6dce3ff 100644
--- a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py
+++ b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py
@@ -168,7 +168,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
type=ParameterType.FLOAT,
default=float(credentials.get('temperature', 0.7)),
min=0,
- max=2
+ max=2,
+ precision=2
),
ParameterRule(
name=DefaultParameterName.TOP_P.value,
@@ -176,7 +177,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
type=ParameterType.FLOAT,
default=float(credentials.get('top_p', 1)),
min=0,
- max=1
+ max=1,
+ precision=2
),
ParameterRule(
name="top_k",
@@ -246,7 +248,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
:return: full response or stream response chunk generator result
"""
headers = {
- 'Content-Type': 'application/json'
+ 'Content-Type': 'application/json',
+ 'Accept-Charset': 'utf-8',
}
api_key = credentials.get('api_key')
@@ -298,6 +301,9 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
stream=stream
)
+ if response.encoding is None or response.encoding == 'ISO-8859-1':
+ response.encoding = 'utf-8'
+
if response.status_code != 200:
raise InvokeError(f"API request failed with status code {response.status_code}: {response.text}")