安全访问,同时兼容 dict 和对象两种类型。这样即使某个 chunk 缺少 name 字段也不会崩溃。
This commit is contained in:
parent
314a693793
commit
b1b98caad7
@ -102,10 +102,12 @@ async def enhanced_generate_stream_response(
|
|||||||
message_tag = "TOOL_CALL"
|
message_tag = "TOOL_CALL"
|
||||||
if config.tool_response:
|
if config.tool_response:
|
||||||
for tool_call_chunk in msg.tool_call_chunks:
|
for tool_call_chunk in msg.tool_call_chunks:
|
||||||
if tool_call_chunk["name"]:
|
chunk_name = tool_call_chunk.get("name") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "name", None)
|
||||||
new_content = f"[{message_tag}] {tool_call_chunk['name']}\n"
|
chunk_args = tool_call_chunk.get("args") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "args", None)
|
||||||
if tool_call_chunk['args']:
|
if chunk_name:
|
||||||
new_content += tool_call_chunk['args']
|
new_content = f"[{message_tag}] {chunk_name}\n"
|
||||||
|
if chunk_args:
|
||||||
|
new_content += chunk_args
|
||||||
# 处理文本内容
|
# 处理文本内容
|
||||||
elif msg.content:
|
elif msg.content:
|
||||||
preamble_completed.set()
|
preamble_completed.set()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user