Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

feat: + unit test

θŽ˜ζƒ 马76ea924a0512
diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py
index 1d65a7f26..68baeccf5 100644
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@ -168,6 +168,11 @@ class Role:
"""Return role `constraints`, read only"""
return self._setting.constraints
+ @property
+ def action_count(self):
+ """Return number of action"""
+ return len(self._actions)
+
def _get_prefix(self):
"""θŽ·ε–θ§’θ‰²ε‰ηΌ€"""
if self._setting.desc:
diff --git a/tests/metagpt/roles/test_uml_meta_role_factory.py b/tests/metagpt/roles/test_uml_meta_role_factory.py
new file mode 100644
index 000000000..f59a30611
--- /dev/null
+++ b/tests/metagpt/roles/test_uml_meta_role_factory.py
@@ -0,0 +1,61 @@
+#!/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()