add: add role's custom config

This commit is contained in:
zhanglei 2024-04-23 17:58:19 +08:00
parent ac9a5e9ec9
commit b50a6062a1
3 changed files with 1 additions and 31 deletions

View file

@ -14,7 +14,6 @@ llm:
# See for more: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/
# Role's custom configuration
# Priority: Role's configuration > Global configuration
roles:
- role: "ProductManager" # role's className or role's role_id
llm:

View file

@ -77,7 +77,7 @@ class Config(CLIParams, YamlModel):
azure_tts_subscription_key: str = ""
azure_tts_region: str = ""
# Role's custom configuration, Priority: Role's configuration > Global configuration
# Role's custom configuration
roles: Optional[List[RoleCustomConfig]] = None
@classmethod

View file

@ -167,12 +167,6 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
if self.is_human:
self.llm = HumanProvider(None)
if self.context.config.roles:
_context, _in = self.get_custom_role_config()
if _in:
self.context = _context
self.llm = LLM(llm_config=self.context.config.llm)
self._check_actions()
self.llm.system_prompt = self._get_prefix()
self.llm.cost_manager = self.context.cost_manager
@ -246,29 +240,6 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
def _setting(self):
return f"{self.name}({self.profile})"
def get_custom_role_config(self):
"""
check and get current role's custom config
1.Check if the custom configurations exist
2.Check if the current role exist in custom configurations
3.Update corresponding configurations item by item based on custom configurations
:return:
_context:replaced the corresponding configuration context with custom config
_in:current role has custom config
"""
_context = self.context
_in = False
if self and self.context.config.roles:
for role_config in self.context.config.roles:
if (not bool(self.role_id) and self.role_id == role_config.role) or type(
self).__name__ == role_config.role:
_in = True
for key, _ in role_config.model_fields.items():
if key not in ["role", "extra_fields"]:
setattr(_context.config, key, getattr(role_config, key))
break
return _context, _in
def _check_actions(self):
"""Check actions and set llm and prefix for each action."""
self.set_actions(self.actions)