mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-01 01:41:59 +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(
|
||||
{"messages": messages},
|
||||
stream_mode="messages",
|
||||
config=agent_config
|
||||
config=agent_config,
|
||||
version="v2"
|
||||
):
|
||||
token, metadata = chunk
|
||||
# 处理流式token(过滤工具调用token,只保留模型生成的内容)
|
||||
if token and hasattr(token, "tool_call_chunks") and not token.tool_call_chunks:
|
||||
self.stream_handler.emit(token.content)
|
||||
if chunk["type"] == "messages":
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user