feat: remove Context.options

This commit is contained in:
莘权 马 2024-01-12 17:43:14 +08:00
parent 1e523f6840
commit b858cc7d83
3 changed files with 11 additions and 15 deletions

View file

@ -8,6 +8,7 @@
from typing import Optional
from metagpt.actions import Action
from metagpt.context import Context
from metagpt.logs import logger
@ -23,7 +24,7 @@ class WriteTeachingPlanPart(Action):
statement_patterns = TeachingPlanBlock.TOPIC_STATEMENTS.get(self.topic, [])
statements = []
for p in statement_patterns:
s = self.format_value(p, options=self.context.options)
s = self.format_value(p, context=self.context)
statements.append(s)
formatter = (
TeachingPlanBlock.PROMPT_TITLE_TEMPLATE
@ -67,13 +68,16 @@ class WriteTeachingPlanPart(Action):
return self.topic
@staticmethod
def format_value(value, options):
def format_value(value, context: Context):
"""Fill parameters inside `value` with `options`."""
if not isinstance(value, str):
return value
if "{" not in value:
return value
options = context.config.model_dump()
for k, v in context.kwargs:
options[k] = v # None value is allowed to override and disable the value from config.
opts = {k: v for k, v in options.items() if v is not None}
try:
return value.format(**opts)