fixbug: teacher role

This commit is contained in:
莘权 马 2023-08-21 10:44:40 +08:00
parent ae94b6dff8
commit 86e0e70619
5 changed files with 24 additions and 18 deletions

View file

@ -90,8 +90,11 @@ async def startup(lesson_file: str, investment: float = 3.0, n_round: int = 1, *
configs = yaml.safe_load(reader)
startup_config = ProjectConfig(**configs)
roles = UMLMetaRoleFactory.create_roles(startup_config.roles, **kwargs)
company = SoftwareCompany()
roles = UMLMetaRoleFactory.create_roles(role_configs=startup_config.roles,
options=company.options,
cost_manager=company.cost_manager,
**kwargs)
company.hire(roles)
company.invest(startup_config.startup.investment)
company.start_project(lesson, role=startup_config.startup.role,

View file

@ -77,7 +77,7 @@ async def startup(lesson_file: str, investment: float = 3.0, n_round: int = 1, *
lesson = demo_lesson
company = SoftwareCompany()
company.hire([Teacher(*args, **kwargs)])
company.hire([Teacher(options=company.options, cost_manager=company.cost_manager, *args, **kwargs)])
company.invest(investment)
company.start_project(lesson, role="Teacher", cause_by=TeachingPlanRequirement)
await company.run(n_round=1)

View file

@ -21,19 +21,22 @@ from metagpt.schema import Message
class MetaAction(Action):
def __init__(self, options: MetaActionOptions, llm=None, **kwargs):
super(MetaAction, self).__init__(options.name, kwargs.get("context"), llm=llm)
self.prompt = options.format_prompt(**kwargs)
self.options = options
def __init__(self, options, action_options: MetaActionOptions, llm=None, **kwargs):
super(MetaAction, self).__init__(options=options,
name=action_options.name,
context=kwargs.get("context"),
llm=llm)
self.prompt = action_options.format_prompt(**kwargs)
self.action_options = action_options
self.kwargs = kwargs
def __str__(self):
"""Return `topic` value when str()"""
return self.options.topic
return self.action_options.topic
def __repr__(self):
"""Show `topic` value when debug"""
return self.options.topic
return self.action_options.topic
async def run(self, messages, *args, **kwargs):
if len(messages) < 1 or not isinstance(messages[0], Message):
@ -46,11 +49,11 @@ class MetaAction(Action):
return self.rsp
def _set_result(self, rsp):
if self.options.rsp_begin_tag and self.options.rsp_begin_tag in rsp:
ix = rsp.index(self.options.rsp_begin_tag)
rsp = rsp[ix + len(self.options.rsp_begin_tag):]
if self.options.rsp_end_tag and self.options.rsp_end_tag in rsp:
ix = rsp.index(self.options.rsp_end_tag)
if self.action_options.rsp_begin_tag and self.action_options.rsp_begin_tag in rsp:
ix = rsp.index(self.action_options.rsp_begin_tag)
rsp = rsp[ix + len(self.action_options.rsp_begin_tag):]
if self.action_options.rsp_end_tag and self.action_options.rsp_end_tag in rsp:
ix = rsp.index(self.action_options.rsp_end_tag)
rsp = rsp[0:ix]
self.rsp = rsp.strip()

View file

@ -26,10 +26,10 @@ from metagpt.schema import Message
class ForkMetaRole(Role):
"""A `fork` style meta role capable of generating arbitrary roles at runtime based on a configuration file"""
def __init__(self, runtime_options, cost_manager, role_options, **kwargs):
def __init__(self, options, cost_manager, role_options, **kwargs):
"""Initialize a `fork` style meta role
:param runtime_options: System configuration
:param options: System configuration
:param cost_manager: Cost manager
:param role_options: pattern yaml file data
:param args: Parameters passed in format: `python your_script.py arg1 arg2 arg3`
@ -49,7 +49,7 @@ class ForkMetaRole(Role):
global_variables[k] = v
super(ForkMetaRole, self).__init__(
options=runtime_options,
options=options,
cost_manager=cost_manager,
name=global_variables["name"],
profile=global_variables["profile"],
@ -70,7 +70,7 @@ class ForkMetaRole(Role):
o = MetaActionOptions(**m)
o.set_default_template(opts.templates[o.template_ix])
act = MetaAction(options=o, llm=self._llm, **m)
act = MetaAction(options=options, action_options=o, llm=self._llm, **m)
actions.append(act)
self._init_actions(actions)
requirement_types = set()

View file

@ -33,7 +33,7 @@ class UMLMetaRoleFactory:
raise NotImplementedError(
f"{opt.role_type} is not implemented"
)
r = constructor(m, **kwargs)
r = constructor(role_options=m, **kwargs)
roles.append(r)
return roles