From 3f52df93ee16ba858546c1b3fcbef47766b142cb Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Fri, 25 Oct 2024 15:36:18 -0700 Subject: [PATCH 1/2] Remove legacy code and instances of anon_clientid --- letta/config.py | 6 - paper_experiments/utils.py | 1 - tests/data/memgpt-0.2.11/config | 3 - tests/test_load_archival.py | 234 ----------------------------- tests/test_openai_assistant_api.py | 46 ------ 5 files changed, 290 deletions(-) delete mode 100644 tests/test_load_archival.py delete mode 100644 tests/test_openai_assistant_api.py diff --git a/letta/config.py b/letta/config.py index cd1ec37c92..51287e0091 100644 --- a/letta/config.py +++ b/letta/config.py @@ -19,7 +19,6 @@ from letta.schemas.agent import AgentState from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.llm_config import LLMConfig -from letta.services.user_manager import UserManager logger = get_logger(__name__) @@ -45,7 +44,6 @@ def set_field(config, section, field, value): @dataclass class LettaConfig: config_path: str = os.getenv("MEMGPT_CONFIG_PATH") or os.path.join(LETTA_DIR, "config") - anon_clientid: str = UserManager.DEFAULT_USER_ID # preset preset: str = DEFAULT_PRESET # TODO: rename to system prompt @@ -182,7 +180,6 @@ def load(cls, llm_config: Optional[LLMConfig] = None, embedding_config: Optional "metadata_storage_path": get_field(config, "metadata_storage", "path"), "metadata_storage_uri": get_field(config, "metadata_storage", "uri"), # Misc - "anon_clientid": get_field(config, "client", "anon_clientid"), "config_path": config_path, "letta_version": get_field(config, "version", "letta_version"), } @@ -278,9 +275,6 @@ def save(self): # set version set_field(config, "version", "letta_version", letta.__version__) - # client - set_field(config, "client", "anon_clientid", self.anon_clientid) - # always make sure all directories are present self.create_config_dir() diff --git a/paper_experiments/utils.py b/paper_experiments/utils.py index c7a4cd1787..ddfb8ddab9 100644 --- a/paper_experiments/utils.py +++ b/paper_experiments/utils.py @@ -25,7 +25,6 @@ def get_experiment_config(postgres_uri, endpoint_type="openai", model="gpt-4"): config.archival_storage_uri = postgres_uri config = LettaConfig( - anon_clientid=config.anon_clientid, archival_storage_type="postgres", archival_storage_uri=postgres_uri, recall_storage_type="postgres", diff --git a/tests/data/memgpt-0.2.11/config b/tests/data/memgpt-0.2.11/config index a2d5fc8bdd..39f7621184 100644 --- a/tests/data/memgpt-0.2.11/config +++ b/tests/data/memgpt-0.2.11/config @@ -31,6 +31,3 @@ path = /Users/sarahwooders/.letta [version] letta_version = 0.2.12 -[client] -anon_clientid = 00000000000000000000d67f40108c5c - diff --git a/tests/test_load_archival.py b/tests/test_load_archival.py deleted file mode 100644 index 67651aa24a..0000000000 --- a/tests/test_load_archival.py +++ /dev/null @@ -1,234 +0,0 @@ -# TODO: add equivalent test into test_client.py by iterating through storage options - -# import os -# import uuid -# -# import pytest -# from sqlalchemy.ext.declarative import declarative_base -# -# from letta.agent_store.storage import StorageConnector, TableType -# from letta.cli.cli_load import load_directory -# from letta.config import LettaConfig -# from letta.credentials import LettaCredentials -# from letta.data_types import EmbeddingConfig, User -# from letta.metadata import MetadataStore -# -## from letta.data_sources.connectors import DirectoryConnector, load_data -## import letta -# from letta.settings import settings -# from tests import TEST_MEMGPT_CONFIG -# -# from .utils import create_config, wipe_config, with_qdrant_storage -# -# GET_ALL_LIMIT = 1000 -# -# -# @pytest.fixture(autouse=True) -# def clear_dynamically_created_models(): -# """Wipe globals for SQLAlchemy""" -# yield -# for key in list(globals().keys()): -# if key.endswith("Model"): -# del globals()[key] -# -# -# @pytest.fixture(autouse=True) -# def recreate_declarative_base(): -# """Recreate the declarative base before each test""" -# global Base -# Base = declarative_base() -# yield -# Base.metadata.clear() -# -# -# @pytest.mark.parametrize("metadata_storage_connector", ["sqlite", "postgres"]) -# @pytest.mark.parametrize("passage_storage_connector", with_qdrant_storage(["chroma", "postgres", "milvus"])) -# def test_load_directory( -# metadata_storage_connector, -# passage_storage_connector, -# clear_dynamically_created_models, -# recreate_declarative_base, -# ): -# wipe_config() -# if os.getenv("OPENAI_API_KEY"): -# create_config("openai") -# credentials = LettaCredentials( -# openai_key=os.getenv("OPENAI_API_KEY"), -# ) -# else: # hosted -# create_config("letta_hosted") -# credentials = LettaCredentials() -# -# config = LettaConfig.load() -# TEST_MEMGPT_CONFIG.default_embedding_config = config.default_embedding_config -# TEST_MEMGPT_CONFIG.default_llm_config = config.default_llm_config -# -# # setup config -# if metadata_storage_connector == "postgres": -# TEST_MEMGPT_CONFIG.metadata_storage_uri = settings.letta_pg_uri -# TEST_MEMGPT_CONFIG.metadata_storage_type = "postgres" -# elif metadata_storage_connector == "sqlite": -# print("testing sqlite metadata") -# # nothing to do (should be config defaults) -# else: -# raise NotImplementedError(f"Storage type {metadata_storage_connector} not implemented") -# if passage_storage_connector == "postgres": -# TEST_MEMGPT_CONFIG.archival_storage_uri = settings.letta_pg_uri -# TEST_MEMGPT_CONFIG.archival_storage_type = "postgres" -# elif passage_storage_connector == "chroma": -# print("testing chroma passage storage") -# # nothing to do (should be config defaults) -# elif passage_storage_connector == "qdrant": -# print("Testing Qdrant passage storage") -# TEST_MEMGPT_CONFIG.archival_storage_type = "qdrant" -# TEST_MEMGPT_CONFIG.archival_storage_uri = "localhost:6333" -# elif passage_storage_connector == "milvus": -# print("Testing Milvus passage storage") -# TEST_MEMGPT_CONFIG.archival_storage_type = "milvus" -# TEST_MEMGPT_CONFIG.archival_storage_uri = "./milvus.db" -# else: -# raise NotImplementedError(f"Storage type {passage_storage_connector} not implemented") -# TEST_MEMGPT_CONFIG.save() -# -# # create metadata store -# ms = MetadataStore(TEST_MEMGPT_CONFIG) -# user = User(id=uuid.UUID(TEST_MEMGPT_CONFIG.anon_clientid)) -# -# # embedding config -# if os.getenv("OPENAI_API_KEY"): -# print("Using OpenAI embeddings for testing") -# credentials = LettaCredentials( -# openai_key=os.getenv("OPENAI_API_KEY"), -# ) -# credentials.save() -# embedding_config = EmbeddingConfig( -# 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"), -# ) -# -# else: -# # print("Using local embedding model for testing") -# # embedding_config = EmbeddingConfig( -# # embedding_endpoint_type="local", -# # embedding_endpoint=None, -# # embedding_dim=384, -# # ) -# -# print("Using official hosted embedding model for testing") -# embedding_config = EmbeddingConfig( -# embedding_endpoint_type="hugging-face", -# embedding_endpoint="https://embeddings.letta.ai", -# embedding_model="BAAI/bge-large-en-v1.5", -# embedding_dim=1024, -# ) -# -# # write out the config so that the 'load' command will use it (CLI commands pull from config) -# TEST_MEMGPT_CONFIG.default_embedding_config = embedding_config -# TEST_MEMGPT_CONFIG.save() -# # config.default_embedding_config = embedding_config -# # config.save() -# -# # create user and agent -# # agent = AgentState( -# # user_id=user.id, -# # name="test_agent", -# # preset=TEST_MEMGPT_CONFIG.preset, -# # persona=get_persona_text(TEST_MEMGPT_CONFIG.persona), -# # human=get_human_text(TEST_MEMGPT_CONFIG.human), -# # llm_config=TEST_MEMGPT_CONFIG.default_llm_config, -# # embedding_config=TEST_MEMGPT_CONFIG.default_embedding_config, -# # tools=[], -# # system="", -# # ) -# ms.delete_user(user.id) -# ms.create_user(user) -# # ms.create_agent(agent) -# user = ms.get_user(user.id) -# print("Got user:", user, embedding_config) -# -# # setup storage connectors -# print("Creating storage connectors...") -# user_id = user.id -# print("User ID", user_id) -# passages_conn = StorageConnector.get_storage_connector(TableType.PASSAGES, TEST_MEMGPT_CONFIG, user_id) -# -# # load data -# name = "test_dataset" -# cache_dir = "CONTRIBUTING.md" -# -# # TODO: load two different data sources -# -# # clear out data -# print("Resetting tables with delete_table...") -# passages_conn.delete_table() -# print("Re-creating tables...") -# passages_conn = StorageConnector.get_storage_connector(TableType.PASSAGES, TEST_MEMGPT_CONFIG, user_id) -# assert ( -# passages_conn.size() == 0 -# ), f"Expected 0 records, got {passages_conn.size()}: {[vars(r) for r in passages_conn.get_all(limit=GET_ALL_LIMIT)]}" -# -# # test: load directory -# print("Loading directory") -# # load_directory(name=name, input_dir=None, input_files=[cache_dir], recursive=False, user_id=user_id) # cache_dir, -# load_directory(name=name, input_files=[cache_dir], recursive=False, user_id=user_id) # cache_dir, -# -# # test to see if contained in storage -# print("Querying table...") -# sources = ms.list_sources(user_id=user_id) -# assert len(sources) == 1, f"Expected 1 source, but got {len(sources)}" -# assert sources[0].name == name, f"Expected name {name}, but got {sources[0].name}" -# print("Source", sources) -# -# # test to see if contained in storage -# assert ( -# len(passages_conn.get_all(limit=GET_ALL_LIMIT)) == passages_conn.size() -# ), f"Expected {passages_conn.size()} passages, but got {len(passages_conn.get_all(limit=GET_ALL_LIMIT))}" -# passages = passages_conn.get_all({"data_source": name}, limit=GET_ALL_LIMIT) -# print("Source", [p.data_source for p in passages]) -# print(passages_conn.get_all(limit=GET_ALL_LIMIT)) -# print("All sources", [p.data_source for p in passages_conn.get_all(limit=GET_ALL_LIMIT)]) -# assert len(passages) > 0, f"Expected >0 passages, but got {len(passages)}" -# assert len(passages) == passages_conn.size(), f"Expected {passages_conn.size()} passages, but got {len(passages)}" -# assert [p.data_source == name for p in passages] -# print("Passages", passages) -# -# # test: listing sources -# print("Querying all...") -# sources = ms.list_sources(user_id=user_id) -# print("All sources", [s.name for s in sources]) -# -# # TODO: add back once agent attachment fully supported from server -# ## test loading into an agent -# ## create agent -# # agent_id = agent.id -# ## create storage connector -# # print("Creating agent archival storage connector...") -# # conn = StorageConnector.get_storage_connector(TableType.ARCHIVAL_MEMORY, config=config, user_id=user_id, agent_id=agent_id) -# # print("Deleting agent archival table...") -# # conn.delete_table() -# # conn = StorageConnector.get_storage_connector(TableType.ARCHIVAL_MEMORY, config=config, user_id=user_id, agent_id=agent_id) -# # assert conn.size() == 0, f"Expected 0 records, got {conn.size()}: {[vars(r) for r in conn.get_all(limit=GET_ALL_LIMIT)]}" -# -# ## attach data -# # print("Attaching data...") -# # attach(agent_name=agent.name, data_source=name, user_id=user_id) -# -# ## test to see if contained in storage -# # assert len(passages) == conn.size() -# # assert len(passages) == len(conn.get_all({"data_source": name}, limit=GET_ALL_LIMIT)) -# -# ## test: delete source -# # passages_conn.delete({"data_source": name}) -# # assert len(passages_conn.get_all({"data_source": name}, limit=GET_ALL_LIMIT)) == 0 -# -# # cleanup -# ms.delete_user(user.id) -# ms.delete_source(sources[0].id) -# -# # revert to openai config -# # client = Letta(quickstart="openai", user_id=user.id) -# wipe_config() -# diff --git a/tests/test_openai_assistant_api.py b/tests/test_openai_assistant_api.py deleted file mode 100644 index 07fa8f9035..0000000000 --- a/tests/test_openai_assistant_api.py +++ /dev/null @@ -1,46 +0,0 @@ -# TODO: modify this to run against an actual running server -# def test_list_messages(): -# client = TestClient(app) -# -# test_user_id = uuid.UUID(LettaConfig.load().anon_clientid) -# -# # create user -# server = SyncServer() -# if not server.get_user(test_user_id): -# print("Creating user in test_list_messages", test_user_id) -# server.create_user({"id": test_user_id}) -# else: -# print("User already exists in test_list_messages", test_user_id) -# -# # write default presets to DB -# server.initialize_default_presets(test_user_id) -# -# # test: create agent -# request_body = { -# "assistant_name": DEFAULT_PRESET, -# } -# print(request_body) -# response = client.post("/v1/threads", json=request_body) -# assert response.status_code == 200, f"Error: {response.json()}" -# agent_id = response.json()["id"] -# print(response.json()) -# -# # test: insert messages -# # TODO: eventually implement the "run" functionality -# request_body = { -# "content": "Hello, world!", -# "role": "user", -# } -# response = client.post(f"/v1/threads/{str(agent_id)}/messages", json=request_body) -# assert response.status_code == 200, f"Error: {response.json()}" -# -# # test: list messages -# thread_id = str(agent_id) -# params = { -# "limit": 10, -# "order": "desc", -# } -# response = client.get(f"/v1/threads/{thread_id}/messages", params=params) -# assert response.status_code == 200, f"Error: {response.json()}" -# print(response.json()) -# From afc881d77c692a8e0181d295f2b9cd1bb4442772 Mon Sep 17 00:00:00 2001 From: Matt Zhou Date: Fri, 25 Oct 2024 15:43:05 -0700 Subject: [PATCH 2/2] restore old config per suggestion --- tests/data/memgpt-0.2.11/config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/data/memgpt-0.2.11/config b/tests/data/memgpt-0.2.11/config index 39f7621184..a2d5fc8bdd 100644 --- a/tests/data/memgpt-0.2.11/config +++ b/tests/data/memgpt-0.2.11/config @@ -31,3 +31,6 @@ path = /Users/sarahwooders/.letta [version] letta_version = 0.2.12 +[client] +anon_clientid = 00000000000000000000d67f40108c5c +