matching openai tool result spec

This commit is contained in:
andrewmjc 2024-07-02 16:57:13 -06:00
parent c4e11e03d7
commit e07b110b47
2 changed files with 17 additions and 4 deletions

View file

@ -328,6 +328,8 @@ def _gemini_convert_messages_with_history(messages: list) -> List[ContentType]:
user_message_types = {"user", "system"}
contents: List[ContentType] = []
last_message_with_tool_calls = None
msg_i = 0
try:
while msg_i < len(messages):
@ -383,6 +385,7 @@ def _gemini_convert_messages_with_history(messages: list) -> List[ContentType]:
messages[msg_i]["tool_calls"]
)
)
last_message_with_tool_calls = messages[msg_i]
else:
assistant_text = (
messages[msg_i].get("content") or ""
@ -397,7 +400,7 @@ def _gemini_convert_messages_with_history(messages: list) -> List[ContentType]:
## APPEND TOOL CALL MESSAGES ##
if msg_i < len(messages) and messages[msg_i]["role"] == "tool":
_part = convert_to_gemini_tool_call_result(messages[msg_i])
_part = convert_to_gemini_tool_call_result(messages[msg_i], last_message_with_tool_calls)
contents.append(ContentType(parts=[_part])) # type: ignore
msg_i += 1
if msg_i == init_msg_i: # prevent infinite loops