feat: A definition has been provided for the return value of _think: returning false indicates that further reasoning cannot continue.

This commit is contained in:
莘权 马 2023-08-23 15:53:33 +08:00
parent 9395d9f7dc
commit 7dd02ae4b1
4 changed files with 21 additions and 8 deletions

View file

@ -10,6 +10,8 @@
For more about `fork` node in activity diagrams, see: `https://www.uml-diagrams.org/activity-diagrams.html`
This file defines a `fork` style meta role capable of generating arbitrary roles at runtime based on a
configuration file.
@Modified By: mashenquan, 2023/8/22. A definition has been provided for the return value of _think: returning false indicates that further reasoning cannot continue.
"""
import re
@ -82,12 +84,13 @@ class ForkMetaRole(Role):
"""Everything will be done part by part."""
if self._rc.todo is None:
self._set_state(0)
return
return True
if self._rc.state + 1 < len(self._states):
self._set_state(self._rc.state + 1)
else:
self._rc.todo = None
return False
async def _react(self) -> Message:
ret = Message(content="")

View file

@ -1,4 +1,8 @@
#!/usr/bin/env python
"""
@Modified By: mashenquan, 2023/8/22. A definition has been provided for the return value of _think: returning false indicates that further reasoning cannot continue.
"""
import asyncio
@ -40,15 +44,16 @@ class Researcher(Role):
if language not in ("en-us", "zh-cn"):
logger.warning(f"The language `{language}` has not been tested, it may not work.")
async def _think(self) -> None:
async def _think(self) -> bool:
if self._rc.todo is None:
self._set_state(0)
return
return True
if self._rc.state + 1 < len(self._states):
self._set_state(self._rc.state + 1)
else:
self._rc.todo = None
return False
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")

View file

@ -7,6 +7,7 @@
@Modified By: mashenquan, 2023-8-7, :class:`Role` + properties.
@Modified By: mashenquan, 2023/8/20. Remove global configuration `CONFIG`, enable configuration support for business isolation;
Change cost control from global to company level.
@Modified By: mashenquan, 2023/8/22. A definition has been provided for the return value of _think: returning false indicates that further reasoning cannot continue.
"""
from __future__ import annotations
@ -192,12 +193,12 @@ class Role:
return self._setting.desc
return PREFIX_TEMPLATE.format(**self._setting.dict())
async def _think(self) -> None:
"""思考要做什么决定下一步的action"""
async def _think(self) -> bool:
"""Consider what to do and decide on the next course of action. Return false if nothing can be done."""
if len(self._actions) == 1:
# 如果只有一个动作,那就只能做这个
self._set_state(0)
return
return True
prompt = self._get_prefix()
prompt += STATE_TEMPLATE.format(history=self._rc.history, states="\n".join(self._states),
n_states=len(self._states) - 1)
@ -207,6 +208,7 @@ class Role:
logger.warning(f'Invalid answer of state, {next_state=}')
next_state = "0"
self._set_state(int(next_state))
return True
async def _act(self) -> Message:
# prompt = self.get_prefix()

View file

@ -4,6 +4,8 @@
@Time : 2023/7/27
@Author : mashenquan
@File : teacher.py
@Modified By: mashenquan, 2023/8/22. A definition has been provided for the return value of _think: returning false indicates that further reasoning cannot continue.
"""
@ -31,16 +33,17 @@ class Teacher(Role):
self._init_actions(actions)
self._watch({TeachingPlanRequirement})
async def _think(self) -> None:
async def _think(self) -> bool:
"""Everything will be done part by part."""
if self._rc.todo is None:
self._set_state(0)
return
return True
if self._rc.state + 1 < len(self._states):
self._set_state(self._rc.state + 1)
else:
self._rc.todo = None
return False
async def _react(self) -> Message:
ret = Message(content="")