From f8617db01246a2fee2c01a95a1ea29da18a7000a Mon Sep 17 00:00:00 2001 From: dufei <33253618+Dofine-dufei@users.noreply.github.com> Date: Fri, 2 Aug 2024 10:03:43 +0800 Subject: [PATCH] fix tongyi tool calls (#6896) --- .../model_runtime/model_providers/tongyi/llm/llm.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api/core/model_runtime/model_providers/tongyi/llm/llm.py b/api/core/model_runtime/model_providers/tongyi/llm/llm.py index 6f768131fb582e..a75db78d8ce412 100644 --- a/api/core/model_runtime/model_providers/tongyi/llm/llm.py +++ b/api/core/model_runtime/model_providers/tongyi/llm/llm.py @@ -497,12 +497,13 @@ def _convert_prompt_messages_to_tongyi_messages(self, prompt_messages: list[Prom content = prompt_message.content if not content: content = ' ' - tongyi_messages.append({ + message = { 'role': 'assistant', - 'content': content if not rich_content else [{"text": content}], - 'tool_calls': [tool_call.model_dump() for tool_call in - prompt_message.tool_calls] if prompt_message.tool_calls else None - }) + 'content': content if not rich_content else [{"text": content}] + } + if prompt_message.tool_calls: + message['tool_calls'] = [tool_call.model_dump() for tool_call in prompt_message.tool_calls] + tongyi_messages.append(message) elif isinstance(prompt_message, ToolPromptMessage): tongyi_messages.append({ "role": "tool",