Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 添加收据助手和教程助手文档 #19

Merged
merged 3 commits into from
Nov 19, 2023
Merged

Conversation

Stitch-z
Copy link
Contributor

No description provided.

@better629
Copy link
Collaborator

LGTM

@better629 better629 merged commit 11c15cc into geekan:main Nov 19, 2023
Comment on lines +51 to +83
2. 重写 `_react` 方法。`_react` 方法循环执行 `think` 和 `action` 操作,当没有下一步 `action` 去 `todo` 时就结束循环。执行完所有的 `action` 后可以做最后的操作,这里是把拼接完的教程内容写成markdown文件。

```python
async def _react(self) -> Message:
"""Execute the assistant's think and actions.

Returns:
A message containing the final result of the assistant's actions.
"""
while True:
await self._think()
if self._rc.todo is None:
break
msg = await self._act()
root_path = TUTORIAL_PATH / datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
await File.write(root_path, f"{self.main_title}.md", self.total_content.encode('utf-8'))
return msg
```

3. 重写 `_think `方法,`_think` 方法是思考下一步的执行。如果 `todo` 为空,即没有下一步操作要执行,则设置 `state` 为 `0` 。如果执行下一步后 `state` 会超出了初始化的 `states` 长度,说明目前已经是最后一步了,将 `todo` 设为空使得在 `_react` 方法会跳出循环,不再执行 `think` 和 `action`,否则 `state` 加 `1` 记录。

```python
async def _think(self) -> None:
"""Determine the next action to be taken by the role."""
if self._rc.todo is None:
self._set_state(0)
return

if self._rc.state + 1 < len(self._states):
self._set_state(self._rc.state + 1)
else:
self._rc.todo = None
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两点的逻辑在不久前的一个更新中已经封装到Role里面了,可以省略部分。只需要在__init__的时候加_set_react_mode(react_mode="by_order"),参考调研员https://docs.deepwisdom.ai/zhcn/guide/use_cases/agent/researcher.html
可以的话英文已经MG源代码那边最好也改下 @Stitch-z

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants