mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-21 14:05:17 +02:00
fix tests
This commit is contained in:
parent
d2233beff4
commit
76d05e44f4
6 changed files with 34 additions and 16 deletions
|
|
@ -24,7 +24,6 @@ class TalkAction(Action):
|
|||
def agent_description(self):
|
||||
return self.g_context.kwargs["agent_description"]
|
||||
|
||||
@property
|
||||
def language(self):
|
||||
return self.g_context.kwargs["language"] or config.language
|
||||
|
||||
|
|
@ -42,7 +41,7 @@ class TalkAction(Action):
|
|||
prompt += (
|
||||
"If the information is insufficient, you can search in the historical conversation or knowledge above.\n"
|
||||
)
|
||||
language = self.language
|
||||
language = self.language()
|
||||
prompt += (
|
||||
f"Answer the following questions strictly in {language}, and the answers must follow the Markdown format.\n "
|
||||
f"{self.context}"
|
||||
|
|
@ -56,7 +55,7 @@ class TalkAction(Action):
|
|||
"{role}": self.agent_description or "",
|
||||
"{history}": self.history_summary or "",
|
||||
"{knowledge}": self.knowledge or "",
|
||||
"{language}": self.language,
|
||||
"{language}": self.language(),
|
||||
"{ask}": self.context,
|
||||
}
|
||||
prompt = TalkActionPrompt.FORMATION_LOOSE
|
||||
|
|
@ -74,7 +73,7 @@ class TalkAction(Action):
|
|||
|
||||
@property
|
||||
def aask_args(self):
|
||||
language = self.language
|
||||
language = self.language()
|
||||
system_msgs = [
|
||||
f"You are {self.agent_description}.",
|
||||
"Your responses should align with the role-play agreement, "
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class Config(CLIParams, YamlModel):
|
|||
llm_for_researcher_report: str = "gpt3"
|
||||
METAGPT_TEXT_TO_IMAGE_MODEL_URL: str = ""
|
||||
language: str = "English"
|
||||
redis_key: str = "placeholder"
|
||||
|
||||
@classmethod
|
||||
def default(cls):
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ from metagpt.utils.git_repository import GitRepository
|
|||
|
||||
|
||||
class AttrDict:
|
||||
"""A dict-like object that allows access to keys as attributes."""
|
||||
|
||||
def __init__(self, d=None):
|
||||
if d is None:
|
||||
d = {}
|
||||
|
|
@ -37,7 +39,7 @@ class AttrDict:
|
|||
|
||||
|
||||
class Context:
|
||||
kwargs: AttrDict = {}
|
||||
kwargs: AttrDict = AttrDict()
|
||||
config: Config = Config.default()
|
||||
git_repo: Optional[GitRepository] = None
|
||||
src_workspace: Optional[Path] = None
|
||||
|
|
@ -72,5 +74,9 @@ context = Context()
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(context.model_dump_json(indent=4))
|
||||
print(context.config.get_openai_llm())
|
||||
# print(context.model_dump_json(indent=4))
|
||||
# print(context.config.get_openai_llm())
|
||||
ad = AttrDict({"name": "John", "age": 30})
|
||||
|
||||
print(ad.name) # Output: John
|
||||
print(ad.height) # Output: None (因为height不存在)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class BrainMemory(BaseModel):
|
|||
is_dirty: bool = False
|
||||
last_talk: str = None
|
||||
cacheable: bool = True
|
||||
llm: Optional[BaseLLM] = None
|
||||
llm: Optional[BaseLLM] = Field(default=None, exclude=True)
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
|
@ -56,8 +56,8 @@ class BrainMemory(BaseModel):
|
|||
|
||||
@staticmethod
|
||||
async def loads(redis_key: str) -> "BrainMemory":
|
||||
redis = Redis()
|
||||
if not redis.is_valid or not redis_key:
|
||||
redis = Redis(config.redis)
|
||||
if not redis_key:
|
||||
return BrainMemory()
|
||||
v = await redis.get(key=redis_key)
|
||||
logger.debug(f"REDIS GET {redis_key} {v}")
|
||||
|
|
@ -70,8 +70,8 @@ class BrainMemory(BaseModel):
|
|||
async def dumps(self, redis_key: str, timeout_sec: int = 30 * 60):
|
||||
if not self.is_dirty:
|
||||
return
|
||||
redis = Redis()
|
||||
if not redis.is_valid or not redis_key:
|
||||
redis = Redis(config.redis)
|
||||
if not redis_key:
|
||||
return False
|
||||
v = self.model_dump_json()
|
||||
if self.cacheable:
|
||||
|
|
@ -140,7 +140,7 @@ class BrainMemory(BaseModel):
|
|||
return text
|
||||
summary = await self._summarize(text=text, max_words=max_words, keep_language=keep_language, limit=limit)
|
||||
if summary:
|
||||
await self.set_history_summary(history_summary=summary, redis_key=config.redis.key)
|
||||
await self.set_history_summary(history_summary=summary, redis_key=config.redis_key)
|
||||
return summary
|
||||
raise ValueError(f"text too long:{text_length}")
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,13 +1,13 @@
|
|||
from typing import Optional
|
||||
|
||||
from metagpt.config2 import config
|
||||
from metagpt.logs import log_llm_stream, logger
|
||||
from metagpt.provider.openai_api import OpenAILLM
|
||||
from tests.metagpt.provider.mock_llm_config import mock_llm_config
|
||||
|
||||
|
||||
class MockLLM(OpenAILLM):
|
||||
def __init__(self, allow_open_api_call):
|
||||
super().__init__(mock_llm_config)
|
||||
super().__init__(config.get_openai_llm())
|
||||
self.allow_open_api_call = allow_open_api_call
|
||||
self.rsp_cache: dict = {}
|
||||
self.rsp_candidates: list[dict] = [] # a test can have multiple calls with the same llm, thus a list
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue