mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 13:28:11 +08:00
fix: openai function call
This commit is contained in:
@@ -339,6 +339,7 @@ class AgentStreamExecutor:
|
|||||||
tool_result_block = {
|
tool_result_block = {
|
||||||
"type": "tool_result",
|
"type": "tool_result",
|
||||||
"tool_use_id": tool_call["id"],
|
"tool_use_id": tool_call["id"],
|
||||||
|
"name": tool_call["name"], # Add function name for Gemini compatibility
|
||||||
"content": result_content
|
"content": result_content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,15 +230,31 @@ class OpenAICompatibleBot:
|
|||||||
if isinstance(content, list):
|
if isinstance(content, list):
|
||||||
# Check if this is a tool result message (user role with tool_result blocks)
|
# Check if this is a tool result message (user role with tool_result blocks)
|
||||||
if role == "user" and any(block.get("type") == "tool_result" for block in content):
|
if role == "user" and any(block.get("type") == "tool_result" for block in content):
|
||||||
# Convert each tool_result block to a separate tool message
|
# Separate text content and tool_result blocks
|
||||||
|
text_parts = []
|
||||||
|
tool_results = []
|
||||||
|
|
||||||
for block in content:
|
for block in content:
|
||||||
if block.get("type") == "tool_result":
|
if block.get("type") == "text":
|
||||||
|
text_parts.append(block.get("text", ""))
|
||||||
|
elif block.get("type") == "tool_result":
|
||||||
|
tool_results.append(block)
|
||||||
|
|
||||||
|
# First, add tool result messages (must come immediately after assistant with tool_calls)
|
||||||
|
for block in tool_results:
|
||||||
openai_messages.append({
|
openai_messages.append({
|
||||||
"role": "tool",
|
"role": "tool",
|
||||||
"tool_call_id": block.get("tool_use_id"),
|
"tool_call_id": block.get("tool_use_id"),
|
||||||
"content": block.get("content", "")
|
"content": block.get("content", "")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Then, add text content as a separate user message if present
|
||||||
|
if text_parts:
|
||||||
|
openai_messages.append({
|
||||||
|
"role": "user",
|
||||||
|
"content": " ".join(text_parts)
|
||||||
|
})
|
||||||
|
|
||||||
# Check if this is an assistant message with tool_use blocks
|
# Check if this is an assistant message with tool_use blocks
|
||||||
elif role == "assistant":
|
elif role == "assistant":
|
||||||
# Separate text content and tool_use blocks
|
# Separate text content and tool_use blocks
|
||||||
|
|||||||
Reference in New Issue
Block a user