Support Mistral format tools

Former-commit-id: e42d0e54b7a64a3f017a09e99846d174db7b438f
This commit is contained in:
ylfeng
2024-09-18 21:45:25 +08:00
committed by hiyouga
parent ebf6a07681
commit 469c7cd462
6 changed files with 160 additions and 60 deletions

View File

@@ -157,7 +157,7 @@ class WebChatModel(ChatModel):
result = response
if isinstance(result, list):
tool_calls = [{"name": tool[0], "arguments": json.loads(tool[1])} for tool in result]
tool_calls = [{"name": tool.name, "arguments": json.loads(tool.arguments)} for tool in result]
tool_calls = json.dumps(tool_calls, indent=4, ensure_ascii=False)
output_messages = messages + [{"role": Role.FUNCTION.value, "content": tool_calls}]
bot_text = "```json\n" + tool_calls + "\n```"