fixbug: role init with is_human=True was not work

This commit is contained in:
kkdev163 2024-01-08 17:45:44 +08:00
parent ce3dc74ef3
commit 6cde039f7f
2 changed files with 7 additions and 0 deletions

View file

@ -166,6 +166,9 @@ class Role(SerializationMixin, is_polymorphic_base=True):
Role.model_rebuild()
super().__init__(**data)
if data.get("is_human"):
self.llm = HumanProvider()
self.llm.system_prompt = self._get_prefix()
self._watch(data.get("watch") or [UserRequirement])

View file

@ -4,6 +4,7 @@
import pytest
from metagpt.roles.role import Role
from metagpt.llm import HumanProvider
def test_role_desc():
@ -11,6 +12,9 @@ def test_role_desc():
assert role.profile == "Sales"
assert role.desc == "Best Seller"
def test_role_human():
role = Role(is_human=True)
assert isinstance(role.llm, HumanProvider)
if __name__ == "__main__":
pytest.main([__file__, "-s"])