Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: move quickstart to use inference.memgpt.ai (#1190)
Sarah Woodersef913a743bc3
diff --git a/configs/memgpt_hosted.json b/configs/memgpt_hosted.jsonindex fb575c106..ea8030ac4 100644--- a/configs/memgpt_hosted.json+++ b/configs/memgpt_hosted.json@@ -1,9 +1,7 @@{"context_window": 16384,- "model": "ehartford/dolphin-2.5-mixtral-8x7b",- "model_endpoint_type": "vllm",- "model_endpoint": "https://api.memgpt.ai",- "model_wrapper": "chatml",+ "model_endpoint_type": "openai",+ "model_endpoint": "https://inference.memgpt.ai","embedding_endpoint_type": "hugging-face","embedding_endpoint": "https://embeddings.memgpt.ai","embedding_model": "BAAI/bge-large-en-v1.5",diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex f6172cc46..fe1361c59 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -75,27 +75,46 @@ def set_config_with_dict(new_config: dict) -> (MemGPTConfig, bool):printd(f"Skipping new config {k}: {v} == {new_config[k]}")# update embedding config- for k, v in vars(old_config.default_embedding_config).items():- if k in new_config:- if v != new_config[k]:- printd(f"Replacing config {k}: {v} -> {new_config[k]}")- modified = True- # old_config[k] = new_config[k]- setattr(old_config.default_embedding_config, k, new_config[k])- else:- printd(f"Skipping new config {k}: {v} == {new_config[k]}")+ if old_config.default_embedding_config:+ for k, v in vars(old_config.default_embedding_config).items():+ if k in new_config:+ if v != new_config[k]:+ printd(f"Replacing config {k}: {v} -> {new_config[k]}")+ modified = True+ # old_config[k] = new_config[k]+ setattr(old_config.default_embedding_config, k, new_config[k])+ else:+ printd(f"Skipping new config {k}: {v} == {new_config[k]}")+ else:+ modified = True+ fields = ["embedding_model", "embedding_dim", "embedding_chunk_size", "embedding_endpoint", "embedding_endpoint_type"]+ args = {}+ for field in fields:+ if field in new_config:+ args[field] = new_config[field]+ printd(f"Setting new config {field}: {new_config[field]}")+ old_config.default_embedding_config = EmbeddingConfig(**args)# update llm config- for k, v in vars(old_config.default_llm_config).items():- if k in new_config:- if v != new_config[k]:- printd(f"Replacing config {k}: {v} -> {new_config[k]}")- modified = True- # old_config[k] = new_config[k]- setattr(old_config.default_llm_config, k, new_config[k])- else:- printd(f"Skipping new config {k}: {v} == {new_config[k]}")-+ if old_config.default_llm_config:+ for k, v in vars(old_config.default_llm_config).items():+ if k in new_config:+ if v != new_config[k]:+ printd(f"Replacing config {k}: {v} -> {new_config[k]}")+ modified = True+ # old_config[k] = new_config[k]+ setattr(old_config.default_llm_config, k, new_config[k])+ else:+ printd(f"Skipping new config {k}: {v} == {new_config[k]}")+ else:+ modified = True+ fields = ["model", "model_endpoint", "model_endpoint_type", "model_wrapper", "context_window"]+ args = {}+ for field in fields:+ if field in new_config:+ args[field] = new_config[field]+ printd(f"Setting new config {field}: {new_config[field]}")+ old_config.default_llm_config = LLMConfig(**args)return (old_config, modified)@@ -153,10 +172,13 @@ def quickstart(else:# Load the file from the relative pathscript_dir = os.path.dirname(__file__) # Get the directory where the script is located+ print("SCRIPT", script_dir)backup_config_path = os.path.join(script_dir, "..", "configs", "memgpt_hosted.json")+ print("FILE PATH", backup_config_path)try:with open(backup_config_path, "r", encoding="utf-8") as file:backup_config = json.load(file)+ print(backup_config)printd("Loaded config file successfully.")new_config, config_was_modified = set_config_with_dict(backup_config)except FileNotFoundError:@@ -301,15 +323,6 @@ def server(# # Add the handler to the logger# server_logger.addHandler(stream_handler)- # override config with postgres enviornment (messy, but necessary for docker compose)- if os.getenv("POSTGRES_URI"):- config = MemGPTConfig.load()- config.archival_storage_uri = os.getenv("POSTGRES_URI")- config.recall_storage_uri = os.getenv("POSTGRES_URI")- config.metadata_storage_uri = os.getenv("POSTGRES_URI")- print(f"Overriding DB config URI with enviornment variable: {config.archival_storage_uri}")- config.save()-if type == ServerChoice.rest_api:import uvicornfrom memgpt.server.rest_api.server import appdiff --git a/memgpt/client/client.py b/memgpt/client/client.pyindex ee7507a9c..08ecf1db3 100644--- a/memgpt/client/client.py+++ b/memgpt/client/client.py@@ -551,8 +551,6 @@ class LocalClient(AbstractClient):preset: Optional[str] = None,persona: Optional[str] = None,human: Optional[str] = None,- embedding_config: Optional[EmbeddingConfig] = None,- llm_config: Optional[LLMConfig] = None,) -> AgentState:if name and self.agent_exists(agent_name=name):raise ValueError(f"Agent with name {name} already exists (user_id={self.user_id})")@@ -564,8 +562,6 @@ class LocalClient(AbstractClient):preset=preset,persona=persona,human=human,- embedding_config=embedding_config,- llm_config=llm_config,)return agent_statediff --git a/memgpt/config.py b/memgpt/config.pyindex 0f0bc4109..1aff760d0 100644--- a/memgpt/config.py+++ b/memgpt/config.py@@ -44,10 +44,10 @@ class MemGPTConfig:human: str = DEFAULT_HUMAN# model parameters- default_llm_config: LLMConfig = field(default_factory=LLMConfig)+ default_llm_config: LLMConfig = None# embedding parameters- default_embedding_config: EmbeddingConfig = field(default_factory=EmbeddingConfig)+ default_embedding_config: EmbeddingConfig = None# database configs: archivalarchival_storage_type: str = "chroma" # local, db@@ -110,6 +110,7 @@ class MemGPTConfig:# insure all configuration directories existcls.create_config_dir()+ print(f"Loading config from {config_path}")if os.path.exists(config_path):# read existing configconfig.read(config_path)diff --git a/memgpt/configs/memgpt_hosted.json b/memgpt/configs/memgpt_hosted.jsonindex fb575c106..013ffe8d7 100644--- a/memgpt/configs/memgpt_hosted.json+++ b/memgpt/configs/memgpt_hosted.json@@ -1,8 +1,8 @@{"context_window": 16384,- "model": "ehartford/dolphin-2.5-mixtral-8x7b",- "model_endpoint_type": "vllm",- "model_endpoint": "https://api.memgpt.ai",+ "model": "memgpt",+ "model_endpoint_type": "openai",+ "model_endpoint": "https://inference.memgpt.ai","model_wrapper": "chatml","embedding_endpoint_type": "hugging-face","embedding_endpoint": "https://embeddings.memgpt.ai",diff --git a/memgpt/configs/openai.json b/memgpt/configs/openai.jsonindex 7c76b1012..82ed0d72e 100644--- a/memgpt/configs/openai.json+++ b/memgpt/configs/openai.json@@ -6,7 +6,7 @@"model_wrapper": null,"embedding_endpoint_type": "openai","embedding_endpoint": "https://api.openai.com/v1",- "embedding_model": null,+ "embedding_model": "text-embedding-ada-002","embedding_dim": 1536,"embedding_chunk_size": 300-}\ No newline at end of file+}diff --git a/memgpt/data_types.py b/memgpt/data_types.pyindex 2e09588dc..d4056466b 100644--- a/memgpt/data_types.py+++ b/memgpt/data_types.py@@ -370,9 +370,9 @@ class Passage(Record):class LLMConfig:def __init__(self,- model: Optional[str] = "gpt-4",- model_endpoint_type: Optional[str] = "openai",- model_endpoint: Optional[str] = "https://api.openai.com/v1",+ model: Optional[str] = None,+ model_endpoint_type: Optional[str] = None,+ model_endpoint: Optional[str] = None,model_wrapper: Optional[str] = None,context_window: Optional[int] = None,):@@ -391,10 +391,10 @@ class LLMConfig:class EmbeddingConfig:def __init__(self,- embedding_endpoint_type: Optional[str] = "openai",- embedding_endpoint: Optional[str] = "https://api.openai.com/v1",- embedding_model: Optional[str] = "text-embedding-ada-002",- embedding_dim: Optional[int] = 1536,+ embedding_endpoint_type: Optional[str] = None,+ embedding_endpoint: Optional[str] = None,+ embedding_model: Optional[str] = None,+ embedding_dim: Optional[int] = None,embedding_chunk_size: Optional[int] = 300,):self.embedding_endpoint_type = embedding_endpoint_typediff --git a/memgpt/llm_api_tools.py b/memgpt/llm_api_tools.pyindex dbfe81dce..b748aeed7 100644--- a/memgpt/llm_api_tools.py+++ b/memgpt/llm_api_tools.py@@ -416,7 +416,8 @@ def create(# openaiif agent_state.llm_config.model_endpoint_type == "openai":# TODO do the same for Azure?- if credentials.openai_key is None:+ if credentials.openai_key is None and agent_state.llm_config.model_endpoint == "https://api.openai.com/v1":+ # only is a problem if we are *not* using an openai proxyraise ValueError(f"OpenAI key is missing from MemGPT config file")if use_tool_naming:data = dict(diff --git a/memgpt/server/server.py b/memgpt/server/server.pyindex 183d578e9..f1e0fd220 100644--- a/memgpt/server/server.py+++ b/memgpt/server/server.py@@ -240,7 +240,8 @@ class SyncServer(LockingServer):embedding_endpoint_type=self.config.default_embedding_config.embedding_endpoint_type,embedding_endpoint=self.config.default_embedding_config.embedding_endpoint,embedding_dim=self.config.default_embedding_config.embedding_dim,- # openai_key=self.credentials.openai_key,+ embedding_model=self.config.default_embedding_config.embedding_model,+ embedding_chunk_size=self.config.default_embedding_config.embedding_chunk_size,)# Initialize the metadata storediff --git a/tests/test_base_functions.py b/tests/test_base_functions.pyindex 6b6557965..accf9edec 100644--- a/tests/test_base_functions.py+++ b/tests/test_base_functions.py@@ -1,4 +1,5 @@import os+import pytestimport uuidfrom memgpt import create_client@@ -10,10 +11,10 @@ from .utils import wipe_config, create_config# test_agent_id = "test_agent"client = None-agent_obj = None-def create_test_agent():[email protected](scope="module")+def agent_obj():"""Create a test agent that we can call functions on"""wipe_config()global client@@ -31,26 +32,18 @@ def create_test_agent():global agent_objuser_id = uuid.UUID(TEST_MEMGPT_CONFIG.anon_clientid)agent_obj = client.server._get_or_load_agent(user_id=user_id, agent_id=agent_state.id)+ yield agent_obj+ client.delete_agent(agent_obj.agent_state.id)-def test_archival():- global agent_obj- if agent_obj is None:- create_test_agent()- assert agent_obj is not None+def test_archival(agent_obj):base_functions.archival_memory_insert(agent_obj, "banana")-base_functions.archival_memory_search(agent_obj, "banana")base_functions.archival_memory_search(agent_obj, "banana", page=0)-def test_recall():- global agent_obj- if agent_obj is None:- create_test_agent()-+def test_recall(agent_obj):base_functions.conversation_search(agent_obj, "banana")base_functions.conversation_search(agent_obj, "banana", page=0)-base_functions.conversation_search_date(agent_obj, start_date="2022-01-01", end_date="2022-01-02")diff --git a/tests/test_client.py b/tests/test_client.pyindex 4b87da308..41f351463 100644--- a/tests/test_client.py+++ b/tests/test_client.py@@ -59,6 +59,7 @@ def run_server():embedding_endpoint_type="openai",embedding_endpoint="https://api.openai.com/v1",embedding_dim=1536,+ embedding_model="text-embedding-ada-002",),# llmsdefault_llm_config=LLMConfig(@@ -237,9 +238,10 @@ def test_config(client, agent):models_response = client.list_models()print("MODELS", models_response)- config_response = client.get_config()+ # TODO: add back+ # config_response = client.get_config()# TODO: ensure config is the same as the one in the server- print("CONFIG", config_response)+ # print("CONFIG", config_response)def test_sources(client, agent):diff --git a/tests/test_different_embedding_size.py b/tests/test_different_embedding_size.pyindex ffeb36242..0fdde27d3 100644--- a/tests/test_different_embedding_size.py+++ b/tests/test_different_embedding_size.py@@ -68,15 +68,13 @@ def test_create_user():openai_agent_run = client.server._get_or_load_agent(user_id=client.user.id, agent_id=openai_agent.id)openai_agent_run.persistence_manager.archival_memory.storage.insert_many(passages)+ # create client+ create_config("memgpt_hosted")+ client = create_client()+# hosted: create agenthosted_agent = client.create_agent(name="hosted_agent",- embedding_config=EmbeddingConfig(- embedding_endpoint_type="hugging-face",- embedding_model="BAAI/bge-large-en-v1.5",- embedding_endpoint="https://embeddings.memgpt.ai",- embedding_dim=1024,- ),)# check to make sure endpoint overridenassert (diff --git a/tests/test_load_archival.py b/tests/test_load_archival.pyindex 7fa56cdcd..09bc29dc8 100644--- a/tests/test_load_archival.py+++ b/tests/test_load_archival.py@@ -11,10 +11,10 @@ from memgpt.cli.cli_load import load_directory# from memgpt.data_sources.connectors import DirectoryConnector, load_datafrom memgpt.credentials import MemGPTCredentialsfrom memgpt.metadata import MetadataStore-from memgpt.data_types import User, AgentState, EmbeddingConfig+from memgpt.data_types import User, AgentState, EmbeddingConfig, LLMConfigfrom memgpt.utils import get_human_text, get_persona_textfrom tests import TEST_MEMGPT_CONFIG-from .utils import wipe_config+from .utils import wipe_config, create_config@pytest.fixture(autouse=True)@@ -44,6 +44,18 @@ def test_load_directory(recreate_declarative_base,):wipe_config()+ TEST_MEMGPT_CONFIG.default_embedding_config = EmbeddingConfig(+ embedding_endpoint_type="openai",+ embedding_endpoint="https://api.openai.com/v1",+ embedding_dim=1536,+ embedding_model="text-embedding-ada-002",+ )+ TEST_MEMGPT_CONFIG.default_llm_config = LLMConfig(+ model_endpoint_type="openai",+ model_endpoint="https://api.openai.com/v1",+ model="gpt-4",+ )+# setup configif metadata_storage_connector == "postgres":if not os.getenv("MEMGPT_PGURI"):@@ -84,6 +96,7 @@ def test_load_directory(embedding_endpoint_type="openai",embedding_endpoint="https://api.openai.com/v1",embedding_dim=1536,+ embedding_model="text-embedding-ada-002",# openai_key=os.getenv("OPENAI_API_KEY"),)diff --git a/tests/test_server.py b/tests/test_server.pyindex 4704849de..cc8820b77 100644--- a/tests/test_server.py+++ b/tests/test_server.py@@ -35,6 +35,7 @@ def server():default_embedding_config=EmbeddingConfig(embedding_endpoint_type="openai",embedding_endpoint="https://api.openai.com/v1",+ embedding_model="text-embedding-ada-002",embedding_dim=1536,),# llmsdiff --git a/tests/test_storage.py b/tests/test_storage.pyindex d592792c4..9450f26cf 100644--- a/tests/test_storage.py+++ b/tests/test_storage.py@@ -5,7 +5,7 @@ import pytestfrom memgpt.agent_store.storage import StorageConnector, TableTypefrom memgpt.embeddings import embedding_model, query_embedding-from memgpt.data_types import Message, Passage, EmbeddingConfig, AgentState+from memgpt.data_types import Message, Passage, EmbeddingConfig, AgentState, LLMConfigfrom memgpt.credentials import MemGPTCredentialsfrom memgpt.agent_store.storage import StorageConnector, TableTypefrom memgpt.metadata import MetadataStore@@ -120,7 +120,17 @@ def test_storage(# if 'Message' in globals():# print("Removing messages", globals()['Message'])# del globals()['Message']-+ TEST_MEMGPT_CONFIG.default_embedding_config = EmbeddingConfig(+ embedding_endpoint_type="openai",+ embedding_endpoint="https://api.openai.com/v1",+ embedding_dim=1536,+ embedding_model="text-embedding-ada-002",+ )+ TEST_MEMGPT_CONFIG.default_llm_config = LLMConfig(+ model_endpoint_type="openai",+ model_endpoint="https://api.openai.com/v1",+ model="gpt-4",+ )if storage_connector == "postgres":if not os.getenv("MEMGPT_PGURI"):print("Skipping test, missing PG URI")