feat: 删掉meta role相关代码

This commit is contained in:
莘权 马 2023-08-26 22:08:45 +08:00
parent cc89f3b726
commit 2574ecaecf
9 changed files with 0 additions and 623 deletions

View file

@ -1,51 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/8/8
@Author : mashenquan
@File : test_meta_action.py
"""
from typing import Dict
from pydantic import BaseModel
from metagpt.actions.meta_action import MetaAction
from metagpt.roles.uml_meta_role_options import MetaActionOptions
def test_meta_action_create():
class Inputs(BaseModel):
options: Dict
kwargs: Dict
expect_class_name: str
expect_prompt: str
inputs = [
{
"options": {
"topic": "TOPIC_A",
"name": "A",
"language": "XX",
"template_ix": 0,
"statements": ["Statement A", "Statement B"],
"template": "{statements}",
"rsp_begin_tag": "",
"rsp_end_tag": ""
},
"kwargs": {},
"expect_class_name": "TOPIC_A",
"expect_prompt": "\n".join(["Statement A", "Statement B"]),
}
]
for i in inputs:
seed = Inputs(**i)
opt = MetaActionOptions(**seed.options)
act = MetaAction(opt, **seed.kwargs)
assert seed.expect_prompt == act.prompt
t = MetaAction.get_action_type(seed.expect_class_name)
assert t.__name__ == seed.expect_class_name
if __name__ == '__main__':
test_meta_action_create()

View file

@ -1,94 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/8/8
@Author : mashenquan
@File : test_fork_meta_role.py
"""
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
def test_creat_role():
class Inputs(BaseModel):
role: Dict
action_count: int
inputs = [
{
"role": {
"role_type": "fork",
"name": "Lily",
"profile": "{teaching_language} Teacher",
"goal": "writing a {language} teaching plan part by part",
"constraints": "writing in {language}",
"role": "You are a {teaching_language} Teacher, named Lily, your goal is writing a {"
"teaching_language} teaching plan part by part, and the constraint is writing in {language}.",
"desc": "",
"output_filename": "teaching_plan_demo.md",
"requirement": ["TeachingPlanRequirement"],
"templates": [
"Do not refer to the context of the previous conversation records, start the conversation "
"anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"["
"LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" "
"defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the "
"format requirements for your responses;\n\t\"Constraint\" defines the conditions that your "
"responses must comply with.\n\n{statements}\nConstraint: Writing in {language}.\nAnswer options: "
"Encloses the lesson title with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" tags.\n["
"LESSON_BEGIN]\n{lesson}\n[LESSON_END]",
"Do not refer to the context of the previous conversation records, start the conversation "
"anew.\n\nFormation: \"Capacity and role\" defines the role you are currently playing;\n\t\"["
"LESSON_BEGIN]\" and \"[LESSON_END]\" tags enclose the content of textbook;\n\t\"Statement\" "
"defines the work detail you need to complete at this stage;\n\t\"Answer options\" defines the "
"format requirements for your responses;\n\t\"Constraint\" defines the conditions that your "
"responses must comply with.\n\nCapacity and role: {role}\nStatement: Write the \"{topic}\" part "
"of teaching plan, WITHOUT ANY content unrelated to \"{topic}\"!!\n{statements}\nAnswer options: "
"Enclose the teaching plan content with \"[TEACHING_PLAN_BEGIN]\" and \"[TEACHING_PLAN_END]\" "
"tags.\nAnswer options: Using proper markdown format from second-level header "
"format.\nConstraint: Writing in {language}.\n[LESSON_BEGIN]\n{lesson}\n[LESSON_END] "
],
"actions": [
{
"name": "",
"topic": "Title",
"language": "Chinese",
"statements": [
"Statement: Find and return the title of the lesson only with \"# \" prefixed, without "
"anything else."],
"template_ix": 0},
{
"name": "",
"topic": "Teaching Hours",
"language": "Chinese",
"statements": [],
"template_ix": 1,
"rsp_begin_tag": "[TEACHING_PLAN_BEGIN]",
"rsp_end_tag": "[TEACHING_PLAN_END]"}
]
},
"action_count": 2
}
]
for i in inputs:
seed = Inputs(**i)
kwargs = {
"teaching_language": "AA",
"language": "BB"
}
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
assert "{" not in role.constraints
if __name__ == '__main__':
test_creat_role()

View file

@ -1,61 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/8/8
@Author : mashenquan
@File : test_uml_meta_role_factory.py
"""
from typing import List, Dict
from pydantic import BaseModel
from metagpt.roles.uml_meta_role_factory import UMLMetaRoleFactory
def test_create_roles():
class Inputs(BaseModel):
roles: List
kwargs: Dict
inputs = [
{
"roles": [
{
"role_type": "fork",
"name": "Lily",
"profile": "{teaching_language} Teacher",
"goal": "writing a {language} teaching plan part by part",
"constraints": "writing in {language}",
"role": "You are a {teaching_language} Teacher, named Lily.",
"desc": "",
"output_filename": "teaching_plan_demo.md",
"requirement": ["TeachingPlanRequirement"],
"templates": ["Do 1 {statements}", "Do 2 {statements}"],
"actions": [
{
"name": "",
"topic": "Title",
"language": "Chinese",
"statements": ["statement 1", "statement 2"]}
],
"template_ix": 0
}
],
"kwargs": {
"teaching_language": "AA",
"language": "BB",
}
}
]
for i in inputs:
seed = Inputs(**i)
roles = UMLMetaRoleFactory.create_roles(seed.roles, **seed.kwargs)
assert len(roles) == 1
assert "{" not in roles[0].profile
assert "{" not in roles[0].goal
assert roles[0].action_count == 1
if __name__ == '__main__':
test_create_roles()

View file

@ -1,40 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/8/8
@Author : mashenquan
@File : test_uml_meta_role_options.py
"""
from typing import List
from pydantic import BaseModel
from metagpt.roles.uml_meta_role_options import MetaActionOptions
def test_set_default_template():
class Inputs(BaseModel):
statements: List
template: str
expect_prompt: str
inputs = [
{
"statements": ["Statement: 1", "Statement: 2"],
"template": "{statements}",
"expect_prompt": "Statement: 1\nStatement: 2"
}
]
for i in inputs:
seed = Inputs(**i)
opt = MetaActionOptions(topic="", statements=seed.statements)
assert opt.template == ""
opt.set_default_template(seed.template)
assert opt.template == seed.template
kwargs = {}
assert opt.format_prompt(**kwargs) == seed.expect_prompt
if __name__ == '__main__':
test_set_default_template()