feat: merge role_option

This commit is contained in:
莘权 马 2023-08-20 20:22:59 +08:00
parent ec20629561
commit ae94b6dff8
7 changed files with 34 additions and 19 deletions

View file

@ -12,12 +12,13 @@ from pydantic import BaseModel
from langchain.llms.base import LLM
from metagpt.actions.write_teaching_plan import WriteTeachingPlanPart
from metagpt.config import Config
from metagpt.schema import Message
class MockWriteTeachingPlanPart(WriteTeachingPlanPart):
def __init__(self, name: str = '', context=None, llm: LLM = None, topic="", language="Chinese"):
super().__init__(name, context, llm, topic, language)
def __init__(self, options, name: str = '', context=None, llm: LLM = None, topic="", language="Chinese"):
super().__init__(options, name, context, llm, topic, language)
async def _aask(self, prompt: str, system_msgs: Optional[list[str]] = None) -> str:
return f"{WriteTeachingPlanPart.DATA_BEGIN_TAG}\nprompt\n{WriteTeachingPlanPart.DATA_END_TAG}"
@ -47,7 +48,8 @@ async def mock_write_teaching_plan_part():
for i in inputs:
seed = Inputs(**i)
act = MockWriteTeachingPlanPart(name=seed.name, topic=seed.topic, language=seed.language)
options = Config().runtime_options
act = MockWriteTeachingPlanPart(options=options, name=seed.name, topic=seed.topic, language=seed.language)
await act.run([Message(content="")])
assert act.topic == seed.topic
assert str(act) == seed.topic

View file

@ -9,6 +9,8 @@ from typing import Dict
from pydantic import BaseModel
from metagpt.config import Config
from metagpt.provider.openai_api import CostManager
from metagpt.roles.fork_meta_role import ForkMetaRole
@ -79,7 +81,9 @@ def test_creat_role():
"teaching_language": "AA",
"language": "BB"
}
role = ForkMetaRole(seed.role, **kwargs)
runtime_options = Config().runtime_options
cost_manager = CostManager(options=runtime_options)
role = ForkMetaRole(runtime_options=runtime_options, cost_manager=cost_manager, role_options=seed.role, **kwargs)
assert role.action_count == 2
assert "{" not in role.profile
assert "{" not in role.goal

View file

@ -9,6 +9,8 @@
from typing import Dict, Optional
from pydantic import BaseModel
from metagpt.config import Config
from metagpt.provider.openai_api import CostManager
from metagpt.roles.teacher import Teacher
@ -42,22 +44,25 @@ def test_init():
},
{
"name": "Lily{language}",
"expect_name": "LilyChinese",
"expect_name": "Lily{language}",
"profile": "X {teaching_language}",
"expect_profile": "X English",
"expect_profile": "X {teaching_language}",
"goal": "Do {something_big}, {language}",
"expect_goal": "Do {something_big}, Chinese",
"expect_goal": "Do {something_big}, {language}",
"constraints": "Do in {key1}, {language}",
"expect_constraints": "Do in {key1}, Chinese",
"expect_constraints": "Do in {key1}, {language}",
"kwargs": {},
"desc": "aaa{language}",
"expect_desc": "aaaChinese"
"expect_desc": "aaa{language}"
},
]
for i in inputs:
seed = Inputs(**i)
teacher = Teacher(name=seed.name, profile=seed.profile, goal=seed.goal, constraints=seed.constraints,
options = Config().runtime_options
cost_manager = CostManager(options=options)
teacher = Teacher(options=options, cost_manager=cost_manager, name=seed.name, profile=seed.profile,
goal=seed.goal, constraints=seed.constraints,
desc=seed.desc, **seed.kwargs)
assert teacher.name == seed.expect_name
assert teacher.desc == seed.expect_desc