fix: webchat show tool call

This commit is contained in:
Soulter
2025-06-29 21:35:39 +08:00
parent 5e1e2d1a4f
commit 8203fdb4f0
2 changed files with 6 additions and 12 deletions
@@ -163,7 +163,11 @@ class LLMRequestSubStage(Stage):
if resp.type == "tool_call_result":
continue # 跳过工具调用结果
if resp.type == "tool_call":
if self.streaming_response:
# 用来标记流式响应需要分节
yield MessageChain(chain=[], type="break")
if self.show_tool_use or event.get_platform_name() == "webchat":
resp.data["chain"].type = "tool_call"
await event.send(resp.data["chain"])
continue
@@ -186,9 +190,6 @@ class LLMRequestSubStage(Stage):
yield resp.data["chain"] # MessageChain
if tool_loop_agent.done():
break
if self.streaming_response:
# 用来标记流式响应结束
yield MessageChain(chain=[], type="break")
except Exception as e:
logger.error(traceback.format_exc())
@@ -35,6 +35,7 @@ class WebChatMessageEvent(AstrMessageEvent):
"cid": cid,
"data": data,
"streaming": streaming,
"chain_type": message.type,
}
)
elif isinstance(comp, Image):
@@ -96,14 +97,6 @@ class WebChatMessageEvent(AstrMessageEvent):
return data
async def send(self, message: MessageChain):
await web_chat_back_queue.put(
{
"type": "end",
"data": "",
"streaming": False,
"cid": self.session_id.split("!")[-1],
}
)
await WebChatMessageEvent._send(message, session_id=self.session_id)
await web_chat_back_queue.put(
{
@@ -118,7 +111,7 @@ class WebChatMessageEvent(AstrMessageEvent):
async def send_streaming(self, generator, use_fallback: bool = False):
final_data = ""
async for chain in generator:
if chain.type == "break":
if chain.type == "break" and final_data:
# 分割符
await web_chat_back_queue.put(
{