Skip to content

fix: 修复第七章 MySimpleAgent.stream_run 流式输出重复打印#639

Open
jianglong-nie wants to merge 1 commit into
datawhalechina:mainfrom
jianglong-nie:chapter7-pr
Open

fix: 修复第七章 MySimpleAgent.stream_run 流式输出重复打印#639
jianglong-nie wants to merge 1 commit into
datawhalechina:mainfrom
jianglong-nie:chapter7-pr

Conversation

@jianglong-nie

Copy link
Copy Markdown

问题

运行 code/chapter7/test_simple_agent.py「测试3:流式响应」时,
流式输出出现逐段叠词,如"用人工智能人工智能"。

根因

MySimpleAgent.stream_run() 通过 self.llm.stream_invoke() → HelloAgentsLLM.think() 输出,
而 think() 内部已经 print,stream_run() 又 print 了一次,
导致每个流式 chunk 被打印两遍。

修复

删除 stream_run() 中多余的 print(chunk, ...)(7.4.1 节代码文件与正文各一处)。

备注

另发现 7.x 节两处直接调用 llm.think() 的示例(正文约 442、1648 行)
存在同类重复打印问题,根源是 think() 的打印副作用,建议后续单独处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant