mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
fix: gemini tool call bug
This commit is contained in:
@@ -521,6 +521,7 @@ class AgentStreamExecutor:
|
|||||||
# Streaming response
|
# Streaming response
|
||||||
full_content = ""
|
full_content = ""
|
||||||
tool_calls_buffer = {} # {index: {id, name, arguments}}
|
tool_calls_buffer = {} # {index: {id, name, arguments}}
|
||||||
|
gemini_raw_parts = None # Preserve Gemini thoughtSignature for round-trip
|
||||||
stop_reason = None # Track why the stream stopped
|
stop_reason = None # Track why the stream stopped
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -612,6 +613,10 @@ class AgentStreamExecutor:
|
|||||||
if "arguments" in func:
|
if "arguments" in func:
|
||||||
tool_calls_buffer[index]["arguments"] += func["arguments"]
|
tool_calls_buffer[index]["arguments"] += func["arguments"]
|
||||||
|
|
||||||
|
# Preserve _gemini_raw_parts for Gemini thoughtSignature round-trip
|
||||||
|
if "_gemini_raw_parts" in delta:
|
||||||
|
gemini_raw_parts = delta["_gemini_raw_parts"]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_str = str(e)
|
error_str = str(e)
|
||||||
error_str_lower = error_str.lower()
|
error_str_lower = error_str.lower()
|
||||||
@@ -793,6 +798,9 @@ class AgentStreamExecutor:
|
|||||||
"input": tc.get("arguments", {})
|
"input": tc.get("arguments", {})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if gemini_raw_parts:
|
||||||
|
assistant_msg["_gemini_raw_parts"] = gemini_raw_parts
|
||||||
|
|
||||||
# Only append if content is not empty
|
# Only append if content is not empty
|
||||||
if assistant_msg["content"]:
|
if assistant_msg["content"]:
|
||||||
self.messages.append(assistant_msg)
|
self.messages.append(assistant_msg)
|
||||||
|
|||||||
@@ -294,6 +294,9 @@ class OpenAICompatibleBot:
|
|||||||
if tool_calls:
|
if tool_calls:
|
||||||
openai_msg["tool_calls"] = tool_calls
|
openai_msg["tool_calls"] = tool_calls
|
||||||
|
|
||||||
|
if msg.get("_gemini_raw_parts"):
|
||||||
|
openai_msg["_gemini_raw_parts"] = msg["_gemini_raw_parts"]
|
||||||
|
|
||||||
openai_messages.append(openai_msg)
|
openai_messages.append(openai_msg)
|
||||||
else:
|
else:
|
||||||
# Other list content, keep as is
|
# Other list content, keep as is
|
||||||
|
|||||||
Reference in New Issue
Block a user