mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-27 12:12:24 +08:00
refactor: Update agent stream processing to support 'v2' chunk format and prevent emitting empty content.
This commit is contained in:
@@ -166,12 +166,16 @@ class MoviePilotAgent:
|
|||||||
async for chunk in agent.astream(
|
async for chunk in agent.astream(
|
||||||
{"messages": messages},
|
{"messages": messages},
|
||||||
stream_mode="messages",
|
stream_mode="messages",
|
||||||
config=agent_config
|
config=agent_config,
|
||||||
|
version="v2"
|
||||||
):
|
):
|
||||||
token, metadata = chunk
|
|
||||||
# 处理流式token(过滤工具调用token,只保留模型生成的内容)
|
# 处理流式token(过滤工具调用token,只保留模型生成的内容)
|
||||||
if token and hasattr(token, "tool_call_chunks") and not token.tool_call_chunks:
|
if chunk["type"] == "messages":
|
||||||
self.stream_handler.emit(token.content)
|
token, metadata = chunk["data"]
|
||||||
|
if (token and hasattr(token, "tool_call_chunks")
|
||||||
|
and not token.tool_call_chunks):
|
||||||
|
if token.content:
|
||||||
|
self.stream_handler.emit(token.content)
|
||||||
|
|
||||||
# 发送最终消息给用户
|
# 发送最终消息给用户
|
||||||
await self.send_agent_message(
|
await self.send_agent_message(
|
||||||
|
|||||||
Reference in New Issue
Block a user