mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-09 15:52:38 +02:00
experience pool
This commit is contained in:
parent
5c416a1f31
commit
15b86e8533
10 changed files with 106 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ from metagpt.configs.search_config import SearchConfig
|
|||
from metagpt.configs.workspace_config import WorkspaceConfig
|
||||
from metagpt.const import CONFIG_ROOT, METAGPT_ROOT
|
||||
from metagpt.utils.yaml_model import YamlModel
|
||||
from metagpt.configs.exp_pool_config import ExperiencePoolConfig
|
||||
|
||||
|
||||
class CLIParams(BaseModel):
|
||||
|
|
@ -67,6 +68,9 @@ class Config(CLIParams, YamlModel):
|
|||
enable_longterm_memory: bool = False
|
||||
code_review_k_times: int = 2
|
||||
|
||||
# Experience Pool Parameters
|
||||
experience_pool: Optional[ExperiencePoolConfig] = None
|
||||
|
||||
# Will be removed in the future
|
||||
metagpt_tti_url: str = ""
|
||||
language: str = "English"
|
||||
|
|
|
|||
6
metagpt/configs/exp_pool_config.py
Normal file
6
metagpt/configs/exp_pool_config.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from metagpt.utils.yaml_model import YamlModel
|
||||
|
||||
|
||||
class ExperiencePoolConfig(YamlModel):
|
||||
enable_read: bool = False
|
||||
enable_write: bool = False
|
||||
0
metagpt/exp_pool/__init__.py
Normal file
0
metagpt/exp_pool/__init__.py
Normal file
4
metagpt/exp_pool/decorator.py
Normal file
4
metagpt/exp_pool/decorator.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
def exp_cache(func):
|
||||
pass
|
||||
32
metagpt/exp_pool/manager.py
Normal file
32
metagpt/exp_pool/manager.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from pydantic import BaseModel, ConfigDict
|
||||
from metagpt.exp_pool.schema import Experience
|
||||
import uuid
|
||||
import chromadb
|
||||
from chromadb import Collection, QueryResult
|
||||
from typing import Optional
|
||||
from metagpt.rag.engines import SimpleEngine
|
||||
from metagpt.rag.schema import ChromaRetrieverConfig
|
||||
|
||||
|
||||
class ExperiencePoolManager(BaseModel):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._storage = None
|
||||
|
||||
@property
|
||||
def storage(self) -> SimpleEngine:
|
||||
if self._storage is None:
|
||||
self._storage = SimpleEngine.from_objs(retriever_configs=[ChromaRetrieverConfig(collection_name="experience_pool", persist_path="./chroma_data")])
|
||||
return self._storage
|
||||
|
||||
def create_exp(self, exp: Experience):
|
||||
self.storage.add_objs([exp])
|
||||
|
||||
async def query_exp(self, req: str) -> list[Experience]:
|
||||
nodes = await self.storage.aretrieve(req)
|
||||
exps = [node.metadata["obj"] for node in nodes]
|
||||
|
||||
return exps
|
||||
|
||||
|
||||
|
||||
25
metagpt/exp_pool/schema.py
Normal file
25
metagpt/exp_pool/schema.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from pydantic import BaseModel, Field
|
||||
from llama_index.core.schema import TextNode
|
||||
|
||||
|
||||
class Experience(BaseModel):
|
||||
req: str = Field(..., description="")
|
||||
resp: str = Field(..., description="")
|
||||
|
||||
def rag_key(self):
|
||||
return self.req
|
||||
|
||||
|
||||
class ExperienceNodeMetadata(BaseModel):
|
||||
"""Metadata of ExperienceNode."""
|
||||
|
||||
resp: str = Field(..., description="")
|
||||
|
||||
|
||||
class ExperienceNode(TextNode):
|
||||
"""ExperienceNode for RAG."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.excluded_llm_metadata_keys = list(ExperienceNodeMetadata.model_fields.keys())
|
||||
self.excluded_embed_metadata_keys = self.excluded_llm_metadata_keys
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
"""class tools, including method inspection, class attributes, inheritance relationships, etc."""
|
||||
import inspect
|
||||
|
||||
|
||||
def check_methods(C, *methods):
|
||||
|
|
@ -16,3 +17,11 @@ def check_methods(C, *methods):
|
|||
else:
|
||||
return NotImplemented
|
||||
return True
|
||||
|
||||
|
||||
def get_func_full_name(func, *args) -> str:
|
||||
if inspect.ismethod(func) or (inspect.isfunction(func) and "self" in inspect.signature(func).parameters):
|
||||
cls_name = args[0].__class__.__name__
|
||||
return f"{func.__module__}.{cls_name}.{func.__name__}"
|
||||
|
||||
return f"{func.__module__}.{func.__name__}"
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@ TOKEN_MAX = {
|
|||
"gpt-4-1106-preview": 128000,
|
||||
"gpt-4-vision-preview": 128000,
|
||||
"gpt-4-1106-vision-preview": 128000,
|
||||
"gpt-4-turbo": 128000,
|
||||
"gpt-4o": 128000,
|
||||
"gpt-4": 8192,
|
||||
"gpt-4-0613": 8192,
|
||||
"gpt-4-32k": 32768,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue