fix: in the localagent.py yield MessageChunk add agr tool_calls,and After calling the "tool_calls", the first returned body data will be concatenated.

This commit is contained in:
Dong_master
2025-08-12 11:25:37 +08:00
parent 9f22b8b585
commit e744e9c4ef
2 changed files with 7 additions and 0 deletions

View File

@@ -248,6 +248,7 @@ class ModelScopeChatCompletions(requester.ProviderAPIRequester):
if hasattr(chunk, 'choices') and chunk.choices:
choice = chunk.choices[0]
delta = choice.delta.model_dump() if hasattr(choice, 'delta') else {}
print(delta)
finish_reason = getattr(choice, 'finish_reason', None)
else:
delta = {}

View File

@@ -155,6 +155,7 @@ class LocalAgentRunner(runner.RequestRunner):
yield llm_entities.MessageChunk(
role=last_role,
content=accumulated_content, # 输出所有累积内容
tool_calls=list(tool_calls_map.values()) if (tool_calls_map and msg.is_final) else None,
is_final=msg.is_final,
)
@@ -166,6 +167,7 @@ class LocalAgentRunner(runner.RequestRunner):
)
pending_tool_calls = final_msg.tool_calls
first_content = final_msg.content
req_messages.append(final_msg)
@@ -222,6 +224,10 @@ class LocalAgentRunner(runner.RequestRunner):
if msg.role:
last_role = msg.role
# 第一次请求工具调用时的内容
if msg_idx == 1:
accumulated_content =first_content if first_content is not None else accumulated_content
# 累积内容
if msg.content:
accumulated_content += msg.content