Unverified Commit 344821ed authored by Chenhe Gu's avatar Chenhe Gu Committed by GitHub

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

parent 126b4c33
......@@ -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}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment