tool_id
This commit is contained in:
parent
367e292854
commit
671569026e
@ -144,7 +144,7 @@ async def enhanced_generate_stream_response(
|
||||
chunk_id = 0
|
||||
message_tag = ""
|
||||
function_call = {}
|
||||
function_name = ""
|
||||
tool_id = ""
|
||||
|
||||
async for msg, metadata in agent.astream({"messages": messages}, stream_mode="messages"):
|
||||
new_content = ""
|
||||
@ -153,13 +153,15 @@ async def enhanced_generate_stream_response(
|
||||
if msg.tool_call_chunks: # 检查工具调用块
|
||||
if message_tag != "TOOL_CALL":
|
||||
message_tag = "TOOL_CALL"
|
||||
function_name = ""
|
||||
if msg.tool_call_chunks[0]["name"]:
|
||||
function_name = msg.tool_call_chunks[0]["name"]
|
||||
if function_name and msg.tool_call_chunks[0]["args"]:
|
||||
if function_name not in function_call:
|
||||
function_call[function_name] = ""
|
||||
function_call[function_name] += msg.tool_call_chunks[0]["args"]
|
||||
tool_id = msg.tool_call_chunks[0]["id"]
|
||||
if tool_id not in function_call:
|
||||
function_call[tool_id] = {
|
||||
"function_name": msg.tool_call_chunks[0]["name"],
|
||||
"arguments": ""
|
||||
}
|
||||
if tool_id and tool_id in function_call and msg.tool_call_chunks[0]["args"]:
|
||||
function_call[tool_id]["arguments"] += msg.tool_call_chunks[0]["args"]
|
||||
elif len(msg.content) > 0:
|
||||
preamble_completed.set()
|
||||
await output_queue.put(("preamble_done", None))
|
||||
@ -173,8 +175,8 @@ async def enhanced_generate_stream_response(
|
||||
("finish_reason" in msg.response_metadata and msg.response_metadata["finish_reason"] == "tool_calls") or \
|
||||
("stop_reason" in msg.response_metadata and msg.response_metadata["stop_reason"] == "tool_use")
|
||||
):
|
||||
for function_name, args in function_call.items():
|
||||
new_content = f"[{message_tag}] {function_name}\n{args}"
|
||||
for args in function_call.values():
|
||||
new_content = f"[{message_tag}] {args['function_name']}\n{args['arguments']}"
|
||||
message_tag = "TOOL_CALL_FINISH"
|
||||
elif isinstance(msg, ToolMessage) and len(msg.content) > 0:
|
||||
message_tag = "TOOL_RESPONSE"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user