Skip to content

fix: 修复 chapter4/chapter7/chapter8 多个代码问题#482

Open
zichuanxu wants to merge 1 commit intodatawhalechina:mainfrom
zichuanxu:fix/issue-413-425-400-478
Open

fix: 修复 chapter4/chapter7/chapter8 多个代码问题#482
zichuanxu wants to merge 1 commit intodatawhalechina:mainfrom
zichuanxu:fix/issue-413-425-400-478

Conversation

@zichuanxu
Copy link
Copy Markdown

Summary

修复以下Issue报告的代码问题:

Changes

code/chapter4/llm_client.py

# 添加空 choices 检查
for chunk in response:
    if not chunk.choices:  # 新增
        continue
    content = chunk.choices[0].delta.content or ""

code/chapter7/my_simple_agent.py

# 5处修复:将 response 改为 response.content
- Message(response, "assistant") → Message(response.content, "assistant")
- return responsereturn response.content
- _parse_tool_calls(response) → _parse_tool_calls(response.content)
- clean_response = responseclean_response = response.content
- final_response = responsefinal_response = response.content

code/chapter7/my_react_agent.py

# 修复参数漏传
- super().__init__(name, llm, system_prompt, config)
+ super().__init__(name, llm, tool_registry, system_prompt, config)

docs/chapter8/*.md

# 移除多余的 self.store 参数
- WorkingMemory(self.config, self.store)  # 修复前
+ WorkingMemory(self.config)  # 修复后
# (EpisodicMemory, SemanticMemory, PerceptualMemory 同理)

Test plan

  • 验证 llm_client.py 流式响应在 choices 为空时不再崩溃
  • 验证 my_simple_agent.py 正常处理 LLMResponse 对象
  • 验证 my_react_agent.py 初始化时 tool_registry 正确传递
  • 验证文档代码示例与类定义一致

🤖 Generated with Claude Code

修复以下Issue:
- Issue datawhalechina#425: llm_client.py 流式响应空choices导致IndexError
  添加 chunk.choices 空检查

- Issue datawhalechina#413: my_simple_agent.py LLMResponse类型错误
  将 response 改为 response.content (5处修复)

- Issue datawhalechina#400: my_react_agent.py super().__init__参数漏传
  添加缺失的 tool_registry 参数

- Issue datawhalechina#478: 文档中 WorkingMemory 等调用参数与定义不一致
  移除多余的 self.store 参数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jjyaoao
Copy link
Copy Markdown
Collaborator

jjyaoao commented Apr 10, 2026

你好,请问有验证过吗,没问题的话我来合入

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.

2 participants