From aa6d2e3035c002be7295312fd1255ce5cf141d8f Mon Sep 17 00:00:00 2001 From: aniaan Date: Thu, 18 Apr 2024 16:54:16 +0800 Subject: [PATCH] fix(openai_api_compatible): fixing the error when converting chunk to json (#3570) --- .../model_providers/openai_api_compatible/llm/llm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 e86755d693..b921e4b5aa 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 @@ -154,7 +154,7 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel): json_result['object'] = 'chat.completion' elif (completion_type is LLMMode.COMPLETION and json_result['object'] == ''): json_result['object'] = 'text_completion' - + if (completion_type is LLMMode.CHAT and ('object' not in json_result or json_result['object'] != 'chat.completion')): raise CredentialsValidateFailedError( @@ -425,6 +425,7 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel): finish_reason = 'Unknown' for chunk in response.iter_lines(decode_unicode=True, delimiter=delimiter): + chunk = chunk.strip() if chunk: # ignore sse comments if chunk.startswith(':'):