mistral, openai: allow anthropic-style messages in message histories (#20565)

This commit is contained in:
ccurme
2024-04-17 15:55:45 -04:00
committed by GitHub
parent 7a7851aa06
commit 2238490069
3 changed files with 76 additions and 21 deletions

View File

@@ -283,9 +283,16 @@ def _convert_message_to_mistral_chat_message(
tool_calls.append(chunk)
else:
pass
if tool_calls and message.content:
# Assistant message must have either content or tool_calls, but not both.
# Some providers may not support tool_calls in the same message as content.
# This is done to ensure compatibility with messages from other providers.
content: Any = ""
else:
content = message.content
return {
"role": "assistant",
"content": message.content,
"content": content,
"tool_calls": tool_calls,
}
elif isinstance(message, SystemMessage):