From 5e02a83b533a0a086c144b19444e2f2db0c2d73d Mon Sep 17 00:00:00 2001 From: liuzhenghua <1090179900@qq.com> Date: Tue, 16 Apr 2024 12:13:10 +0800 Subject: [PATCH] fix: the object field is empty string in some openAI api compatible model (#3506) --- .../model_providers/openai_api_compatible/llm/llm.py | 4 +++- 1 file changed, 3 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 4886b62d72..54f4405de1 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 @@ -150,6 +150,8 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel): except json.JSONDecodeError as e: raise CredentialsValidateFailedError('Credentials validation failed: JSON decode error') + if (completion_type is LLMMode.CHAT and json_result['object'] == ''): + json_result['object'] = 'chat.completion' if (completion_type is LLMMode.CHAT and ('object' not in json_result or json_result['object'] != 'chat.completion')): raise CredentialsValidateFailedError( @@ -807,4 +809,4 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel): function=function ) - return tool_call \ No newline at end of file + return tool_call