Skip to content

Commit

Permalink
remove extra value after model_validator in Role/ContextMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
shenchucheng committed Feb 2, 2024
1 parent f6824b0 commit 3125f4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions metagpt/context_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ class ContextMixin(BaseModel):

@model_validator(mode="after")
def validate_context_mixin_extra(self):
self._process_context_mixin_extra(**(self.model_extra or {}))
self._process_context_mixin_extra()
return self

def _process_context_mixin_extra(self, **kwargs):
def _process_context_mixin_extra(self):
"""Process the extra field"""
self.set_context(kwargs.get("context"))
self.set_config(kwargs.get("config"))
self.set_llm(kwargs.get("llm"))
kwargs = self.model_extra or {}
self.set_context(kwargs.pop("context", None))
self.set_config(kwargs.pop("config", None))
self.set_llm(kwargs.pop("llm", None))

def set(self, k, v, override=False):
"""Set attribute"""
Expand Down
7 changes: 4 additions & 3 deletions metagpt/roles/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,19 @@ class Role(SerializationMixin, ContextMixin, BaseModel):

@model_validator(mode="after")
def validate_role_extra(self):
self._process_role_extra(**(self.model_extra or {}))
self._process_role_extra()
return self

def _process_role_extra(self, **kwargs):
def _process_role_extra(self):
self.pydantic_rebuild_model()
kwargs = self.model_extra or {}

if self.is_human:
self.llm = HumanProvider(None)

self._check_actions()
self.llm.system_prompt = self._get_prefix()
self._watch(kwargs.get("watch") or [UserRequirement])
self._watch(kwargs.pop("watch", [UserRequirement]))

if self.latest_observed_msg:
self.recovered = True
Expand Down

0 comments on commit 3125f4c

Please sign in to comment.