fix: differentiate prompts fields based on function_calling_type (#5880)

This commit is contained in:
耐小心 2024-07-12 11:07:38 +08:00 committed by GitHub
parent f46792334c
commit d7a6f25c63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -616,10 +616,11 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
message = cast(AssistantPromptMessage, message)
message_dict = {"role": "assistant", "content": message.content}
if message.tool_calls:
# message_dict["tool_calls"] = [helper.dump_model(PromptMessageFunction(function=tool_call)) for tool_call
# in
# message.tool_calls]
function_calling_type = credentials.get('function_calling_type', 'no_call')
if function_calling_type == 'tool_call':
message_dict["tool_calls"] = [tool_call.dict() for tool_call in
message.tool_calls]
elif function_calling_type == 'function_call':
function_call = message.tool_calls[0]
message_dict["function_call"] = {
"name": function_call.function.name,
@ -630,13 +631,16 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
message_dict = {"role": "system", "content": message.content}
elif isinstance(message, ToolPromptMessage):
message = cast(ToolPromptMessage, message)
# message_dict = {
# "role": "tool",
# "content": message.content,
# "tool_call_id": message.tool_call_id
# }
function_calling_type = credentials.get('function_calling_type', 'no_call')
if function_calling_type == 'tool_call':
message_dict = {
"role": "tool" if credentials and credentials.get('function_calling_type', 'no_call') == 'tool_call' else "function",
"role": "tool",
"content": message.content,
"tool_call_id": message.tool_call_id
}
elif function_calling_type == 'function_call':
message_dict = {
"role": "function",
"content": message.content,
"name": message.tool_call_id
}