fix: 修复第七章 MySimpleAgent.stream_run 流式输出重复打印#639
Open
jianglong-nie wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
运行 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() 的打印副作用,建议后续单独处理。