refine code: gloabl context to CONTEXT

This commit is contained in:
geekan 2024-01-10 13:56:02 +08:00
parent ba6793383f
commit f5bb850f25
18 changed files with 85 additions and 85 deletions

View file

@ -144,7 +144,7 @@ class ContextMixin(BaseModel):
"""Role context: role context > context"""
if self._context:
return self._context
return context
return CONTEXT
@context.setter
def context(self, context: Context):
@ -153,4 +153,4 @@ class ContextMixin(BaseModel):
# Global context, not in Env
context = Context()
CONTEXT = Context()

View file

@ -9,11 +9,11 @@
from typing import Optional
from metagpt.configs.llm_config import LLMType
from metagpt.context import context
from metagpt.context import CONTEXT
from metagpt.provider.base_llm import BaseLLM
def LLM(name: Optional[str] = None, provider: LLMType = LLMType.OPENAI) -> BaseLLM:
"""get the default llm provider if name is None"""
# context.use_llm(name=name, provider=provider)
return context.llm(name=name, provider=provider)
return CONTEXT.llm(name=name, provider=provider)

View file

@ -22,7 +22,7 @@ from pydantic import Field
from metagpt.actions.skill_action import ArgumentsParingAction, SkillAction
from metagpt.actions.talk_action import TalkAction
from metagpt.context import context
from metagpt.context import CONTEXT
from metagpt.learn.skill_loader import SkillsDeclaration
from metagpt.logs import logger
from metagpt.memory.brain_memory import BrainMemory
@ -48,7 +48,7 @@ class Assistant(Role):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.constraints = self.constraints.format(language=kwargs.get("language") or context.kwargs.language)
self.constraints = self.constraints.format(language=kwargs.get("language") or CONTEXT.kwargs.language)
async def think(self) -> bool:
"""Everything will be done part by part."""
@ -56,7 +56,7 @@ class Assistant(Role):
if not last_talk:
return False
if not self.skills:
skill_path = Path(context.kwargs.SKILL_PATH) if context.kwargs.SKILL_PATH else None
skill_path = Path(CONTEXT.kwargs.SKILL_PATH) if CONTEXT.kwargs.SKILL_PATH else None
self.skills = await SkillsDeclaration.load(skill_yaml_file_name=skill_path)
prompt = ""