Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

chore: run autoflake + isort (#1279)

Charles Packerb35de11d96ac
diff --git a/examples/google_search.py b/examples/google_search.py
index 5e60bdb91..f532a3170 100644
--- a/examples/google_search.py
+++ b/examples/google_search.py
@@ -1,17 +1,15 @@
-import random
+import os
import time
from concurrent.futures import ThreadPoolExecutor
-import os
from typing import List, Tuple
-from openai import OpenAI
+
import serpapi
+from openai import OpenAI
-from memgpt.data_sources.connectors import WebConnector
-from memgpt.data_types import Document, Passage
from memgpt.credentials import MemGPTCredentials
+from memgpt.data_sources.connectors import WebConnector
from memgpt.utils import printd
-
"""
This example show how you can add a google search custom function to your MemGPT agent.
diff --git a/examples/memgpt_client.py b/examples/memgpt_client.py
index 6f5280b9c..41795f2ae 100644
--- a/examples/memgpt_client.py
+++ b/examples/memgpt_client.py
@@ -1,8 +1,8 @@
import json
-from memgpt import create_client, Admin
-from memgpt.constants import DEFAULT_PRESET, DEFAULT_HUMAN, DEFAULT_PERSONA
-from memgpt.utils import get_human_text, get_persona_text
+from memgpt import Admin, create_client
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
+from memgpt.utils import get_human_text, get_persona_text
"""
Make sure you run the MemGPT server before running this example.
diff --git a/main.py b/main.py
index 5135f7d90..f1b9bcc0a 100644
--- a/main.py
+++ b/main.py
@@ -1,4 +1,3 @@
-from memgpt.main import app
import typer
typer.secho(
diff --git a/memgpt/__init__.py b/memgpt/__init__.py
index a0970687f..4f4552bd2 100644
--- a/memgpt/__init__.py
+++ b/memgpt/__init__.py
@@ -1,4 +1,4 @@
__version__ = "0.3.11"
-from memgpt.client.client import create_client
from memgpt.client.admin import Admin
+from memgpt.client.client import create_client
diff --git a/memgpt/agent.py b/memgpt/agent.py
index d24181a74..735763075 100644
--- a/memgpt/agent.py
+++ b/memgpt/agent.py
@@ -1,48 +1,52 @@
import datetime
-import uuid
import inspect
import json
-from pathlib import Path
import traceback
-from typing import List, Tuple, Optional, cast, Union
+import uuid
+from pathlib import Path
+from typing import List, Optional, Tuple, Union, cast
+
from tqdm import tqdm
+from memgpt.agent_store.storage import StorageConnector
+from memgpt.constants import (
+ CLI_WARNING_PREFIX,
+ CORE_MEMORY_HUMAN_CHAR_LIMIT,
+ CORE_MEMORY_PERSONA_CHAR_LIMIT,
+ FIRST_MESSAGE_ATTEMPTS,
+ JSON_ENSURE_ASCII,
+ JSON_LOADS_STRICT,
+ LLM_MAX_TOKENS,
+ MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST,
+ MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC,
+ MESSAGE_SUMMARY_WARNING_FRAC,
+)
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, Message, Passage, Preset
+from memgpt.interface import AgentInterface
+from memgpt.llm_api.llm_api_tools import create, is_context_overflow_error
+from memgpt.memory import ArchivalMemory
+from memgpt.memory import CoreMemory as InContextMemory
+from memgpt.memory import RecallMemory, summarize_messages
from memgpt.metadata import MetadataStore
-from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.data_types import AgentState, Message, LLMConfig, EmbeddingConfig, Passage, Preset
from memgpt.models import chat_completion_response
-from memgpt.interface import AgentInterface
from memgpt.persistence_manager import LocalStateManager
-from memgpt.system import get_login_event, package_function_response, package_summarize_message, get_initial_boot_messages
-from memgpt.memory import CoreMemory as InContextMemory, summarize_messages, ArchivalMemory, RecallMemory
-from memgpt.llm_api.llm_api_tools import create, is_context_overflow_error
+from memgpt.system import get_initial_boot_messages, get_login_event, package_function_response, package_summarize_message
from memgpt.utils import (
- get_utc_time,
+ count_tokens,
create_random_username,
- get_tool_call_id,
+ create_uuid_from_string,
get_local_time,
+ get_schema_diff,
+ get_tool_call_id,
+ get_utc_time,
+ is_utc_datetime,
parse_json,
- united_diff,
printd,
- count_tokens,
- get_schema_diff,
+ united_diff,
validate_function_response,
verify_first_message_correctness,
- create_uuid_from_string,
- is_utc_datetime,
-)
-from memgpt.constants import (
- FIRST_MESSAGE_ATTEMPTS,
- JSON_LOADS_STRICT,
- MESSAGE_SUMMARY_WARNING_FRAC,
- MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC,
- MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST,
- CORE_MEMORY_HUMAN_CHAR_LIMIT,
- CORE_MEMORY_PERSONA_CHAR_LIMIT,
- LLM_MAX_TOKENS,
- CLI_WARNING_PREFIX,
- JSON_ENSURE_ASCII,
)
+
from .errors import LLMError
from .functions.functions import USER_FUNCTIONS_DIR, load_all_function_sets
diff --git a/memgpt/agent_store/chroma.py b/memgpt/agent_store/chroma.py
index bccf1acf9..91e18c46b 100644
--- a/memgpt/agent_store/chroma.py
+++ b/memgpt/agent_store/chroma.py
@@ -1,13 +1,13 @@
import uuid
-from typing import Optional, List, Iterator, Dict, Tuple, cast
+from typing import Dict, Iterator, List, Optional, Tuple, cast
import chromadb
-from chromadb.api.types import Include, GetResult
+from chromadb.api.types import Include
from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.utils import printd, datetime_to_timestamp, timestamp_to_datetime
from memgpt.config import MemGPTConfig
-from memgpt.data_types import Record, Message, Passage, RecordType
+from memgpt.data_types import Passage, Record, RecordType
+from memgpt.utils import datetime_to_timestamp, printd, timestamp_to_datetime
class ChromaStorageConnector(StorageConnector):
diff --git a/memgpt/agent_store/db.py b/memgpt/agent_store/db.py
index 82a1b295b..8584f46d0 100644
--- a/memgpt/agent_store/db.py
+++ b/memgpt/agent_store/db.py
@@ -1,30 +1,39 @@
-import os
import base64
-from sqlalchemy import create_engine, Column, String, BIGINT, select, inspect, text, JSON, BLOB, BINARY, ARRAY, DateTime
-from sqlalchemy import func, or_, and_
-from sqlalchemy import desc, asc
-from sqlalchemy.orm import sessionmaker, mapped_column, declarative_base
-from sqlalchemy.orm.session import close_all_sessions
-from sqlalchemy.sql import func
-from sqlalchemy.dialects.postgresql import UUID
-from sqlalchemy_json import mutable_json_type, MutableJson
-from sqlalchemy import TypeDecorator, CHAR
+import os
import uuid
+from typing import Dict, Iterator, List, Optional
-from tqdm import tqdm
-from typing import Optional, List, Iterator, Dict
import numpy as np
+from sqlalchemy import (
+ BIGINT,
+ BINARY,
+ CHAR,
+ JSON,
+ Column,
+ DateTime,
+ String,
+ TypeDecorator,
+ and_,
+ asc,
+ create_engine,
+ desc,
+ func,
+ or_,
+ select,
+ text,
+)
+from sqlalchemy.dialects.postgresql import UUID
+from sqlalchemy.orm import declarative_base, mapped_column, sessionmaker
+from sqlalchemy.orm.session import close_all_sessions
+from sqlalchemy.sql import func
+from sqlalchemy_json import MutableJson
from tqdm import tqdm
-import pandas as pd
-from memgpt.settings import settings
-from memgpt.config import MemGPTConfig
from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.config import MemGPTConfig
-from memgpt.utils import printd
-from memgpt.data_types import Record, Message, Passage, ToolCall, RecordType
from memgpt.constants import MAX_EMBEDDING_DIM
-from memgpt.metadata import MetadataStore
+from memgpt.data_types import Message, Passage, Record, RecordType, ToolCall
+from memgpt.settings import settings
# Custom UUID type
diff --git a/memgpt/agent_store/lancedb.py b/memgpt/agent_store/lancedb.py
index 274693dc1..3f8c387e6 100644
--- a/memgpt/agent_store/lancedb.py
+++ b/memgpt/agent_store/lancedb.py
@@ -1,21 +1,14 @@
# type: ignore
-import lancedb
import uuid
from datetime import datetime
-from tqdm import tqdm
-from typing import Optional, List, Iterator, Dict
+from typing import Dict, Iterator, List, Optional
+
+from lancedb.pydantic import LanceModel, Vector
-from memgpt.config import MemGPTConfig
from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.config import AgentConfig, MemGPTConfig
-from memgpt.constants import MEMGPT_DIR
-from memgpt.utils import printd
-from memgpt.data_types import Record, Message, Passage, Source
-
-from datetime import datetime
-
-from lancedb.pydantic import Vector, LanceModel
+from memgpt.data_types import Message, Passage, Record
""" Initial implementation - not complete """
diff --git a/memgpt/agent_store/storage.py b/memgpt/agent_store/storage.py
index 89ee8eed9..a780a8efb 100644
--- a/memgpt/agent_store/storage.py
+++ b/memgpt/agent_store/storage.py
@@ -3,16 +3,12 @@
We originally tried to use Llama Index VectorIndex, but their limited API was extremely problematic.
"""
-from typing import Optional, List, Iterator, Union, Tuple, Type
import uuid
from abc import abstractmethod
-
-from typing import List, Optional, Dict
-from tqdm import tqdm
-
+from typing import Dict, Iterator, List, Optional, Tuple, Type, Union
from memgpt.config import MemGPTConfig
-from memgpt.data_types import Record, Passage, Document, Message, Source, RecordType
+from memgpt.data_types import Document, Message, Passage, Record, RecordType
from memgpt.utils import printd
diff --git a/memgpt/autogen/examples/agent_autoreply.py b/memgpt/autogen/examples/agent_autoreply.py
index abd8ffc2e..80304b6c7 100644
--- a/memgpt/autogen/examples/agent_autoreply.py
+++ b/memgpt/autogen/examples/agent_autoreply.py
@@ -10,9 +10,11 @@ Begin by doing:
"""
import os
+
import autogen
+
from memgpt.autogen.memgpt_agent import create_memgpt_autogen_agent_from_config
-from memgpt.constants import LLM_MAX_TOKENS, DEFAULT_PRESET
+from memgpt.constants import DEFAULT_PRESET, LLM_MAX_TOKENS
LLM_BACKEND = "openai"
# LLM_BACKEND = "azure"
diff --git a/memgpt/autogen/examples/agent_docs.py b/memgpt/autogen/examples/agent_docs.py
index 23429566a..c3c885a01 100644
--- a/memgpt/autogen/examples/agent_docs.py
+++ b/memgpt/autogen/examples/agent_docs.py
@@ -12,9 +12,11 @@ Begin by doing:
"""
import os
+
import autogen
+
from memgpt.autogen.memgpt_agent import create_memgpt_autogen_agent_from_config
-from memgpt.constants import LLM_MAX_TOKENS, DEFAULT_PRESET
+from memgpt.constants import DEFAULT_PRESET, LLM_MAX_TOKENS
LLM_BACKEND = "openai"
# LLM_BACKEND = "azure"
diff --git a/memgpt/autogen/examples/agent_groupchat.py b/memgpt/autogen/examples/agent_groupchat.py
index 271460c2b..e57ab7d9d 100644
--- a/memgpt/autogen/examples/agent_groupchat.py
+++ b/memgpt/autogen/examples/agent_groupchat.py
@@ -10,9 +10,11 @@ Begin by doing:
"""
import os
+
import autogen
-from memgpt.autogen.memgpt_agent import create_memgpt_autogen_agent_from_config, load_autogen_memgpt_agent
-from memgpt.constants import LLM_MAX_TOKENS, DEFAULT_PRESET
+
+from memgpt.autogen.memgpt_agent import create_memgpt_autogen_agent_from_config
+from memgpt.constants import DEFAULT_PRESET, LLM_MAX_TOKENS
LLM_BACKEND = "openai"
# LLM_BACKEND = "azure"
diff --git a/memgpt/autogen/interface.py b/memgpt/autogen/interface.py
index fcbd9bc12..0c3e81ca8 100644
--- a/memgpt/autogen/interface.py
+++ b/memgpt/autogen/interface.py
@@ -4,8 +4,8 @@ from typing import Optional
from colorama import Fore, Style, init
-from memgpt.data_types import Message
from memgpt.constants import CLI_WARNING_PREFIX, JSON_LOADS_STRICT
+from memgpt.data_types import Message
init(autoreset=True)
diff --git a/memgpt/autogen/memgpt_agent.py b/memgpt/autogen/memgpt_agent.py
index 5440de33b..695d7a199 100644
--- a/memgpt/autogen/memgpt_agent.py
+++ b/memgpt/autogen/memgpt_agent.py
@@ -1,22 +1,21 @@
-import uuid
import sys
-from typing import Callable, Optional, List, Dict, Union, Any, Tuple
+import uuid
+from typing import Any, Callable, Dict, List, Optional, Tuple, Union
-from autogen.agentchat import Agent, ConversableAgent, UserProxyAgent, GroupChat, GroupChatManager
+from autogen.agentchat import Agent, ConversableAgent, GroupChat, GroupChatManager, UserProxyAgent
-from memgpt.metadata import MetadataStore
+import memgpt.constants as constants
+import memgpt.system as system
+import memgpt.utils as utils
from memgpt.agent import Agent as MemGPTAgent
from memgpt.agent import save_agent
+from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.autogen.interface import AutoGenInterface
-import memgpt.system as system
-import memgpt.constants as constants
-import memgpt.utils as utils
-import memgpt.presets.presets as presets
+from memgpt.cli.cli_load import load_directory, load_vector_database
from memgpt.config import MemGPTConfig
from memgpt.credentials import MemGPTCredentials
-from memgpt.cli.cli_load import load_directory, load_vector_database
-from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.data_types import AgentState, User, LLMConfig, EmbeddingConfig
+from memgpt.data_types import EmbeddingConfig, LLMConfig, User
+from memgpt.metadata import MetadataStore
from memgpt.utils import get_human_text, get_persona_text
diff --git a/memgpt/benchmark/benchmark.py b/memgpt/benchmark/benchmark.py
index 094461ea2..50e28a7ef 100644
--- a/memgpt/benchmark/benchmark.py
+++ b/memgpt/benchmark/benchmark.py
@@ -1,17 +1,18 @@
# type: ignore
-import uuid
-import typer
import time
+import uuid
from typing import Annotated
+import typer
+
from memgpt import create_client
+from memgpt.benchmark.constants import HUMAN, PERSONA, PROMPTS, TRIES
from memgpt.config import MemGPTConfig
-from memgpt.utils import get_human_text, get_persona_text
# from memgpt.agent import Agent
from memgpt.errors import LLMJSONParsingError
-from memgpt.benchmark.constants import TRIES, PERSONA, HUMAN, PROMPTS
+from memgpt.utils import get_human_text, get_persona_text
app = typer.Typer()
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.py
index 02260050b..c39c47cd8 100644
--- a/memgpt/cli/cli.py
+++ b/memgpt/cli/cli.py
@@ -1,34 +1,32 @@
-import uuid
import json
-import requests
-import sys
import logging
-from pathlib import Path
import os
import subprocess
+import sys
+import uuid
from enum import Enum
+from pathlib import Path
from typing import Annotated, Optional
-import typer
import questionary
+import requests
+import typer
-from memgpt.log import logger
-
-# from memgpt.interface import CLIInterface as interface # for printing to terminal
-from memgpt.streaming_interface import StreamingRefreshCLIInterface as interface # for printing to terminal
-from memgpt.cli.cli_config import configure
-import memgpt.presets.presets as presets
import memgpt.utils as utils
-from memgpt.utils import printd, open_folder_in_explorer, suppress_stdout
+from memgpt.agent import Agent, save_agent
+from memgpt.cli.cli_config import configure
from memgpt.config import MemGPTConfig
+from memgpt.constants import CLI_WARNING_PREFIX, MEMGPT_DIR
from memgpt.credentials import MemGPTCredentials
-from memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIX, JSON_ENSURE_ASCII
-from memgpt.agent import Agent, save_agent
-from memgpt.embeddings import embedding_model
-from memgpt.server.constants import WS_DEFAULT_PORT, REST_DEFAULT_PORT
-from memgpt.data_types import AgentState, LLMConfig, EmbeddingConfig, User, Passage
+from memgpt.data_types import EmbeddingConfig, LLMConfig, User
+from memgpt.log import logger
from memgpt.metadata import MetadataStore
from memgpt.migrate import migrate_all_agents, migrate_all_sources
+from memgpt.server.constants import WS_DEFAULT_PORT
+
+# from memgpt.interface import CLIInterface as interface # for printing to terminal
+from memgpt.streaming_interface import StreamingRefreshCLIInterface as interface # for printing to terminal
+from memgpt.utils import open_folder_in_explorer, printd
def migrate(
@@ -326,8 +324,7 @@ def server(
# server_logger.addHandler(stream_handler)
if type == ServerChoice.rest_api:
- import uvicorn
- from memgpt.server.rest_api.server import app
+ pass
if MemGPTConfig.exists():
config = MemGPTConfig.load()
@@ -471,7 +468,7 @@ def run(
else:
logger.setLevel(logging.CRITICAL)
- from memgpt.migrate import config_is_compatible, wipe_config_and_reconfigure, VERSION_CUTOFF
+ from memgpt.migrate import VERSION_CUTOFF, config_is_compatible, wipe_config_and_reconfigure
if not config_is_compatible(allow_empty=True):
typer.secho(f"\nYour current config file is incompatible with MemGPT versions later than {VERSION_CUTOFF}\n", fg=typer.colors.RED)
diff --git a/memgpt/cli/cli_config.py b/memgpt/cli/cli_config.py
index a061b93eb..a34f5fa76 100644
--- a/memgpt/cli/cli_config.py
+++ b/memgpt/cli/cli_config.py
@@ -1,37 +1,32 @@
import builtins
import os
import uuid
-from typing import Annotated, Optional
from enum import Enum
-from typing import Annotated
+from typing import Annotated, Optional
import questionary
import typer
-from prettytable import PrettyTable, SINGLE_BORDER
from prettytable.colortable import ColorTable, Themes
from tqdm import tqdm
from memgpt import utils
from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.config import MemGPTConfig
-from memgpt.constants import LLM_MAX_TOKENS
-from memgpt.constants import MEMGPT_DIR
-from memgpt.credentials import MemGPTCredentials, SUPPORTED_AUTH_TYPES
-from memgpt.data_types import User, LLMConfig, EmbeddingConfig
-from memgpt.llm_api.openai import openai_get_model_list
-from memgpt.llm_api.azure_openai import azure_openai_get_model_list
-from memgpt.llm_api.google_ai import google_ai_get_model_list, google_ai_get_model_context_window
+from memgpt.constants import LLM_MAX_TOKENS, MEMGPT_DIR
+from memgpt.credentials import SUPPORTED_AUTH_TYPES, MemGPTCredentials
+from memgpt.data_types import EmbeddingConfig, LLMConfig, Source, User
from memgpt.llm_api.anthropic import anthropic_get_model_list, antropic_get_model_context_window
-from memgpt.llm_api.cohere import cohere_get_model_list, cohere_get_model_context_window, COHERE_VALID_MODEL_LIST
+from memgpt.llm_api.azure_openai import azure_openai_get_model_list
+from memgpt.llm_api.cohere import COHERE_VALID_MODEL_LIST, cohere_get_model_context_window, cohere_get_model_list
+from memgpt.llm_api.google_ai import google_ai_get_model_context_window, google_ai_get_model_list
from memgpt.llm_api.llm_api_tools import LLM_API_PROVIDER_OPTIONS
+from memgpt.llm_api.openai import openai_get_model_list
from memgpt.local_llm.constants import DEFAULT_ENDPOINTS, DEFAULT_OLLAMA_MODEL, DEFAULT_WRAPPER_NAME
from memgpt.local_llm.utils import get_available_wrappers
-from memgpt.server.utils import shorten_key_middle
-from memgpt.data_types import User, LLMConfig, EmbeddingConfig, Source
from memgpt.metadata import MetadataStore
-from memgpt.server.utils import shorten_key_middle
-from memgpt.models.pydantic_models import HumanModel, PersonaModel, PresetModel
+from memgpt.models.pydantic_models import HumanModel, PersonaModel
from memgpt.presets.presets import create_preset_from_file
+from memgpt.server.utils import shorten_key_middle
app = typer.Typer()
diff --git a/memgpt/cli/cli_load.py b/memgpt/cli/cli_load.py
index 8525899a8..783ad10b9 100644
--- a/memgpt/cli/cli_load.py
+++ b/memgpt/cli/cli_load.py
@@ -8,21 +8,16 @@ memgpt load <data-connector-type> --name <dataset-name> [ADDITIONAL ARGS]
"""
-from typing import List, Optional, Annotated
-from tqdm import tqdm
-import numpy as np
-import typer
import uuid
+from typing import Annotated, List, Optional
+
+import typer
-from memgpt.data_sources.connectors import load_data, DirectoryConnector, VectorDBConnector
-from memgpt.embeddings import embedding_model, check_and_split_text
-from memgpt.agent_store.storage import StorageConnector
+from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.config import MemGPTConfig
+from memgpt.data_sources.connectors import DirectoryConnector, VectorDBConnector, load_data
+from memgpt.data_types import Source
from memgpt.metadata import MetadataStore
-from memgpt.data_types import Source, Passage, Document, User
-from memgpt.utils import get_utc_time, suppress_stdout
-from memgpt.agent_store.storage import StorageConnector, TableType
-
app = typer.Typer()
diff --git a/memgpt/client/admin.py b/memgpt/client/admin.py
index dd2eea095..d57cd4e00 100644
--- a/memgpt/client/admin.py
+++ b/memgpt/client/admin.py
@@ -1,15 +1,16 @@
-from typing import Optional
import uuid
+from typing import Optional
+
import requests
from requests import HTTPError
from memgpt.server.rest_api.admin.users import (
- CreateUserResponse,
CreateAPIKeyResponse,
- GetAPIKeysResponse,
+ CreateUserResponse,
DeleteAPIKeyResponse,
DeleteUserResponse,
GetAllUsersResponse,
+ GetAPIKeysResponse,
)
diff --git a/memgpt/client/client.py b/memgpt/client/client.py
index 4324bdd10..f41ce1a99 100644
--- a/memgpt/client/client.py
+++ b/memgpt/client/client.py
@@ -1,38 +1,36 @@
import datetime
-import requests
-from requests.exceptions import RequestException
-import uuid
-from typing import Dict, List, Union, Optional, Tuple
import time
+import uuid
+from typing import Dict, List, Optional, Tuple, Union
+
+import requests
-from memgpt.data_types import AgentState, User, Preset, LLMConfig, EmbeddingConfig, Source
-from memgpt.models.pydantic_models import HumanModel, PersonaModel, PresetModel, SourceModel, JobModel, JobStatus
-from memgpt.cli.cli import QuickstartChoice
-from memgpt.cli.cli import set_config_with_dict, quickstart as quickstart_func, str_to_quickstart_choice
from memgpt.config import MemGPTConfig
-from memgpt.server.rest_api.interface import QueuingInterface
-from memgpt.server.server import SyncServer
-from memgpt.metadata import MetadataStore
from memgpt.data_sources.connectors import DataConnector
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, Preset, Source, User
+from memgpt.metadata import MetadataStore
+from memgpt.models.pydantic_models import HumanModel, JobModel, JobStatus, PersonaModel, PresetModel, SourceModel
# import pydantic response objects from memgpt.server.rest_api
from memgpt.server.rest_api.agents.command import CommandResponse
from memgpt.server.rest_api.agents.config import GetAgentResponse
+from memgpt.server.rest_api.agents.index import CreateAgentResponse, ListAgentsResponse
from memgpt.server.rest_api.agents.memory import (
- GetAgentMemoryResponse,
GetAgentArchivalMemoryResponse,
- UpdateAgentMemoryResponse,
+ GetAgentMemoryResponse,
InsertAgentArchivalMemoryResponse,
+ UpdateAgentMemoryResponse,
)
-from memgpt.server.rest_api.agents.index import ListAgentsResponse, CreateAgentResponse
-from memgpt.server.rest_api.agents.message import UserMessageResponse, GetAgentMessagesResponse
+from memgpt.server.rest_api.agents.message import GetAgentMessagesResponse, UserMessageResponse
from memgpt.server.rest_api.config.index import ConfigResponse
from memgpt.server.rest_api.humans.index import ListHumansResponse
-from memgpt.server.rest_api.personas.index import ListPersonasResponse
-from memgpt.server.rest_api.tools.index import ListToolsResponse, CreateToolResponse
+from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.rest_api.models.index import ListModelsResponse
+from memgpt.server.rest_api.personas.index import ListPersonasResponse
from memgpt.server.rest_api.presets.index import CreatePresetResponse, CreatePresetsRequest, ListPresetsResponse
-from memgpt.server.rest_api.sources.index import ListSourcesResponse, UploadFileToSourceResponse
+from memgpt.server.rest_api.sources.index import ListSourcesResponse
+from memgpt.server.rest_api.tools.index import CreateToolResponse, ListToolsResponse
+from memgpt.server.server import SyncServer
def create_client(base_url: Optional[str] = None, token: Optional[str] = None):
diff --git a/memgpt/config.py b/memgpt/config.py
index 50406b6b0..0db59ab2d 100644
--- a/memgpt/config.py
+++ b/memgpt/config.py
@@ -1,16 +1,15 @@
-from memgpt.log import logger
+import configparser
import inspect
import json
import os
import uuid
-from dataclasses import dataclass, field
-import configparser
+from dataclasses import dataclass
import memgpt
import memgpt.utils as utils
-
-from memgpt.constants import MEMGPT_DIR, DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
-from memgpt.data_types import AgentState, LLMConfig, EmbeddingConfig
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET, MEMGPT_DIR
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig
+from memgpt.log import logger
# helper functions for writing to configs
@@ -89,7 +88,7 @@ class MemGPTConfig:
@classmethod
def load(cls) -> "MemGPTConfig":
# avoid circular import
- from memgpt.migrate import config_is_compatible, VERSION_CUTOFF
+ from memgpt.migrate import VERSION_CUTOFF, config_is_compatible
from memgpt.utils import printd
if not config_is_compatible(allow_empty=True):
diff --git a/memgpt/constants.py b/memgpt/constants.py
index 4726b72d0..68ad7c5d1 100644
--- a/memgpt/constants.py
+++ b/memgpt/constants.py
@@ -1,5 +1,5 @@
import os
-from logging import CRITICAL, ERROR, WARN, WARNING, INFO, DEBUG, NOTSET
+from logging import CRITICAL, DEBUG, ERROR, INFO, NOTSET, WARN, WARNING
MEMGPT_DIR = os.path.join(os.path.expanduser("~"), ".memgpt")
diff --git a/memgpt/credentials.py b/memgpt/credentials.py
index a1d3afd33..f4b14b47c 100644
--- a/memgpt/credentials.py
+++ b/memgpt/credentials.py
@@ -1,20 +1,10 @@
-from memgpt.log import logger
+import configparser
import os
from dataclasses import dataclass
-import configparser
-import typer
-import questionary
from typing import Optional
-import memgpt
-import memgpt.utils as utils
-from memgpt.utils import printd, get_schema_diff
-from memgpt.functions.functions import load_all_function_sets
-
-from memgpt.constants import MEMGPT_DIR, LLM_MAX_TOKENS, DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
-from memgpt.data_types import AgentState, User, LLMConfig, EmbeddingConfig
from memgpt.config import get_field, set_field
-
+from memgpt.constants import MEMGPT_DIR
SUPPORTED_AUTH_TYPES = ["bearer_token", "api_key"]
@@ -102,7 +92,7 @@ class MemGPTCredentials:
return config
def save(self):
- import memgpt
+ pass
config = configparser.ConfigParser()
# openai config
diff --git a/memgpt/data_sources/connectors.py b/memgpt/data_sources/connectors.py
index 2128115a0..b893c9f2d 100644
--- a/memgpt/data_sources/connectors.py
+++ b/memgpt/data_sources/connectors.py
@@ -1,13 +1,13 @@
-from memgpt.data_types import Passage, Document, EmbeddingConfig, Source
-from memgpt.utils import create_uuid_from_string
-from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.embeddings import embedding_model
-from memgpt.data_types import Document, Passage
+from typing import Dict, Iterator, List, Optional, Tuple
-from typing import List, Iterator, Dict, Tuple, Optional
import typer
from llama_index.core import Document as LlamaIndexDocument
+from memgpt.agent_store.storage import StorageConnector
+from memgpt.data_types import Document, EmbeddingConfig, Passage, Source
+from memgpt.embeddings import embedding_model
+from memgpt.utils import create_uuid_from_string
+
class DataConnector:
def generate_documents(self) -> Iterator[Tuple[str, Dict]]: # -> Iterator[Document]:
@@ -202,8 +202,8 @@ class VectorDBConnector(DataConnector):
yield self.table_name, None
def generate_passages(self, documents: List[Document], chunk_size: int = 1024) -> Iterator[Tuple[str, Dict]]: # -> Iterator[Passage]:
- from sqlalchemy import select, MetaData, Table, Inspector
from pgvector.sqlalchemy import Vector
+ from sqlalchemy import Inspector, MetaData, Table, select
metadata = MetaData()
# Create an inspector to inspect the database
diff --git a/memgpt/data_types.py b/memgpt/data_types.py
index 2e7766820..e70c0796d 100644
--- a/memgpt/data_types.py
+++ b/memgpt/data_types.py
@@ -1,25 +1,16 @@
""" This module contains the data types used by MemGPT. Each data type must include a function to create a DB model. """
-import uuid
import json
+import uuid
from datetime import datetime, timezone
-from typing import Optional, List, Dict, TypeVar
+from typing import Dict, List, Optional, TypeVar
+
import numpy as np
-from pydantic import BaseModel, Field, Json
-
-from memgpt.constants import (
- DEFAULT_HUMAN,
- DEFAULT_MEMGPT_MODEL,
- DEFAULT_PERSONA,
- DEFAULT_PRESET,
- LLM_MAX_TOKENS,
- MAX_EMBEDDING_DIM,
- TOOL_CALL_ID_MAX_LEN,
-)
-from memgpt.utils import get_utc_time, create_uuid_from_string
-from memgpt.models import chat_completion_response
-from memgpt.utils import get_human_text, get_persona_text, printd, is_utc_datetime
-from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION
+from pydantic import BaseModel, Field
+
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, LLM_MAX_TOKENS, MAX_EMBEDDING_DIM, TOOL_CALL_ID_MAX_LEN
+from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG
+from memgpt.utils import create_uuid_from_string, get_human_text, get_persona_text, get_utc_time, is_utc_datetime
class Record:
diff --git a/memgpt/embeddings.py b/memgpt/embeddings.py
index ee7d4b80d..5fba83f29 100644
--- a/memgpt/embeddings.py
+++ b/memgpt/embeddings.py
@@ -1,17 +1,8 @@
-import typer
-import uuid
-from typing import Optional, List, Any
import os
-import numpy as np
-
-from memgpt.utils import is_valid_url, printd
-from memgpt.data_types import EmbeddingConfig
-from memgpt.credentials import MemGPTCredentials
-from memgpt.constants import MAX_EMBEDDING_DIM, EMBEDDING_TO_TOKENIZER_MAP, EMBEDDING_TO_TOKENIZER_DEFAULT
+import uuid
+from typing import Any, List, Optional
-# from llama_index.core.base.embeddings import BaseEmbedding
-from llama_index.core.node_parser import SentenceSplitter
-from llama_index.core import Document as LlamaIndexDocument
+import numpy as np
# from llama_index.core.base.embeddings import BaseEmbedding
# from llama_index.core.embeddings import BaseEmbedding
@@ -20,6 +11,15 @@ from llama_index.core import Document as LlamaIndexDocument
# from llama_index.embeddings.base import BaseEmbedding
# from llama_index.embeddings.huggingface_utils import format_text
import tiktoken
+from llama_index.core import Document as LlamaIndexDocument
+
+# from llama_index.core.base.embeddings import BaseEmbedding
+from llama_index.core.node_parser import SentenceSplitter
+
+from memgpt.constants import EMBEDDING_TO_TOKENIZER_DEFAULT, EMBEDDING_TO_TOKENIZER_MAP, MAX_EMBEDDING_DIM
+from memgpt.credentials import MemGPTCredentials
+from memgpt.data_types import EmbeddingConfig
+from memgpt.utils import is_valid_url, printd
def parse_and_chunk_text(text: str, chunk_size: int) -> List[str]:
diff --git a/memgpt/functions/function_sets/base.py b/memgpt/functions/function_sets/base.py
index 769a05d2e..562325e83 100644
--- a/memgpt/functions/function_sets/base.py
+++ b/memgpt/functions/function_sets/base.py
@@ -1,10 +1,10 @@
-from typing import Optional
import datetime
import json
import math
+from typing import Optional
-from memgpt.constants import MAX_PAUSE_HEARTBEATS, RETRIEVAL_QUERY_DEFAULT_PAGE_SIZE, JSON_ENSURE_ASCII
from memgpt.agent import Agent
+from memgpt.constants import JSON_ENSURE_ASCII, MAX_PAUSE_HEARTBEATS, RETRIEVAL_QUERY_DEFAULT_PAGE_SIZE
### Functions / tools the agent can use
# All functions should return a response string (or None)
diff --git a/memgpt/functions/function_sets/extras.py b/memgpt/functions/function_sets/extras.py
index 943c153ab..32379d161 100644
--- a/memgpt/functions/function_sets/extras.py
+++ b/memgpt/functions/function_sets/extras.py
@@ -1,18 +1,13 @@
-from typing import Optional
-import os
import json
-import requests
+import os
import uuid
+from typing import Optional
-from memgpt.constants import (
- JSON_LOADS_STRICT,
- MESSAGE_CHATGPT_FUNCTION_MODEL,
- MESSAGE_CHATGPT_FUNCTION_SYSTEM_MESSAGE,
- MAX_PAUSE_HEARTBEATS,
- JSON_ENSURE_ASCII,
-)
-from memgpt.llm_api.llm_api_tools import create
+import requests
+
+from memgpt.constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT, MESSAGE_CHATGPT_FUNCTION_MODEL, MESSAGE_CHATGPT_FUNCTION_SYSTEM_MESSAGE
from memgpt.data_types import Message
+from memgpt.llm_api.llm_api_tools import create
def message_chatgpt(self, message: str):
diff --git a/memgpt/functions/functions.py b/memgpt/functions/functions.py
index 5df29f640..329f60952 100644
--- a/memgpt/functions/functions.py
+++ b/memgpt/functions/functions.py
@@ -1,13 +1,12 @@
import importlib
import inspect
import os
-import warnings
import sys
+import warnings
from types import ModuleType
-
+from memgpt.constants import CLI_WARNING_PREFIX, MEMGPT_DIR
from memgpt.functions.schema_generator import generate_schema
-from memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIX
USER_FUNCTIONS_DIR = os.path.join(MEMGPT_DIR, "functions")
diff --git a/memgpt/functions/schema_generator.py b/memgpt/functions/schema_generator.py
index 189d0dfd5..bc891157f 100644
--- a/memgpt/functions/schema_generator.py
+++ b/memgpt/functions/schema_generator.py
@@ -5,7 +5,7 @@ from typing import get_args, get_origin
from docstring_parser import parse
from pydantic import BaseModel
-from memgpt.constants import FUNCTION_PARAM_NAME_REQ_HEARTBEAT, FUNCTION_PARAM_TYPE_REQ_HEARTBEAT, FUNCTION_PARAM_DESCRIPTION_REQ_HEARTBEAT
+from memgpt.constants import FUNCTION_PARAM_DESCRIPTION_REQ_HEARTBEAT, FUNCTION_PARAM_NAME_REQ_HEARTBEAT, FUNCTION_PARAM_TYPE_REQ_HEARTBEAT
NO_HEARTBEAT_FUNCTIONS = ["send_message", "pause_heartbeats"]
diff --git a/memgpt/interface.py b/memgpt/interface.py
index edfd86a2b..3e9c6c5c3 100644
--- a/memgpt/interface.py
+++ b/memgpt/interface.py
@@ -1,13 +1,13 @@
-from abc import ABC, abstractmethod
import json
import re
+from abc import ABC, abstractmethod
from typing import List, Optional
from colorama import Fore, Style, init
-from memgpt.utils import printd
from memgpt.constants import CLI_WARNING_PREFIX, JSON_LOADS_STRICT
from memgpt.data_types import Message
+from memgpt.utils import printd
init(autoreset=True)
diff --git a/memgpt/llm_api/anthropic.py b/memgpt/llm_api/anthropic.py
index cbe70206d..1de279e1a 100644
--- a/memgpt/llm_api/anthropic.py
+++ b/memgpt/llm_api/anthropic.py
@@ -1,20 +1,16 @@
-import requests
-import uuid
import json
import re
-from typing import Union, Optional, List
+import uuid
+from typing import List, Optional, Union
+
+import requests
from memgpt.data_types import Message
-from memgpt.models.chat_completion_response import (
- ChatCompletionResponse,
- UsageStatistics,
- Choice,
- Message as ChoiceMessage, # NOTE: avoid conflict with our own MemGPT Message datatype
- ToolCall,
- FunctionCall,
-)
from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool
-from memgpt.utils import smart_urljoin, get_utc_time
+from memgpt.models.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall
+from memgpt.models.chat_completion_response import Message as ChoiceMessage # NOTE: avoid conflict with our own MemGPT Message datatype
+from memgpt.models.chat_completion_response import ToolCall, UsageStatistics
+from memgpt.utils import get_utc_time, smart_urljoin
BASE_URL = "https://api.anthropic.com/v1"
diff --git a/memgpt/llm_api/azure_openai.py b/memgpt/llm_api/azure_openai.py
index f6190feab..dcf766fd5 100644
--- a/memgpt/llm_api/azure_openai.py
+++ b/memgpt/llm_api/azure_openai.py
@@ -1,11 +1,11 @@
-import requests
from typing import Union
+import requests
+
from memgpt.models.chat_completion_response import ChatCompletionResponse
from memgpt.models.embedding_response import EmbeddingResponse
from memgpt.utils import smart_urljoin
-
MODEL_TO_AZURE_ENGINE = {
"gpt-4-1106-preview": "gpt-4",
"gpt-4": "gpt-4",
diff --git a/memgpt/llm_api/cohere.py b/memgpt/llm_api/cohere.py
index 753576a2d..9cf8c9780 100644
--- a/memgpt/llm_api/cohere.py
+++ b/memgpt/llm_api/cohere.py
@@ -1,22 +1,17 @@
-import requests
-import uuid
import json
-import re
-from typing import Union, Optional, List
+import uuid
+from typing import List, Optional, Union
+import requests
+
+from memgpt.constants import JSON_ENSURE_ASCII
from memgpt.data_types import Message
-from memgpt.models.chat_completion_response import (
- ChatCompletionResponse,
- UsageStatistics,
- Choice,
- Message as ChoiceMessage, # NOTE: avoid conflict with our own MemGPT Message datatype
- ToolCall,
- FunctionCall,
-)
-from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool
-from memgpt.utils import smart_urljoin, get_utc_time, get_tool_call_id
-from memgpt.constants import NON_USER_MSG_PREFIX, JSON_ENSURE_ASCII
from memgpt.local_llm.utils import count_tokens
+from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool
+from memgpt.models.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall
+from memgpt.models.chat_completion_response import Message as ChoiceMessage # NOTE: avoid conflict with our own MemGPT Message datatype
+from memgpt.models.chat_completion_response import ToolCall, UsageStatistics
+from memgpt.utils import get_tool_call_id, get_utc_time, smart_urljoin
BASE_URL = "https://api.cohere.ai/v1"
@@ -168,7 +163,7 @@ def convert_cohere_response_to_chatcompletion(
function_name = tool_call_response["name"]
function_args = tool_call_response["parameters"]
if inner_thoughts_in_kwargs:
- from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION
+ from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG
assert INNER_THOUGHTS_KWARG in function_args
# NOTE:
diff --git a/memgpt/llm_api/google_ai.py b/memgpt/llm_api/google_ai.py
index e0facf642..b03f623bd 100644
--- a/memgpt/llm_api/google_ai.py
+++ b/memgpt/llm_api/google_ai.py
@@ -1,15 +1,15 @@
-import requests
import json
import uuid
-from typing import Union, List, Optional
+from typing import List, Optional
-from memgpt.models.chat_completion_response import ChatCompletionResponse, Choice, Message, ToolCall, FunctionCall, UsageStatistics
-from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool
-from memgpt.models.embedding_response import EmbeddingResponse
-from memgpt.utils import smart_urljoin, get_tool_call_id, get_utc_time
-from memgpt.local_llm.utils import count_tokens
+import requests
+
+from memgpt.constants import JSON_ENSURE_ASCII, NON_USER_MSG_PREFIX
from memgpt.local_llm.json_parser import clean_json_string_extra_backslash
-from memgpt.constants import NON_USER_MSG_PREFIX, JSON_ENSURE_ASCII
+from memgpt.local_llm.utils import count_tokens
+from memgpt.models.chat_completion_request import Tool
+from memgpt.models.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall, Message, ToolCall, UsageStatistics
+from memgpt.utils import get_tool_call_id, get_utc_time
# from memgpt.data_types import ToolCall
@@ -282,7 +282,7 @@ def convert_google_ai_response_to_chatcompletion(
# NOTE: this also involves stripping the inner monologue out of the function
if pull_inner_thoughts_from_args:
- from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION
+ from memgpt.local_llm.constants import INNER_THOUGHTS_KWARG
assert INNER_THOUGHTS_KWARG in function_args, f"Couldn't find inner thoughts in function args:\n{function_call}"
inner_thoughts = function_args.pop(INNER_THOUGHTS_KWARG)
diff --git a/memgpt/llm_api/llm_api_tools.py b/memgpt/llm_api/llm_api_tools.py
index fbbaa2f6b..3582e6f08 100644
--- a/memgpt/llm_api/llm_api_tools.py
+++ b/memgpt/llm_api/llm_api_tools.py
@@ -1,28 +1,22 @@
-import random
-import time
-import requests
import os
+import random
import time
from typing import List, Optional, Union
-from memgpt.credentials import MemGPTCredentials
-from memgpt.local_llm.chat_completion_proxy import get_chat_completion
-from memgpt.constants import CLI_WARNING_PREFIX
-from memgpt.models.chat_completion_response import ChatCompletionResponse
-from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool, cast_message_to_subtype
-from memgpt.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface
+import requests
+from memgpt.constants import CLI_WARNING_PREFIX
+from memgpt.credentials import MemGPTCredentials
from memgpt.data_types import AgentState, Message
-
-from memgpt.llm_api.openai import openai_chat_completions_request, openai_chat_completions_process_stream
-from memgpt.llm_api.azure_openai import azure_openai_chat_completions_request, MODEL_TO_AZURE_ENGINE
-from memgpt.llm_api.google_ai import (
- google_ai_chat_completions_request,
- convert_tools_to_google_ai_format,
-)
from memgpt.llm_api.anthropic import anthropic_chat_completions_request
+from memgpt.llm_api.azure_openai import MODEL_TO_AZURE_ENGINE, azure_openai_chat_completions_request
from memgpt.llm_api.cohere import cohere_chat_completions_request
-
+from memgpt.llm_api.google_ai import convert_tools_to_google_ai_format, google_ai_chat_completions_request
+from memgpt.llm_api.openai import openai_chat_completions_process_stream, openai_chat_completions_request
+from memgpt.local_llm.chat_completion_proxy import get_chat_completion
+from memgpt.models.chat_completion_request import ChatCompletionRequest, Tool, cast_message_to_subtype
+from memgpt.models.chat_completion_response import ChatCompletionResponse
+from memgpt.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface
LLM_API_PROVIDER_OPTIONS = ["openai", "azure", "anthropic", "google_ai", "cohere", "local"]
@@ -82,7 +76,7 @@ def retry_with_exponential_backoff(
"""Retry a function with exponential backoff."""
def wrapper(*args, **kwargs):
- from memgpt.utils import printd
+ pass
# Initialize variables
num_retries = 0
diff --git a/memgpt/llm_api/openai.py b/memgpt/llm_api/openai.py
index 8b4d34747..aa864230c 100644
--- a/memgpt/llm_api/openai.py
+++ b/memgpt/llm_api/openai.py
@@ -1,26 +1,25 @@
-import requests
import json
+from typing import Generator, Optional, Union
+
import httpx
+import requests
from httpx_sse import connect_sse
from httpx_sse._exceptions import SSEError
-from typing import Union, Optional, Generator
+from memgpt.local_llm.utils import num_tokens_from_functions, num_tokens_from_messages
+from memgpt.models.chat_completion_request import ChatCompletionRequest
from memgpt.models.chat_completion_response import (
+ ChatCompletionChunkResponse,
ChatCompletionResponse,
Choice,
+ FunctionCall,
Message,
ToolCall,
- FunctionCall,
UsageStatistics,
- ChatCompletionChunkResponse,
)
-from memgpt.models.chat_completion_request import ChatCompletionRequest
from memgpt.models.embedding_response import EmbeddingResponse
-from memgpt.utils import smart_urljoin, get_utc_time
-from memgpt.local_llm.utils import num_tokens_from_messages, num_tokens_from_functions
-from memgpt.interface import AgentInterface
from memgpt.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface
-
+from memgpt.utils import get_utc_time, smart_urljoin
OPENAI_SSE_DONE = "[DONE]"
diff --git a/memgpt/local_llm/chat_completion_proxy.py b/memgpt/local_llm/chat_completion_proxy.py
index 47b8c9d56..e8baab707 100644
--- a/memgpt/local_llm/chat_completion_proxy.py
+++ b/memgpt/local_llm/chat_completion_proxy.py
@@ -1,27 +1,27 @@
"""Key idea: create drop-in replacement for agent's ChatCompletion call that runs on an OpenLLM backend"""
-from datetime import datetime
-import requests
import json
import uuid
+import requests
+
+from memgpt.constants import CLI_WARNING_PREFIX, JSON_ENSURE_ASCII
+from memgpt.errors import LocalLLMConnectionError, LocalLLMError
+from memgpt.local_llm.constants import DEFAULT_WRAPPER
+from memgpt.local_llm.function_parser import patch_function
from memgpt.local_llm.grammars.gbnf_grammar_generator import create_dynamic_model_from_function, generate_gbnf_grammar_and_documentation
-from memgpt.local_llm.webui.api import get_webui_completion
-from memgpt.local_llm.webui.legacy_api import get_webui_completion as get_webui_completion_legacy
-from memgpt.local_llm.lmstudio.api import get_lmstudio_completion
-from memgpt.local_llm.llamacpp.api import get_llamacpp_completion
+from memgpt.local_llm.groq.api import get_groq_completion
from memgpt.local_llm.koboldcpp.api import get_koboldcpp_completion
+from memgpt.local_llm.llamacpp.api import get_llamacpp_completion
+from memgpt.local_llm.llm_chat_completion_wrappers import simple_summary_wrapper
+from memgpt.local_llm.lmstudio.api import get_lmstudio_completion
from memgpt.local_llm.ollama.api import get_ollama_completion
+from memgpt.local_llm.utils import count_tokens, get_available_wrappers
from memgpt.local_llm.vllm.api import get_vllm_completion
-from memgpt.local_llm.groq.api import get_groq_completion
-from memgpt.local_llm.llm_chat_completion_wrappers import simple_summary_wrapper
-from memgpt.local_llm.constants import DEFAULT_WRAPPER
-from memgpt.local_llm.utils import get_available_wrappers, count_tokens
-from memgpt.local_llm.function_parser import patch_function
-from memgpt.prompts.gpt_summarize import SYSTEM as SUMMARIZE_SYSTEM_MESSAGE
-from memgpt.errors import LocalLLMConnectionError, LocalLLMError
-from memgpt.constants import CLI_WARNING_PREFIX, JSON_ENSURE_ASCII
+from memgpt.local_llm.webui.api import get_webui_completion
+from memgpt.local_llm.webui.legacy_api import get_webui_completion as get_webui_completion_legacy
from memgpt.models.chat_completion_response import ChatCompletionResponse, Choice, Message, ToolCall, UsageStatistics
+from memgpt.prompts.gpt_summarize import SYSTEM as SUMMARIZE_SYSTEM_MESSAGE
from memgpt.utils import get_tool_call_id, get_utc_time
has_shown_warning = False
diff --git a/memgpt/local_llm/constants.py b/memgpt/local_llm/constants.py
index b47c0a3be..d25374b4f 100644
--- a/memgpt/local_llm/constants.py
+++ b/memgpt/local_llm/constants.py
@@ -1,5 +1,5 @@
# import memgpt.local_llm.llm_chat_completion_wrappers.airoboros as airoboros
-from memgpt.local_llm.llm_chat_completion_wrappers.chatml import ChatMLInnerMonologueWrapper, ChatMLOuterInnerMonologueWrapper
+from memgpt.local_llm.llm_chat_completion_wrappers.chatml import ChatMLInnerMonologueWrapper
DEFAULT_ENDPOINTS = {
# Local
diff --git a/memgpt/local_llm/grammars/gbnf_grammar_generator.py b/memgpt/local_llm/grammars/gbnf_grammar_generator.py
index a1d2f937f..b1c96e52e 100644
--- a/memgpt/local_llm/grammars/gbnf_grammar_generator.py
+++ b/memgpt/local_llm/grammars/gbnf_grammar_generator.py
@@ -1,15 +1,14 @@
import inspect
import json
+import re
from copy import copy
-from inspect import isclass, getdoc
+from enum import Enum
+from inspect import getdoc, isclass
from types import NoneType
+from typing import Any, Callable, List, Optional, Tuple, Type, Union, _GenericAlias, get_args, get_origin
from docstring_parser import parse
-from pydantic import BaseModel, create_model, Field
-from typing import Any, Type, List, get_args, get_origin, Tuple, Union, Optional, _GenericAlias
-from enum import Enum
-from typing import Callable
-import re
+from pydantic import BaseModel, create_model
class PydanticDataType(Enum):
diff --git a/memgpt/local_llm/groq/api.py b/memgpt/local_llm/groq/api.py
index c680af301..289f047f6 100644
--- a/memgpt/local_llm/groq/api.py
+++ b/memgpt/local_llm/groq/api.py
@@ -1,12 +1,10 @@
-from urllib.parse import urljoin
-import requests
from typing import Tuple
+from urllib.parse import urljoin
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import post_json_auth_request
from memgpt.utils import count_tokens
-
API_CHAT_SUFFIX = "/v1/chat/completions"
# LMSTUDIO_API_COMPLETIONS_SUFFIX = "/v1/completions"
diff --git a/memgpt/local_llm/json_parser.py b/memgpt/local_llm/json_parser.py
index 1f7a7cbc4..0c8bbe033 100644
--- a/memgpt/local_llm/json_parser.py
+++ b/memgpt/local_llm/json_parser.py
@@ -1,7 +1,7 @@
import json
import re
-from memgpt.constants import JSON_LOADS_STRICT
+from memgpt.constants import JSON_LOADS_STRICT
from memgpt.errors import LLMJSONParsingError
diff --git a/memgpt/local_llm/koboldcpp/api.py b/memgpt/local_llm/koboldcpp/api.py
index a6ac87e04..06b351fa3 100644
--- a/memgpt/local_llm/koboldcpp/api.py
+++ b/memgpt/local_llm/koboldcpp/api.py
@@ -1,5 +1,4 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import count_tokens, post_json_auth_request
diff --git a/memgpt/local_llm/koboldcpp/settings.py b/memgpt/local_llm/koboldcpp/settings.py
index c3a47dfab..51f495653 100644
--- a/memgpt/local_llm/koboldcpp/settings.py
+++ b/memgpt/local_llm/koboldcpp/settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
# see https://lite.koboldai.net/koboldcpp_api#/v1/post_v1_generate
SIMPLE = {
"stop_sequence": [
diff --git a/memgpt/local_llm/llamacpp/api.py b/memgpt/local_llm/llamacpp/api.py
index 438fe7d51..50e27e41c 100644
--- a/memgpt/local_llm/llamacpp/api.py
+++ b/memgpt/local_llm/llamacpp/api.py
@@ -1,10 +1,8 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import count_tokens, post_json_auth_request
-
LLAMACPP_API_SUFFIX = "/completion"
diff --git a/memgpt/local_llm/llamacpp/settings.py b/memgpt/local_llm/llamacpp/settings.py
index 870afc2a1..c352a1c8a 100644
--- a/memgpt/local_llm/llamacpp/settings.py
+++ b/memgpt/local_llm/llamacpp/settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
# see https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md#api-endpoints for options
SIMPLE = {
"stop": [
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py b/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
index bbcab1b95..352a1b3f9 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py
@@ -1,9 +1,9 @@
import json
-from .wrapper_base import LLMChatCompletionWrapper
-from ..json_parser import clean_json
from ...constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
from ...errors import LLMJSONParsingError
+from ..json_parser import clean_json
+from .wrapper_base import LLMChatCompletionWrapper
class Airoboros21Wrapper(LLMChatCompletionWrapper):
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
index b824bf762..d1952b334 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/chatml.py
@@ -1,10 +1,9 @@
import json
-from memgpt.local_llm.llm_chat_completion_wrappers.wrapper_base import LLMChatCompletionWrapper
-from memgpt.local_llm.json_parser import clean_json
from memgpt.constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
from memgpt.errors import LLMJSONParsingError
-
+from memgpt.local_llm.json_parser import clean_json
+from memgpt.local_llm.llm_chat_completion_wrappers.wrapper_base import LLMChatCompletionWrapper
PREFIX_HINT = """# Reminders:
# Important information about yourself and the user is stored in (limited) core memory
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py b/memgpt/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py
index 0c9be182e..cf5478dee 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py
@@ -2,11 +2,10 @@ import json
import yaml
-from .wrapper_base import LLMChatCompletionWrapper
from ...constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
-from ..json_parser import clean_json
-from ...constants import JSON_ENSURE_ASCII
from ...errors import LLMJSONParsingError
+from ..json_parser import clean_json
+from .wrapper_base import LLMChatCompletionWrapper
# A configurable model agnostic wrapper.
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py b/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
index 6edb78086..e2056d928 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/dolphin.py
@@ -1,9 +1,9 @@
import json
-from .wrapper_base import LLMChatCompletionWrapper
-from ..json_parser import clean_json
from ...constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
from ...errors import LLMJSONParsingError
+from ..json_parser import clean_json
+from .wrapper_base import LLMChatCompletionWrapper
class Dolphin21MistralWrapper(LLMChatCompletionWrapper):
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py b/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
index 82fcf8020..1f0c72d7e 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/simple_summary_wrapper.py
@@ -1,6 +1,7 @@
import json
-from .wrapper_base import LLMChatCompletionWrapper
+
from ...constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
+from .wrapper_base import LLMChatCompletionWrapper
class SimpleSummaryWrapper(LLMChatCompletionWrapper):
diff --git a/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py b/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
index 60cc6056e..4eda496d8 100644
--- a/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
+++ b/memgpt/local_llm/llm_chat_completion_wrappers/zephyr.py
@@ -1,9 +1,9 @@
import json
-from .wrapper_base import LLMChatCompletionWrapper
-from ..json_parser import clean_json
from ...constants import JSON_ENSURE_ASCII
from ...errors import LLMJSONParsingError
+from ..json_parser import clean_json
+from .wrapper_base import LLMChatCompletionWrapper
class ZephyrMistralWrapper(LLMChatCompletionWrapper):
diff --git a/memgpt/local_llm/lmstudio/api.py b/memgpt/local_llm/lmstudio/api.py
index a82b827b4..f4f22ece1 100644
--- a/memgpt/local_llm/lmstudio/api.py
+++ b/memgpt/local_llm/lmstudio/api.py
@@ -1,11 +1,9 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import post_json_auth_request
from memgpt.utils import count_tokens
-
LMSTUDIO_API_CHAT_SUFFIX = "/v1/chat/completions"
LMSTUDIO_API_COMPLETIONS_SUFFIX = "/v1/completions"
diff --git a/memgpt/local_llm/lmstudio/settings.py b/memgpt/local_llm/lmstudio/settings.py
index e102577dd..5070884ad 100644
--- a/memgpt/local_llm/lmstudio/settings.py
+++ b/memgpt/local_llm/lmstudio/settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
SIMPLE = {
"stop": [
"\nUSER:",
diff --git a/memgpt/local_llm/ollama/api.py b/memgpt/local_llm/ollama/api.py
index b8471328e..a9003fe65 100644
--- a/memgpt/local_llm/ollama/api.py
+++ b/memgpt/local_llm/ollama/api.py
@@ -1,12 +1,9 @@
from urllib.parse import urljoin
-import requests
-
+from memgpt.errors import LocalLLMError
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import post_json_auth_request
from memgpt.utils import count_tokens
-from memgpt.errors import LocalLLMError
-
OLLAMA_API_SUFFIX = "/api/generate"
diff --git a/memgpt/local_llm/ollama/settings.py b/memgpt/local_llm/ollama/settings.py
index 47f340338..eb68317ac 100644
--- a/memgpt/local_llm/ollama/settings.py
+++ b/memgpt/local_llm/ollama/settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
# see https://github.com/jmorganca/ollama/blob/main/docs/api.md
# and https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values
SIMPLE = {
diff --git a/memgpt/local_llm/settings/settings.py b/memgpt/local_llm/settings/settings.py
index 09f3824ff..84a6181c7 100644
--- a/memgpt/local_llm/settings/settings.py
+++ b/memgpt/local_llm/settings/settings.py
@@ -1,10 +1,9 @@
import json
import os
-from memgpt.constants import MEMGPT_DIR, JSON_ENSURE_ASCII
-from memgpt.local_llm.settings.simple import settings as simple_settings
+from memgpt.constants import JSON_ENSURE_ASCII, MEMGPT_DIR
from memgpt.local_llm.settings.deterministic_mirostat import settings as det_miro_settings
-
+from memgpt.local_llm.settings.simple import settings as simple_settings
DEFAULT = "simple"
SETTINGS_FOLDER_NAME = "settings"
diff --git a/memgpt/local_llm/utils.py b/memgpt/local_llm/utils.py
index 15c85c286..c41e66b41 100644
--- a/memgpt/local_llm/utils.py
+++ b/memgpt/local_llm/utils.py
@@ -1,13 +1,14 @@
import os
+from typing import List
+
import requests
import tiktoken
-from typing import List
import memgpt.local_llm.llm_chat_completion_wrappers.airoboros as airoboros
-import memgpt.local_llm.llm_chat_completion_wrappers.dolphin as dolphin
-import memgpt.local_llm.llm_chat_completion_wrappers.zephyr as zephyr
import memgpt.local_llm.llm_chat_completion_wrappers.chatml as chatml
import memgpt.local_llm.llm_chat_completion_wrappers.configurable_wrapper as configurable_wrapper
+import memgpt.local_llm.llm_chat_completion_wrappers.dolphin as dolphin
+import memgpt.local_llm.llm_chat_completion_wrappers.zephyr as zephyr
def post_json_auth_request(uri, json_payload, auth_type, auth_key):
diff --git a/memgpt/local_llm/vllm/api.py b/memgpt/local_llm/vllm/api.py
index a22a1fb14..e10a0e2dc 100644
--- a/memgpt/local_llm/vllm/api.py
+++ b/memgpt/local_llm/vllm/api.py
@@ -1,5 +1,4 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import count_tokens, post_json_auth_request
diff --git a/memgpt/local_llm/webui/api.py b/memgpt/local_llm/webui/api.py
index 5751591d2..f9168804e 100644
--- a/memgpt/local_llm/webui/api.py
+++ b/memgpt/local_llm/webui/api.py
@@ -1,5 +1,4 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import count_tokens, post_json_auth_request
diff --git a/memgpt/local_llm/webui/legacy_api.py b/memgpt/local_llm/webui/legacy_api.py
index 6fc99c38d..b2f62ac29 100644
--- a/memgpt/local_llm/webui/legacy_api.py
+++ b/memgpt/local_llm/webui/legacy_api.py
@@ -1,5 +1,4 @@
from urllib.parse import urljoin
-import requests
from memgpt.local_llm.settings.settings import get_completions_settings
from memgpt.local_llm.utils import count_tokens, post_json_auth_request
diff --git a/memgpt/local_llm/webui/legacy_settings.py b/memgpt/local_llm/webui/legacy_settings.py
index cdccc67be..d2f09903a 100644
--- a/memgpt/local_llm/webui/legacy_settings.py
+++ b/memgpt/local_llm/webui/legacy_settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
SIMPLE = {
"stopping_strings": [
"\nUSER:",
diff --git a/memgpt/local_llm/webui/settings.py b/memgpt/local_llm/webui/settings.py
index 57c775489..27da3e748 100644
--- a/memgpt/local_llm/webui/settings.py
+++ b/memgpt/local_llm/webui/settings.py
@@ -1,5 +1,3 @@
-from ...constants import LLM_MAX_TOKENS
-
SIMPLE = {
# "stopping_strings": [
"stop": [
diff --git a/memgpt/log.py b/memgpt/log.py
index 24fef9d39..966ed7349 100644
--- a/memgpt/log.py
+++ b/memgpt/log.py
@@ -1,15 +1,9 @@
+import logging
import os
import os.path
-import logging
from logging.handlers import RotatingFileHandler
-from memgpt.constants import (
- LOGGER_NAME,
- LOGGER_DEFAULT_LEVEL,
- LOGGER_DIR,
- LOGGER_FILENAME,
- LOGGER_FILE_BACKUP_COUNT,
- LOGGER_MAX_FILE_SIZE,
-)
+
+from memgpt.constants import LOGGER_DEFAULT_LEVEL, LOGGER_DIR, LOGGER_FILE_BACKUP_COUNT, LOGGER_FILENAME, LOGGER_MAX_FILE_SIZE, LOGGER_NAME
# Checking if log directory exists
if not os.path.exists(LOGGER_DIR):
diff --git a/memgpt/main.py b/memgpt/main.py
index c6329aa5b..a7ac035ca 100644
--- a/memgpt/main.py
+++ b/memgpt/main.py
@@ -1,30 +1,29 @@
+import json
import os
import sys
import traceback
-import requests
-import json
import questionary
+import requests
import typer
-
from rich.console import Console
-from memgpt.constants import FUNC_FAILED_HEARTBEAT_MESSAGE, JSON_ENSURE_ASCII, JSON_LOADS_STRICT, REQ_HEARTBEAT_MESSAGE
-from memgpt.agent_store.storage import StorageConnector, TableType
-
-# from memgpt.interface import CLIInterface as interface # for printing to terminal
-from memgpt.streaming_interface import AgentRefreshStreamingInterface
-from memgpt.config import MemGPTConfig
import memgpt.agent as agent
-import memgpt.system as system
import memgpt.errors as errors
-from memgpt.cli.cli import run, version, server, open_folder, quickstart, migrate, delete_agent
-from memgpt.cli.cli_config import configure, list, add, delete
-from memgpt.cli.cli_load import app as load_app
-from memgpt.metadata import MetadataStore
+import memgpt.system as system
+from memgpt.agent_store.storage import StorageConnector, TableType
# import benchmark
from memgpt.benchmark.benchmark import bench
+from memgpt.cli.cli import delete_agent, migrate, open_folder, quickstart, run, server, version
+from memgpt.cli.cli_config import add, configure, delete, list
+from memgpt.cli.cli_load import app as load_app
+from memgpt.config import MemGPTConfig
+from memgpt.constants import FUNC_FAILED_HEARTBEAT_MESSAGE, JSON_ENSURE_ASCII, JSON_LOADS_STRICT, REQ_HEARTBEAT_MESSAGE
+from memgpt.metadata import MetadataStore
+
+# from memgpt.interface import CLIInterface as interface # for printing to terminal
+from memgpt.streaming_interface import AgentRefreshStreamingInterface
# interface = interface()
diff --git a/memgpt/memory.py b/memgpt/memory.py
index aed8f102f..92c91474c 100644
--- a/memgpt/memory.py
+++ b/memgpt/memory.py
@@ -1,14 +1,14 @@
-from abc import ABC, abstractmethod
import datetime
import uuid
-from typing import Optional, List, Tuple, Union
+from abc import ABC, abstractmethod
+from typing import List, Optional, Tuple, Union
-from memgpt.constants import MESSAGE_SUMMARY_WARNING_FRAC, MESSAGE_SUMMARY_REQUEST_ACK
-from memgpt.utils import get_local_time, printd, count_tokens, validate_date_format, extract_date_from_timestamp
-from memgpt.prompts.gpt_summarize import SYSTEM as SUMMARY_PROMPT_SYSTEM
+from memgpt.constants import MESSAGE_SUMMARY_REQUEST_ACK, MESSAGE_SUMMARY_WARNING_FRAC
+from memgpt.data_types import AgentState, Message, Passage
+from memgpt.embeddings import embedding_model, parse_and_chunk_text, query_embedding
from memgpt.llm_api.llm_api_tools import create
-from memgpt.data_types import Message, Passage, AgentState
-from memgpt.embeddings import embedding_model, query_embedding, parse_and_chunk_text
+from memgpt.prompts.gpt_summarize import SYSTEM as SUMMARY_PROMPT_SYSTEM
+from memgpt.utils import count_tokens, extract_date_from_timestamp, get_local_time, printd, validate_date_format
# from llama_index import Document
# from llama_index.node_parser import SimpleNodeParser
@@ -370,7 +370,6 @@ class EmbeddingArchivalMemory(ArchivalMemory):
:type archival_memory_database: str
"""
from memgpt.agent_store.storage import StorageConnector
- from memgpt.config import MemGPTConfig
self.top_k = top_k
self.agent_state = agent_state
diff --git a/memgpt/metadata.py b/memgpt/metadata.py
index 2450884d4..a48bde519 100644
--- a/memgpt/metadata.py
+++ b/memgpt/metadata.py
@@ -1,31 +1,22 @@
""" Metadata store for user/agent/data_source information"""
-import os
import inspect as python_inspect
-import uuid
+import os
import secrets
-from typing import Optional, List
-
-from memgpt.settings import settings
-from memgpt.constants import DEFAULT_HUMAN, DEFAULT_MEMGPT_MODEL, DEFAULT_PERSONA, DEFAULT_PRESET, LLM_MAX_TOKENS
-from memgpt.utils import enforce_types, printd, get_utc_time
-from memgpt.data_types import AgentState, Source, User, LLMConfig, EmbeddingConfig, Token, Preset
-from memgpt.config import MemGPTConfig
-from memgpt.functions.functions import load_all_function_sets
-
-from memgpt.models.pydantic_models import PersonaModel, HumanModel, ToolModel, JobModel, JobStatus
+import uuid
+from typing import List, Optional
-from sqlalchemy import create_engine, Column, String, BIGINT, select, inspect, text, JSON, BLOB, BINARY, ARRAY, Boolean
-from sqlalchemy import func
-from sqlalchemy.orm import sessionmaker, mapped_column, declarative_base
-from sqlalchemy.orm.session import close_all_sessions
+from sqlalchemy import BIGINT, CHAR, JSON, Boolean, Column, DateTime, String, TypeDecorator, create_engine, func, inspect
+from sqlalchemy.dialects.postgresql import UUID
+from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.sql import func
-from sqlalchemy import Column, BIGINT, String, DateTime
-from sqlalchemy.dialects.postgresql import JSONB, UUID
-from sqlalchemy_json import mutable_json_type, MutableJson
-from sqlalchemy import TypeDecorator, CHAR
-from sqlalchemy.orm import sessionmaker, mapped_column, declarative_base
+from memgpt.config import MemGPTConfig
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, Preset, Source, Token, User
+from memgpt.functions.functions import load_all_function_sets
+from memgpt.models.pydantic_models import HumanModel, JobModel, JobStatus, PersonaModel, ToolModel
+from memgpt.settings import settings
+from memgpt.utils import enforce_types, get_utc_time, printd
Base = declarative_base()
diff --git a/memgpt/migrate.py b/memgpt/migrate.py
index e37b02788..5d424ddb4 100644
--- a/memgpt/migrate.py
+++ b/memgpt/migrate.py
@@ -1,36 +1,35 @@
import configparser
-from datetime import datetime
+import glob
+import json
import os
import pickle
-import glob
+import shutil
import sys
import traceback
import uuid
-import json
-import shutil
-from typing import Optional, List
-import pytz
+from datetime import datetime
+from typing import List, Optional
+import pytz
+import questionary
import typer
from tqdm import tqdm
-import questionary
-
from memgpt.agent import Agent, save_agent
-from memgpt.data_types import AgentState, User, Passage, Source, Message
+from memgpt.agent_store.storage import StorageConnector, TableType
+from memgpt.cli.cli_config import configure
+from memgpt.config import MemGPTConfig
+from memgpt.data_types import AgentState, Message, Passage, Source, User
from memgpt.metadata import MetadataStore
+from memgpt.persistence_manager import LocalStateManager
from memgpt.utils import (
MEMGPT_DIR,
- get_utc_time,
- version_less_than,
OpenAIBackcompatUnpickler,
annotate_message_json_list_with_tool_calls,
+ get_utc_time,
parse_formatted_time,
+ version_less_than,
)
-from memgpt.config import MemGPTConfig
-from memgpt.cli.cli_config import configure
-from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.persistence_manager import PersistenceManager, LocalStateManager
# This is the version where the breaking change was made
VERSION_CUTOFF = "0.2.12"
@@ -132,7 +131,6 @@ def migrate_source(source_name: str, data_dir: str = MEMGPT_DIR, ms: Optional[Me
assert os.path.exists(source_path), f"Source {source_name} does not exist at {source_path}"
# load state from old checkpoint file
- from memgpt.cli.cli_load import load_index
# 2. Create a new AgentState using the agent config + agent internal state
config = MemGPTConfig.load()
diff --git a/memgpt/models/chat_completion_request.py b/memgpt/models/chat_completion_request.py
index 3a6c7febe..f01684f43 100644
--- a/memgpt/models/chat_completion_request.py
+++ b/memgpt/models/chat_completion_request.py
@@ -1,5 +1,6 @@
-from typing import List, Union, Optional, Dict, Literal, Any
-from pydantic import BaseModel, Field, Json
+from typing import Any, Dict, List, Literal, Optional, Union
+
+from pydantic import BaseModel, Field
class SystemMessage(BaseModel):
diff --git a/memgpt/models/chat_completion_response.py b/memgpt/models/chat_completion_response.py
index 983fd629b..e6e3efa64 100644
--- a/memgpt/models/chat_completion_response.py
+++ b/memgpt/models/chat_completion_response.py
@@ -1,7 +1,7 @@
-from typing import List, Optional, Union, Dict, Literal
-from pydantic import BaseModel, Field
import datetime
+from typing import Dict, List, Literal, Optional, Union
+from pydantic import BaseModel
# class ToolCallFunction(BaseModel):
# name: str
diff --git a/memgpt/models/embedding_response.py b/memgpt/models/embedding_response.py
index fb4664872..9858ba0ec 100644
--- a/memgpt/models/embedding_response.py
+++ b/memgpt/models/embedding_response.py
@@ -1,4 +1,5 @@
from typing import List, Literal
+
from pydantic import BaseModel
diff --git a/memgpt/models/openai.py b/memgpt/models/openai.py
index 5d41c0915..d0646ad8e 100644
--- a/memgpt/models/openai.py
+++ b/memgpt/models/openai.py
@@ -1,6 +1,7 @@
-from typing import List, Union, Optional, Dict
from enum import Enum
-from pydantic import BaseModel, Field, Json
+from typing import Dict, List, Optional, Union
+
+from pydantic import BaseModel, Field
class ImageFile(BaseModel):
diff --git a/memgpt/models/pydantic_models.py b/memgpt/models/pydantic_models.py
index 35635a304..05592404b 100644
--- a/memgpt/models/pydantic_models.py
+++ b/memgpt/models/pydantic_models.py
@@ -1,18 +1,15 @@
-from typing import List, Optional, Dict, Literal, Type
-from pydantic import BaseModel, Field, Json, ConfigDict
-
-from enum import Enum
-
import uuid
-import base64
-import numpy as np
from datetime import datetime
-from sqlmodel import Field, SQLModel
+from enum import Enum
+from typing import Dict, List, Optional
+
+from pydantic import BaseModel, ConfigDict, Field
+from sqlalchemy import JSON, Column
from sqlalchemy_utils import ChoiceType
-from sqlalchemy import JSON, Column, BINARY, TypeDecorator, String
+from sqlmodel import Field, SQLModel
-from memgpt.constants import DEFAULT_HUMAN, DEFAULT_MEMGPT_MODEL, DEFAULT_PERSONA, DEFAULT_PRESET, LLM_MAX_TOKENS, MAX_EMBEDDING_DIM
-from memgpt.utils import get_human_text, get_persona_text, printd, get_utc_time
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
+from memgpt.utils import get_human_text, get_persona_text, get_utc_time
class LLMConfigModel(BaseModel):
diff --git a/memgpt/openai_backcompat/openai_object.py b/memgpt/openai_backcompat/openai_object.py
index fcc638360..ec157db58 100644
--- a/memgpt/openai_backcompat/openai_object.py
+++ b/memgpt/openai_backcompat/openai_object.py
@@ -2,13 +2,13 @@
import json
from copy import deepcopy
+from enum import Enum
from typing import Optional, Tuple, Union
-from enum import Enum
+from memgpt.constants import JSON_ENSURE_ASCII
# import openai
-from memgpt.constants import JSON_ENSURE_ASCII
# from openai import api_requestor, util
# from openai.openai_response import OpenAIResponse
diff --git a/memgpt/persistence_manager.py b/memgpt/persistence_manager.py
index acee437bd..bbead880c 100644
--- a/memgpt/persistence_manager.py
+++ b/memgpt/persistence_manager.py
@@ -1,14 +1,10 @@
from abc import ABC, abstractmethod
+from datetime import datetime
from typing import List
-from memgpt.memory import (
- BaseRecallMemory,
- EmbeddingArchivalMemory,
-)
+from memgpt.data_types import AgentState, Message
+from memgpt.memory import BaseRecallMemory, EmbeddingArchivalMemory
from memgpt.utils import printd
-from memgpt.data_types import Message, ToolCall, AgentState
-
-from datetime import datetime
def parse_formatted_time(formatted_time: str):
diff --git a/memgpt/presets/presets.py b/memgpt/presets/presets.py
index 6250e6304..ca19ced36 100644
--- a/memgpt/presets/presets.py
+++ b/memgpt/presets/presets.py
@@ -1,17 +1,16 @@
-from typing import List
import os
+import uuid
+from typing import List
+
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
from memgpt.data_types import AgentState, Preset
-from memgpt.interface import AgentInterface
-from memgpt.presets.utils import load_all_presets, is_valid_yaml_format, load_yaml_file
-from memgpt.utils import get_human_text, get_persona_text, printd, list_human_files, list_persona_files
-from memgpt.prompts import gpt_system
from memgpt.functions.functions import load_all_function_sets
+from memgpt.interface import AgentInterface
from memgpt.metadata import MetadataStore
-from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
from memgpt.models.pydantic_models import HumanModel, PersonaModel
-
-import uuid
-
+from memgpt.presets.utils import load_all_presets, load_yaml_file
+from memgpt.prompts import gpt_system
+from memgpt.utils import get_human_text, get_persona_text, list_human_files, list_persona_files, printd
available_presets = load_all_presets()
preset_options = list(available_presets.keys())
@@ -142,12 +141,10 @@ def create_agent_from_preset(
# available_presets = load_all_presets()
# if preset_name not in available_presets:
# raise ValueError(f"Preset '{preset_name}.yaml' not found")
-
# preset = available_presets[preset_name]
# preset_system_prompt = preset["system_prompt"]
# preset_function_set_names = preset["functions"]
# preset_function_set_schemas = generate_functions_json(preset_function_set_names)
-
# Override the following in the AgentState:
# persona: str # the current persona text
# human: str # the current human text
diff --git a/memgpt/presets/utils.py b/memgpt/presets/utils.py
index 68d246d2e..3b436ab87 100644
--- a/memgpt/presets/utils.py
+++ b/memgpt/presets/utils.py
@@ -1,5 +1,6 @@
-import os
import glob
+import os
+
import yaml
from memgpt.constants import MEMGPT_DIR
diff --git a/memgpt/server/rest_api/agents/command.py b/memgpt/server/rest_api/agents/command.py
index e522653a0..04b122bba 100644
--- a/memgpt/server/rest_api/agents/command.py
+++ b/memgpt/server/rest_api/agents/command.py
@@ -1,7 +1,7 @@
import uuid
from functools import partial
-from fastapi import APIRouter, Body, HTTPException, Depends
+from fastapi import APIRouter, Body, Depends, HTTPException
from pydantic import BaseModel, Field
from memgpt.server.rest_api.auth_token import get_current_user
diff --git a/memgpt/server/rest_api/agents/config.py b/memgpt/server/rest_api/agents/config.py
index d0f24fbff..3f3beb105 100644
--- a/memgpt/server/rest_api/agents/config.py
+++ b/memgpt/server/rest_api/agents/config.py
@@ -1,13 +1,13 @@
import re
import uuid
from functools import partial
+from typing import List, Optional
-from fastapi import APIRouter, Body, Depends, Query, HTTPException, status
+from fastapi import APIRouter, Body, Depends, HTTPException, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
-from typing import List, Optional
-from memgpt.models.pydantic_models import AgentStateModel, LLMConfigModel, EmbeddingConfigModel
+from memgpt.models.pydantic_models import AgentStateModel, EmbeddingConfigModel, LLMConfigModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
diff --git a/memgpt/server/rest_api/agents/index.py b/memgpt/server/rest_api/agents/index.py
index 1a86b1a30..7b54bc228 100644
--- a/memgpt/server/rest_api/agents/index.py
+++ b/memgpt/server/rest_api/agents/index.py
@@ -2,14 +2,13 @@ import uuid
from functools import partial
from typing import List
-from fastapi import APIRouter, Depends, Body, HTTPException
+from fastapi import APIRouter, Body, Depends, HTTPException
from pydantic import BaseModel, Field
+from memgpt.models.pydantic_models import AgentStateModel, EmbeddingConfigModel, LLMConfigModel, PresetModel
+from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
-from memgpt.server.rest_api.auth_token import get_current_user
-from memgpt.data_types import AgentState
-from memgpt.models.pydantic_models import LLMConfigModel, EmbeddingConfigModel, AgentStateModel, PresetModel
router = APIRouter()
diff --git a/memgpt/server/rest_api/agents/memory.py b/memgpt/server/rest_api/agents/memory.py
index 2447ab04e..b6e8f1ab8 100644
--- a/memgpt/server/rest_api/agents/memory.py
+++ b/memgpt/server/rest_api/agents/memory.py
@@ -2,7 +2,7 @@ import uuid
from functools import partial
from typing import List, Optional
-from fastapi import APIRouter, Depends, Body, HTTPException, status, Query
+from fastapi import APIRouter, Body, Depends, HTTPException, Query, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
diff --git a/memgpt/server/rest_api/agents/message.py b/memgpt/server/rest_api/agents/message.py
index 3ea0d2f30..07ab789c4 100644
--- a/memgpt/server/rest_api/agents/message.py
+++ b/memgpt/server/rest_api/agents/message.py
@@ -1,21 +1,20 @@
import asyncio
import json
import uuid
-from datetime import datetime, timezone
from asyncio import AbstractEventLoop
+from datetime import datetime
from enum import Enum
from functools import partial
-from typing import List, Optional, Any
+from typing import List, Optional
-from fastapi import APIRouter, Body, HTTPException, Query, Depends
-from pydantic import BaseModel, Field, validator
+from fastapi import APIRouter, Body, Depends, HTTPException, Query
+from pydantic import BaseModel, Field
from starlette.responses import StreamingResponse
from memgpt.constants import JSON_ENSURE_ASCII
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
-from memgpt.data_types import Message
router = APIRouter()
diff --git a/memgpt/server/rest_api/auth_token.py b/memgpt/server/rest_api/auth_token.py
index 7b3008497..39191313c 100644
--- a/memgpt/server/rest_api/auth_token.py
+++ b/memgpt/server/rest_api/auth_token.py
@@ -1,7 +1,7 @@
import uuid
from fastapi import Depends, HTTPException
-from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
+from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from memgpt.server.server import SyncServer
diff --git a/memgpt/server/rest_api/humans/index.py b/memgpt/server/rest_api/humans/index.py
index 80af6b4c4..ea5f3ad1f 100644
--- a/memgpt/server/rest_api/humans/index.py
+++ b/memgpt/server/rest_api/humans/index.py
@@ -2,7 +2,7 @@ import uuid
from functools import partial
from typing import List
-from fastapi import APIRouter, Depends, Body
+from fastapi import APIRouter, Body, Depends
from pydantic import BaseModel, Field
from memgpt.models.pydantic_models import HumanModel
diff --git a/memgpt/server/rest_api/interface.py b/memgpt/server/rest_api/interface.py
index 440decdf2..9edf4a101 100644
--- a/memgpt/server/rest_api/interface.py
+++ b/memgpt/server/rest_api/interface.py
@@ -1,12 +1,9 @@
import asyncio
import queue
-from datetime import datetime
from typing import Optional
-import pytz
-
-from memgpt.interface import AgentInterface
from memgpt.data_types import Message
+from memgpt.interface import AgentInterface
from memgpt.utils import is_utc_datetime
diff --git a/memgpt/server/rest_api/models/index.py b/memgpt/server/rest_api/models/index.py
index ad4a23a0d..abc016e82 100644
--- a/memgpt/server/rest_api/models/index.py
+++ b/memgpt/server/rest_api/models/index.py
@@ -1,15 +1,14 @@
from functools import partial
from typing import List
-from fastapi import APIRouter, Depends
+from fastapi import APIRouter
from pydantic import BaseModel, Field
+from memgpt.models.pydantic_models import LLMConfigModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
-from memgpt.models.pydantic_models import LLMConfigModel, EmbeddingConfigModel
-
router = APIRouter()
diff --git a/memgpt/server/rest_api/openai_assistants/assistants.py b/memgpt/server/rest_api/openai_assistants/assistants.py
index e7138f692..16d11d264 100644
--- a/memgpt/server/rest_api/openai_assistants/assistants.py
+++ b/memgpt/server/rest_api/openai_assistants/assistants.py
@@ -1,37 +1,27 @@
-from fastapi import FastAPI
import uuid
from typing import List, Optional
-from datetime import datetime
-from fastapi import APIRouter, Depends, Body, HTTPException, Query, Path
-from pydantic import BaseModel, Field, constr, validator
-from starlette.responses import StreamingResponse
-
-from memgpt.server.rest_api.interface import QueuingInterface
-from memgpt.server.server import SyncServer
+from fastapi import APIRouter, Body, HTTPException, Path, Query
+from pydantic import BaseModel, Field
from memgpt.config import MemGPTConfig
-import uuid
-
-from memgpt.server.server import SyncServer
-from memgpt.server.rest_api.interface import QueuingInterface
-from memgpt.server.rest_api.static_files import mount_static_files
+from memgpt.constants import DEFAULT_PRESET
+from memgpt.data_types import Message
from memgpt.models.openai import (
AssistantFile,
MessageFile,
+ MessageRoleType,
OpenAIAssistant,
- OpenAIThread,
OpenAIMessage,
OpenAIRun,
OpenAIRunStep,
- MessageRoleType,
+ OpenAIThread,
Text,
- ImageFile,
ToolCall,
ToolCallOutput,
)
-from memgpt.data_types import LLMConfig, EmbeddingConfig, Message
-from memgpt.constants import DEFAULT_PRESET
+from memgpt.server.rest_api.interface import QueuingInterface
+from memgpt.server.server import SyncServer
from memgpt.utils import get_utc_time
router = APIRouter()
diff --git a/memgpt/server/rest_api/personas/index.py b/memgpt/server/rest_api/personas/index.py
index 76cb11820..ea46ee9ea 100644
--- a/memgpt/server/rest_api/personas/index.py
+++ b/memgpt/server/rest_api/personas/index.py
@@ -2,7 +2,7 @@ import uuid
from functools import partial
from typing import List
-from fastapi import APIRouter, Depends, Body
+from fastapi import APIRouter, Body, Depends
from pydantic import BaseModel, Field
from memgpt.models.pydantic_models import PersonaModel
diff --git a/memgpt/server/rest_api/presets/index.py b/memgpt/server/rest_api/presets/index.py
index 3a573003f..22f935c80 100644
--- a/memgpt/server/rest_api/presets/index.py
+++ b/memgpt/server/rest_api/presets/index.py
@@ -1,17 +1,17 @@
import uuid
from functools import partial
-from typing import List, Optional, Dict, Union
+from typing import Dict, List, Optional, Union
-from fastapi import APIRouter, Body, Depends, Query, HTTPException, status
+from fastapi import APIRouter, Body, Depends, HTTPException, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
from memgpt.data_types import Preset # TODO remove
from memgpt.models.pydantic_models import PresetModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
-from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
from memgpt.utils import get_human_text, get_persona_text
router = APIRouter()
diff --git a/memgpt/server/rest_api/server.py b/memgpt/server/rest_api/server.py
index 21a5c3c8c..fcc46c15c 100644
--- a/memgpt/server/rest_api/server.py
+++ b/memgpt/server/rest_api/server.py
@@ -1,15 +1,17 @@
import json
-import uvicorn
-from typing import Optional
import logging
import os
import secrets
+import subprocess
+from typing import Optional
-from fastapi import FastAPI, HTTPException, Depends
-from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
+import uvicorn
+from fastapi import Depends, FastAPI, HTTPException
+from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from starlette.middleware.cors import CORSMiddleware
-from memgpt.settings import settings
+from memgpt.config import MemGPTConfig
+from memgpt.server.constants import REST_DEFAULT_PORT
from memgpt.server.rest_api.admin.users import setup_admin_router
from memgpt.server.rest_api.agents.command import setup_agents_command_router
from memgpt.server.rest_api.agents.config import setup_agents_config_router
@@ -23,14 +25,12 @@ from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.rest_api.models.index import setup_models_index_router
from memgpt.server.rest_api.openai_assistants.assistants import setup_openai_assistant_router
from memgpt.server.rest_api.personas.index import setup_personas_index_router
+from memgpt.server.rest_api.presets.index import setup_presets_index_router
+from memgpt.server.rest_api.sources.index import setup_sources_index_router
from memgpt.server.rest_api.static_files import mount_static_files
from memgpt.server.rest_api.tools.index import setup_tools_index_router
-from memgpt.server.rest_api.sources.index import setup_sources_index_router
-from memgpt.server.rest_api.presets.index import setup_presets_index_router
from memgpt.server.server import SyncServer
-from memgpt.config import MemGPTConfig
-from memgpt.server.constants import REST_DEFAULT_PORT
-import subprocess
+from memgpt.settings import settings
"""
Basic REST API sitting on top of the internal MemGPT python server (SyncServer)
diff --git a/memgpt/server/rest_api/sources/index.py b/memgpt/server/rest_api/sources/index.py
index 76eda1310..10e0f05d2 100644
--- a/memgpt/server/rest_api/sources/index.py
+++ b/memgpt/server/rest_api/sources/index.py
@@ -1,21 +1,19 @@
-import uuid
-import tempfile
import os
-import hashlib
+import tempfile
+import uuid
from functools import partial
from typing import List, Optional
-from fastapi import APIRouter, Body, Depends, Query, HTTPException, status, UploadFile, BackgroundTasks
+from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException, Query, UploadFile, status
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
-from starlette.responses import StreamingResponse
-from memgpt.models.pydantic_models import SourceModel, PassageModel, DocumentModel, JobModel, JobStatus
+from memgpt.data_sources.connectors import DirectoryConnector
+from memgpt.data_types import Source
+from memgpt.models.pydantic_models import DocumentModel, JobModel, JobStatus, PassageModel, SourceModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
-from memgpt.data_types import Source
-from memgpt.data_sources.connectors import DirectoryConnector
router = APIRouter()
diff --git a/memgpt/server/rest_api/static_files.py b/memgpt/server/rest_api/static_files.py
index 4d836cdaf..f1e653bb1 100644
--- a/memgpt/server/rest_api/static_files.py
+++ b/memgpt/server/rest_api/static_files.py
@@ -1,7 +1,7 @@
import os
+from fastapi import FastAPI, HTTPException
from starlette.exceptions import HTTPException as StarletteHTTPException
-from fastapi import HTTPException, FastAPI
from starlette.staticfiles import StaticFiles
diff --git a/memgpt/server/rest_api/tools/index.py b/memgpt/server/rest_api/tools/index.py
index 1ce2e73c7..6b5a0672b 100644
--- a/memgpt/server/rest_api/tools/index.py
+++ b/memgpt/server/rest_api/tools/index.py
@@ -1,8 +1,8 @@
import uuid
from functools import partial
-from typing import List, Optional, Literal
+from typing import List, Literal, Optional
-from fastapi import APIRouter, Depends, Body
+from fastapi import APIRouter, Body, Depends
from pydantic import BaseModel, Field
from memgpt.models.pydantic_models import ToolModel
diff --git a/memgpt/server/server.py b/memgpt/server/server.py
index bf38d6880..443b48967 100644
--- a/memgpt/server/server.py
+++ b/memgpt/server/server.py
@@ -1,16 +1,14 @@
import json
-import subprocess
import logging
import uuid
+import warnings
from abc import abstractmethod
from datetime import datetime
from functools import wraps
from threading import Lock
-from typing import Union, Callable, Optional, List, Tuple
-import warnings
+from typing import Callable, List, Optional, Tuple, Union
from fastapi import HTTPException
-import uvicorn
import memgpt.constants as constants
import memgpt.presets.presets as presets
@@ -18,31 +16,21 @@ import memgpt.server.utils as server_utils
import memgpt.system as system
from memgpt.agent import Agent, save_agent
from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.utils import get_human_text, get_persona_text
# from memgpt.llm_api_tools import openai_get_model_list, azure_openai_get_model_list, smart_urljoin
from memgpt.cli.cli_config import get_model_options
from memgpt.config import MemGPTConfig
-from memgpt.constants import JSON_LOADS_STRICT, JSON_ENSURE_ASCII
+from memgpt.constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
from memgpt.credentials import MemGPTCredentials
from memgpt.data_sources.connectors import DataConnector, load_data
-from memgpt.data_types import (
- User,
- Source,
- AgentState,
- LLMConfig,
- EmbeddingConfig,
- Message,
- Token,
- Preset,
-)
-
-from memgpt.models.pydantic_models import SourceModel, PassageModel, DocumentModel, PresetModel, ToolModel
-from memgpt.interface import AgentInterface # abstract
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, Message, Preset, Source, Token, User
# TODO use custom interface
+from memgpt.interface import AgentInterface # abstract
from memgpt.interface import CLIInterface # for printing to terminal
from memgpt.metadata import MetadataStore
+from memgpt.models.pydantic_models import DocumentModel, PassageModel, PresetModel, SourceModel, ToolModel
+from memgpt.utils import get_human_text, get_persona_text
logger = logging.getLogger(__name__)
@@ -1413,8 +1401,6 @@ class SyncServer(LockingServer):
def create_tool(self, name: str, user_id: uuid.UUID) -> ToolModel: # TODO: add other fields
"""Create a new tool"""
- pass
def delete_tool(self, tool_id: uuid.UUID, user_id: uuid.UUID):
"""Delete a tool"""
- pass
diff --git a/memgpt/server/ws_api/example_client.py b/memgpt/server/ws_api/example_client.py
index 52e2ccb92..eb38cab84 100644
--- a/memgpt/server/ws_api/example_client.py
+++ b/memgpt/server/ws_api/example_client.py
@@ -5,10 +5,9 @@ import websockets
import memgpt.server.ws_api.protocol as protocol
from memgpt.constants import JSON_ENSURE_ASCII, JSON_LOADS_STRICT
-from memgpt.server.constants import WS_DEFAULT_PORT, WS_CLIENT_TIMEOUT
+from memgpt.server.constants import WS_CLIENT_TIMEOUT, WS_DEFAULT_PORT
from memgpt.server.utils import condition_to_stop_receiving, print_server_response
-
# CLEAN_RESPONSES = False # print the raw server responses (JSON)
CLEAN_RESPONSES = True # make the server responses cleaner
diff --git a/memgpt/server/ws_api/interface.py b/memgpt/server/ws_api/interface.py
index 12fa70885..873477e25 100644
--- a/memgpt/server/ws_api/interface.py
+++ b/memgpt/server/ws_api/interface.py
@@ -1,9 +1,8 @@
import asyncio
import threading
-
-from memgpt.interface import AgentInterface
import memgpt.server.ws_api.protocol as protocol
+from memgpt.interface import AgentInterface
class BaseWebSocketInterface(AgentInterface):
diff --git a/memgpt/server/ws_api/protocol.py b/memgpt/server/ws_api/protocol.py
index 70ad40954..fdeea3b90 100644
--- a/memgpt/server/ws_api/protocol.py
+++ b/memgpt/server/ws_api/protocol.py
@@ -2,7 +2,6 @@ import json
from memgpt.constants import JSON_ENSURE_ASCII
-
# Server -> client
diff --git a/memgpt/server/ws_api/server.py b/memgpt/server/ws_api/server.py
index 07fade11d..6ee9fcb8b 100644
--- a/memgpt/server/ws_api/server.py
+++ b/memgpt/server/ws_api/server.py
@@ -6,12 +6,10 @@ import traceback
import websockets
+import memgpt.server.ws_api.protocol as protocol
+from memgpt.server.constants import WS_DEFAULT_PORT
from memgpt.server.server import SyncServer
from memgpt.server.ws_api.interface import SyncWebSocketInterface
-from memgpt.server.constants import WS_DEFAULT_PORT
-import memgpt.server.ws_api.protocol as protocol
-import memgpt.system as system
-import memgpt.constants as memgpt_constants
class WebSocketServer:
diff --git a/memgpt/settings.py b/memgpt/settings.py
index 291eec3ee..d59f38db0 100644
--- a/memgpt/settings.py
+++ b/memgpt/settings.py
@@ -1,4 +1,5 @@
from typing import Optional
+
from pydantic_settings import BaseSettings, SettingsConfigDict
diff --git a/memgpt/streaming_interface.py b/memgpt/streaming_interface.py
index 928810da8..5815998c1 100644
--- a/memgpt/streaming_interface.py
+++ b/memgpt/streaming_interface.py
@@ -1,21 +1,15 @@
-from abc import ABC, abstractmethod
import json
-import re
-import sys
+from abc import ABC, abstractmethod
from typing import List, Optional
# from colorama import Fore, Style, init
from rich.console import Console
from rich.live import Live
from rich.markup import escape
-from rich.style import Style
-from rich.text import Text
-from memgpt.utils import printd
-from memgpt.constants import CLI_WARNING_PREFIX, JSON_LOADS_STRICT
from memgpt.data_types import Message
+from memgpt.interface import CLIInterface
from memgpt.models.chat_completion_response import ChatCompletionChunkResponse, ChatCompletionResponse
-from memgpt.interface import AgentInterface, CLIInterface
# init(autoreset=True)
diff --git a/memgpt/system.py b/memgpt/system.py
index bb7d0fd18..f6640198d 100644
--- a/memgpt/system.py
+++ b/memgpt/system.py
@@ -1,14 +1,14 @@
-import uuid
import json
+import uuid
-from .utils import get_local_time
from .constants import (
INITIAL_BOOT_MESSAGE,
- INITIAL_BOOT_MESSAGE_SEND_MESSAGE_THOUGHT,
INITIAL_BOOT_MESSAGE_SEND_MESSAGE_FIRST_MSG,
- MESSAGE_SUMMARY_WARNING_STR,
+ INITIAL_BOOT_MESSAGE_SEND_MESSAGE_THOUGHT,
JSON_ENSURE_ASCII,
+ MESSAGE_SUMMARY_WARNING_STR,
)
+from .utils import get_local_time
def get_initial_boot_messages(version="startup"):
diff --git a/memgpt/utils.py b/memgpt/utils.py
index 4ee947452..c7d842322 100644
--- a/memgpt/utils.py
+++ b/memgpt/utils.py
@@ -1,42 +1,39 @@
-from datetime import datetime, timezone, timedelta
import copy
-import re
+import difflib
+import hashlib
+import inspect
+import io
import json
import os
import pickle
import platform
import random
+import re
import subprocess
-import uuid
import sys
-import io
-import hashlib
-from typing import List
-import inspect
+import uuid
+from contextlib import contextmanager
+from datetime import datetime, timedelta, timezone
from functools import wraps
-from typing import get_type_hints, Union, _GenericAlias
-
+from typing import List, Union, _GenericAlias, get_type_hints
+from urllib.parse import urljoin, urlparse
-from urllib.parse import urlparse, urljoin
-from contextlib import contextmanager
-import difflib
import demjson3 as demjson
import pytz
import tiktoken
import memgpt
from memgpt.constants import (
- JSON_LOADS_STRICT,
- MEMGPT_DIR,
- FUNCTION_RETURN_CHAR_LIMIT,
CLI_WARNING_PREFIX,
CORE_MEMORY_HUMAN_CHAR_LIMIT,
CORE_MEMORY_PERSONA_CHAR_LIMIT,
+ FUNCTION_RETURN_CHAR_LIMIT,
JSON_ENSURE_ASCII,
+ JSON_LOADS_STRICT,
+ MEMGPT_DIR,
TOOL_CALL_ID_MAX_LEN,
)
from memgpt.models.chat_completion_response import ChatCompletionResponse
-
from memgpt.openai_backcompat.openai_object import OpenAIObject
# TODO: what is this?
diff --git a/paper_experiments/doc_qa_task/doc_qa.py b/paper_experiments/doc_qa_task/doc_qa.py
index 72e1055c1..c06cb1b74 100644
--- a/paper_experiments/doc_qa_task/doc_qa.py
+++ b/paper_experiments/doc_qa_task/doc_qa.py
@@ -16,30 +16,24 @@ from late 2018, following past work on NaturalQuestions-Open (Izacard & Grave, 2
et al., 2021) We randomly sample a subset of 50 questions for each point in the graph.
"""
-import json
import argparse
-import uuid
+import json
import os
-import openai
+import uuid
+from typing import List
+
+from icml_experiments.utils import get_experiment_config, load_gzipped_file
from openai import OpenAI
-from typing import List, Optional
from tqdm import tqdm
-from memgpt.embeddings import embedding_model
-from memgpt import MemGPT
-from memgpt.credentials import MemGPTCredentials
-from memgpt.data_types import Message, AgentState
-from memgpt.cli.cli import attach
+from memgpt import MemGPT, utils
from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.config import MemGPTConfig
-from memgpt.metadata import MetadataStore
from memgpt.cli.cli_config import delete
-from memgpt import utils
+from memgpt.config import MemGPTConfig
+from memgpt.credentials import MemGPTCredentials
+from memgpt.embeddings import embedding_model
from memgpt.utils import count_tokens
-from icml_experiments.utils import load_gzipped_file, get_experiment_config
-
-
DATA_SOURCE_NAME = "wikipedia"
DOC_QA_PERSONA = "You are MemGPT DOC-QA bot. Your job is to answer questions about documents that are stored in your archival memory. The answer to the users question will ALWAYS be in your archival memory, so remember to keep searching if you can't find the answer. Answer the questions as if though the year is 2018." # TODO decide on a good persona/human
DOC_QA_HUMAN = "The user will ask you questions about documents. Answer them to the best of your ability."
@@ -94,7 +88,7 @@ def generate_docqa_baseline_response(
archival_memory = StorageConnector.get_storage_connector(TableType.PASSAGES, config, user_id)
archival_memory.disable_write = True # prevent archival memory writes
archival_memory.filters = {"data_source": data_souce_name}
- archival_memory_size = archival_memory.size()
+ archival_memory.size()
print(f"Attaching archival memory with {archival_memory.size()} passages")
# grab the top N documents
@@ -203,7 +197,7 @@ def generate_docqa_response(
archival_memory = StorageConnector.get_storage_connector(TableType.PASSAGES, config, user_id)
archival_memory.disable_write = True # prevent archival memory writes
archival_memory.filters = {"data_source": data_souce_name}
- archival_memory_size = archival_memory.size()
+ archival_memory.size()
print(f"Attaching archival memory with {archival_memory.size()} passages")
# override the agent's archival memory with table containing wikipedia embeddings
@@ -283,7 +277,7 @@ def run_docqa_task(
# - a set of context documents one of which contains the answer (List[dict])
# - a gold annotation that has a title of the context doc, a long answer, and a list of short answers
question = data["question"]
- documents = data["ctxs"]
+ data["ctxs"]
answers = data["answers"]
# The only thing we actually use here is the 'question'
diff --git a/paper_experiments/doc_qa_task/llm_judge_doc_qa.py b/paper_experiments/doc_qa_task/llm_judge_doc_qa.py
index 95d1c3b77..fb6b8e8e3 100644
--- a/paper_experiments/doc_qa_task/llm_judge_doc_qa.py
+++ b/paper_experiments/doc_qa_task/llm_judge_doc_qa.py
@@ -1,9 +1,10 @@
import argparse
-import re
import json
-import openai
+import re
+
from openai import OpenAI
from tqdm import tqdm
+
from memgpt.credentials import MemGPTCredentials
# Note: did not end up using since no cases of cheating were observed
diff --git a/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py b/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py
index 430674c83..523321e3f 100644
--- a/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py
+++ b/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py
@@ -1,21 +1,18 @@
-import json
+import copy
import hashlib
+import json
import os
+import time
import uuid
-import copy
-from pprint import pprint
+from concurrent.futures import ThreadPoolExecutor, as_completed
+
+from absl import app, flags
+from icml_experiments.utils import get_experiment_config
from tqdm import tqdm
-from memgpt.cli.cli_load import insert_passages_into_source
+
+from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.cli.cli_config import delete
from memgpt.data_types import Passage
-from memgpt.config import MemGPTConfig
-from memgpt.agent_store.storage import StorageConnector, TableType
-
-from icml_experiments.utils import get_experiment_config
-from multiprocessing import Pool
-from concurrent.futures import ThreadPoolExecutor, as_completed
-from absl import app, flags
-import time
# Create an empty list to store the JSON objects
source_name = "wikipedia"
@@ -52,7 +49,7 @@ def insert_lines(lines, conn, show_progress=False):
embedding_dim = len(embedding)
assert embedding_dim == 1536, f"Wrong embedding dim: {len(embedding_dim)}"
assert len(d[1]["data"]) == 1, f"More than one embedding: {len(d[1]['data'])}"
- metadata = d[1]["usage"]
+ d[1]["usage"]
# print(text)
passage_id = create_uuid_from_string(text) # consistent hash for text (prevent duplicates)
@@ -148,7 +145,7 @@ def main(argv):
print(f"Waiting for {len(futures)} futures")
# wait for futures
for future in tqdm(as_completed(futures)):
- succ = future.result()
+ future.result()
# check metadata
# storage = StorageConnector.get_storage_connector(TableType.PASSAGES, config, user_id)
diff --git a/paper_experiments/nested_kv_task/nested_kv.py b/paper_experiments/nested_kv_task/nested_kv.py
index 5aa8c90b8..34d9ef8cc 100644
--- a/paper_experiments/nested_kv_task/nested_kv.py
+++ b/paper_experiments/nested_kv_task/nested_kv.py
@@ -19,30 +19,22 @@ sample 30 different ordering configurations including both
the initial key position and nesting key positions.
"""
-import math
-import json
import argparse
-import uuid
+import json
+import math
import os
-from typing import List
-from tqdm import tqdm
+import uuid
from collections import OrderedDict
-from openai import OpenAI
-import openai
-from memgpt import MemGPT
-from memgpt.data_types import Message, AgentState, Passage
-from memgpt.cli.cli import attach
-from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.config import MemGPTConfig
-from memgpt.metadata import MetadataStore
-from memgpt.cli.cli_config import delete
-from memgpt import utils
-from memgpt.constants import MAX_PAUSE_HEARTBEATS, RETRIEVAL_QUERY_DEFAULT_PAGE_SIZE, JSON_ENSURE_ASCII
-
from typing import Optional
-from icml_experiments.utils import load_gzipped_file, get_experiment_config
+import openai
+from icml_experiments.utils import get_experiment_config, load_gzipped_file
+from tqdm import tqdm
+from memgpt import MemGPT, utils
+from memgpt.cli.cli_config import delete
+from memgpt.config import MemGPTConfig
+from memgpt.constants import JSON_ENSURE_ASCII
# TODO: update personas
NESTED_PERSONA = "You are MemGPT DOC-QA bot. Your job is to answer questions about documents that are stored in your archival memory. The answer to the users question will ALWAYS be in your archival memory, so remember to keep searching if you can't find the answer. DO NOT STOP SEARCHING UNTIL YOU VERIFY THAT THE VALUE IS NOT A KEY. Do not stop making nested lookups until this condition is met." # TODO decide on a good persona/human
diff --git a/paper_experiments/utils.py b/paper_experiments/utils.py
index 1c065cf93..cb461e362 100644
--- a/paper_experiments/utils.py
+++ b/paper_experiments/utils.py
@@ -1,9 +1,10 @@
import gzip
import json
from typing import List
+
from memgpt.config import MemGPTConfig
-from memgpt.data_types import LLMConfig, EmbeddingConfig
from memgpt.constants import LLM_MAX_TOKENS
+from memgpt.data_types import EmbeddingConfig, LLMConfig
def load_gzipped_file(file_path):
diff --git a/tests/__init__.py b/tests/__init__.py
index 9dfe7151f..6f06078cf 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,4 +1,3 @@
from tests.config import TestMGPTConfig
-
TEST_MEMGPT_CONFIG = TestMGPTConfig()
diff --git a/tests/clear_postgres_db.py b/tests/clear_postgres_db.py
index 7d10afe32..7c07f98f1 100644
--- a/tests/clear_postgres_db.py
+++ b/tests/clear_postgres_db.py
@@ -1,6 +1,6 @@
import os
-from sqlalchemy import create_engine, MetaData
+from sqlalchemy import MetaData, create_engine
def main():
diff --git a/tests/config.py b/tests/config.py
index 5843ebf80..80f922310 100644
--- a/tests/config.py
+++ b/tests/config.py
@@ -1,4 +1,5 @@
import os
+
from memgpt.config import MemGPTConfig
from memgpt.constants import MEMGPT_DIR
diff --git a/tests/data/functions/dump_json.py b/tests/data/functions/dump_json.py
index 7cca80b0b..b6cd21eea 100644
--- a/tests/data/functions/dump_json.py
+++ b/tests/data/functions/dump_json.py
@@ -1,4 +1,5 @@
import json
+
from memgpt.agent import Agent
diff --git a/tests/test_admin_client.py b/tests/test_admin_client.py
index dcaaf471e..1185f1452 100644
--- a/tests/test_admin_client.py
+++ b/tests/test_admin_client.py
@@ -1,24 +1,17 @@
-import uuid
import os
-import time
import threading
-from dotenv import load_dotenv
+import time
+import uuid
-from memgpt import Admin, create_client
-from memgpt.constants import DEFAULT_PRESET
+import pytest
from dotenv import load_dotenv
-from tests.config import TestMGPTConfig
-
-from memgpt.settings import settings
-from memgpt.server.rest_api.server import start_server
+from memgpt import Admin
from memgpt.credentials import MemGPTCredentials
from memgpt.data_types import EmbeddingConfig, LLMConfig
-from .utils import wipe_config, wipe_memgpt_home
-
-
-import pytest
-import uuid
+from memgpt.server.rest_api.server import start_server
+from memgpt.settings import settings
+from tests.config import TestMGPTConfig
test_base_url = "http://localhost:8283"
@@ -27,8 +20,7 @@ test_server_token = "test_server_token"
def run_server():
- import uvicorn
- from memgpt.server.rest_api.server import app
+ pass
load_dotenv()
diff --git a/tests/test_agent_function_update.py b/tests/test_agent_function_update.py
index d945abca0..a4bf1cd48 100644
--- a/tests/test_agent_function_update.py
+++ b/tests/test_agent_function_update.py
@@ -1,18 +1,16 @@
+import inspect
import json
import os
-import inspect
import uuid
-from memgpt import create_client
-from memgpt import constants
+import pytest
+
+from memgpt import constants, create_client
from memgpt.functions.functions import USER_FUNCTIONS_DIR
-from memgpt.utils import assistant_function_to_tool
from memgpt.models import chat_completion_response
+from memgpt.utils import assistant_function_to_tool
from tests import TEST_MEMGPT_CONFIG
-
-from tests.utils import wipe_config, create_config
-
-import pytest
+from tests.utils import create_config, wipe_config
def hello_world(self) -> str:
diff --git a/tests/test_autogen_integration.py b/tests/test_autogen_integration.py
index 1c1b37cdd..e2cdeec33 100644
--- a/tests/test_autogen_integration.py
+++ b/tests/test_autogen_integration.py
@@ -1,5 +1,6 @@
import os
import subprocess
+
import pytest
diff --git a/tests/test_base_functions.py b/tests/test_base_functions.py
index accf9edec..b7c527272 100644
--- a/tests/test_base_functions.py
+++ b/tests/test_base_functions.py
@@ -1,13 +1,13 @@
import os
-import pytest
import uuid
-from memgpt import create_client
-from memgpt import constants
+import pytest
+
import memgpt.functions.function_sets.base as base_functions
+from memgpt import constants, create_client
from tests import TEST_MEMGPT_CONFIG
-from .utils import wipe_config, create_config
+from .utils import create_config, wipe_config
# test_agent_id = "test_agent"
client = None
diff --git a/tests/test_cli.py b/tests/test_cli.py
index e11c17ea3..f15ab7fc9 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,14 +1,12 @@
-import subprocess
import os
+import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "pexpect"])
import pexpect
from .constants import TIMEOUT
-from .utils import create_config, wipe_config
-from memgpt import create_client
-
+from .utils import create_config
# def test_configure_memgpt():
# configure_memgpt()
diff --git a/tests/test_client.py b/tests/test_client.py
index 87192d34b..d50351542 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -1,24 +1,18 @@
-import uuid
import os
-import time
import threading
+import time
+import uuid
+
+import pytest
from dotenv import load_dotenv
from memgpt import Admin, create_client
from memgpt.constants import DEFAULT_PRESET
-from memgpt.data_types import Preset # TODO move to PresetModel
-from dotenv import load_dotenv
-
-from tests.config import TestMGPTConfig
-
-from memgpt.settings import settings
from memgpt.credentials import MemGPTCredentials
+from memgpt.data_types import Preset # TODO move to PresetModel
from memgpt.data_types import EmbeddingConfig, LLMConfig
-from .utils import wipe_config, wipe_memgpt_home
-
-
-import pytest
-import uuid
+from memgpt.settings import settings
+from tests.config import TestMGPTConfig
test_agent_name = f"test_client_{str(uuid.uuid4())}"
# test_preset_name = "test_preset"
@@ -37,7 +31,7 @@ test_server_token = "test_server_token"
def run_server():
- import uvicorn
+ pass
load_dotenv()
@@ -96,7 +90,6 @@ def run_server():
config.save()
credentials.save()
- from memgpt.server.rest_api.server import app
from memgpt.server.rest_api.server import start_server
print("Starting server...", config.config_path)
@@ -125,7 +118,7 @@ def client(request):
admin = Admin(request.param["base_url"], test_server_token)
response = admin.create_user(test_user_id) # Adjust as per your client's method
- user_id = response.user_id
+ response.user_id
token = response.api_key
else:
token = None
diff --git a/tests/test_different_embedding_size.py b/tests/test_different_embedding_size.py
index 0fdde27d3..25be0b2d0 100644
--- a/tests/test_different_embedding_size.py
+++ b/tests/test_different_embedding_size.py
@@ -1,14 +1,13 @@
-import uuid
import os
+import uuid
from memgpt import create_client
-from memgpt.data_types import EmbeddingConfig, Passage
-from memgpt.embeddings import embedding_model
from memgpt.agent_store.storage import StorageConnector, TableType
+from memgpt.data_types import Passage
+from memgpt.embeddings import embedding_model
from tests import TEST_MEMGPT_CONFIG
-from .utils import wipe_config, create_config
-import uuid
+from .utils import create_config, wipe_config
test_agent_name = f"test_client_{str(uuid.uuid4())}"
test_agent_state = None
diff --git a/tests/test_function_parser.py b/tests/test_function_parser.py
index a720715f3..146b29ad7 100644
--- a/tests/test_function_parser.py
+++ b/tests/test_function_parser.py
@@ -1,9 +1,8 @@
import json
+import memgpt.system as system
from memgpt.constants import JSON_ENSURE_ASCII
from memgpt.local_llm.function_parser import patch_function
-import memgpt.system as system
-
EXAMPLE_FUNCTION_CALL_SEND_MESSAGE = {
"message_history": [
diff --git a/tests/test_json_parsers.py b/tests/test_json_parsers.py
index 3ada8e342..35ee19aa1 100644
--- a/tests/test_json_parsers.py
+++ b/tests/test_json_parsers.py
@@ -1,8 +1,7 @@
import json
-from memgpt.constants import JSON_LOADS_STRICT
import memgpt.local_llm.json_parser as json_parser
-
+from memgpt.constants import JSON_LOADS_STRICT
EXAMPLE_ESCAPED_UNDERSCORES = """{
"function":"send\_message",
diff --git a/tests/test_load_archival.py b/tests/test_load_archival.py
index d7013a087..11e951c93 100644
--- a/tests/test_load_archival.py
+++ b/tests/test_load_archival.py
@@ -1,22 +1,22 @@
import os
import uuid
+
import pytest
from sqlalchemy.ext.declarative import declarative_base
-
-# import memgpt
-from memgpt.settings import settings
from memgpt.agent_store.storage import StorageConnector, TableType
from memgpt.cli.cli_load import load_directory
+from memgpt.credentials import MemGPTCredentials
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, User
+from memgpt.metadata import MetadataStore
# from memgpt.data_sources.connectors import DirectoryConnector, load_data
+# import memgpt
from memgpt.settings import settings
-from memgpt.credentials import MemGPTCredentials
-from memgpt.metadata import MetadataStore
-from memgpt.data_types import User, AgentState, EmbeddingConfig, LLMConfig
from memgpt.utils import get_human_text, get_persona_text
from tests import TEST_MEMGPT_CONFIG
-from .utils import wipe_config, create_config
+
+from .utils import wipe_config
@pytest.fixture(autouse=True)
diff --git a/tests/test_log.py b/tests/test_log.py
index 5beb45305..6f9e2158d 100644
--- a/tests/test_log.py
+++ b/tests/test_log.py
@@ -1,7 +1,7 @@
import logging
-from memgpt.log import logger
+
from memgpt.constants import LOGGER_LOG_LEVELS
-import pytest
+from memgpt.log import logger
def test_log_debug():
diff --git a/tests/test_metadata_store.py b/tests/test_metadata_store.py
index 5fc63bc8d..3ccf6c914 100644
--- a/tests/test_metadata_store.py
+++ b/tests/test_metadata_store.py
@@ -1,16 +1,14 @@
-import os
-from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
import pytest
-from memgpt.settings import settings
from memgpt.agent import Agent, save_agent
+from memgpt.constants import DEFAULT_HUMAN, DEFAULT_PERSONA, DEFAULT_PRESET
+from memgpt.data_types import AgentState, LLMConfig, Source, User
from memgpt.metadata import MetadataStore
-from memgpt.data_types import User, AgentState, Source, LLMConfig
+from memgpt.models.pydantic_models import HumanModel, PersonaModel
+from memgpt.presets.presets import add_default_presets
+from memgpt.settings import settings
from memgpt.utils import get_human_text, get_persona_text
from tests import TEST_MEMGPT_CONFIG
-from memgpt.presets.presets import add_default_presets, add_default_humans_and_personas
-from memgpt.models.pydantic_models import HumanModel, PersonaModel
-from memgpt.models.pydantic_models import HumanModel, PersonaModel
# @pytest.mark.parametrize("storage_connector", ["postgres", "sqlite"])
diff --git a/tests/test_migrate.py b/tests/test_migrate.py
index c2cc084d7..b7e6c042a 100644
--- a/tests/test_migrate.py
+++ b/tests/test_migrate.py
@@ -2,11 +2,10 @@ import os
import shutil
import uuid
-from memgpt.migrate import migrate_all_agents, migrate_all_sources
-from memgpt.config import MemGPTConfig
+from memgpt.migrate import migrate_all_agents
from memgpt.server.server import SyncServer
-from .utils import wipe_config, create_config
+from .utils import create_config, wipe_config
def test_migrate_0211():
diff --git a/tests/test_openai_assistant_api.py b/tests/test_openai_assistant_api.py
index 8f15e358c..54d8c8485 100644
--- a/tests/test_openai_assistant_api.py
+++ b/tests/test_openai_assistant_api.py
@@ -1,10 +1,3 @@
-from fastapi import FastAPI
-from fastapi.testclient import TestClient
-
-from memgpt.server.server import SyncServer
-from memgpt.server.rest_api.server import app
-from memgpt.constants import DEFAULT_PRESET
-
# TODO: modify this to run against an actual running server
# def test_list_messages():
# client = TestClient(app)
diff --git a/tests/test_openai_client.py b/tests/test_openai_client.py
index 8654c9fea..b77295cdc 100644
--- a/tests/test_openai_client.py
+++ b/tests/test_openai_client.py
@@ -1,6 +1,7 @@
-from openai import OpenAI, APIConnectionError
from logging import getLogger
+from openai import APIConnectionError, OpenAI
+
logger = getLogger(__name__)
diff --git a/tests/test_schema_generator.py b/tests/test_schema_generator.py
index a68d241b5..ac9322b03 100644
--- a/tests/test_schema_generator.py
+++ b/tests/test_schema_generator.py
@@ -2,8 +2,8 @@ import inspect
import memgpt.functions.function_sets.base as base_functions
import memgpt.functions.function_sets.extras as extras_functions
-from memgpt.prompts.gpt_functions import FUNCTIONS_CHAINING
from memgpt.functions.schema_generator import generate_schema
+from memgpt.prompts.gpt_functions import FUNCTIONS_CHAINING
def send_message(self, message: str):
diff --git a/tests/test_server.py b/tests/test_server.py
index a505cfb02..ee73de346 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -1,17 +1,19 @@
+import os
import uuid
+
import pytest
-import os
-import memgpt.utils as utils
from dotenv import load_dotenv
+import memgpt.utils as utils
from tests.config import TestMGPTConfig
utils.DEBUG = True
-from memgpt.settings import settings
from memgpt.credentials import MemGPTCredentials
-from memgpt.server.server import SyncServer
from memgpt.data_types import EmbeddingConfig, LLMConfig
-from .utils import wipe_config, wipe_memgpt_home, DummyDataConnector
+from memgpt.server.server import SyncServer
+from memgpt.settings import settings
+
+from .utils import DummyDataConnector, wipe_config, wipe_memgpt_home
@pytest.fixture(scope="module")
diff --git a/tests/test_storage.py b/tests/test_storage.py
index ba6104892..4081ba34d 100644
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -1,24 +1,20 @@
import os
-from sqlalchemy.ext.declarative import declarative_base
import uuid
+from datetime import datetime, timedelta
+
import pytest
+from sqlalchemy.ext.declarative import declarative_base
-from memgpt.settings import settings
from memgpt.agent_store.storage import StorageConnector, TableType
-from memgpt.embeddings import embedding_model, query_embedding
-from memgpt.data_types import Message, Passage, EmbeddingConfig, AgentState, LLMConfig
+from memgpt.constants import MAX_EMBEDDING_DIM
from memgpt.credentials import MemGPTCredentials
-from memgpt.agent_store.storage import StorageConnector, TableType
+from memgpt.data_types import AgentState, EmbeddingConfig, LLMConfig, Message, Passage, User
+from memgpt.embeddings import embedding_model, query_embedding
from memgpt.metadata import MetadataStore
-from memgpt.data_types import User
-from memgpt.constants import MAX_EMBEDDING_DIM
+from memgpt.settings import settings
from memgpt.utils import get_human_text, get_persona_text
-
-from datetime import datetime, timedelta
-
from tests import TEST_MEMGPT_CONFIG
-
# Note: the database will filter out rows that do not correspond to agent1 and test_user by default.
texts = ["This is a test passage", "This is another test passage", "Cinderella wept"]
start_date = datetime(2009, 10, 5, 18, 00)
diff --git a/tests/test_summarize.py b/tests/test_summarize.py
index 2ed765053..c52b753f6 100644
--- a/tests/test_summarize.py
+++ b/tests/test_summarize.py
@@ -2,9 +2,8 @@ import os
import uuid
from memgpt import create_client
-from memgpt import constants
-from .utils import wipe_config, create_config
+from .utils import create_config, wipe_config
# test_agent_id = "test_agent"
test_agent_name = f"test_client_{str(uuid.uuid4())}"
diff --git a/tests/test_websocket_interface.py b/tests/test_websocket_interface.py
index 5d0671ef5..8b7ab7f0b 100644
--- a/tests/test_websocket_interface.py
+++ b/tests/test_websocket_interface.py
@@ -1,13 +1,13 @@
import os
-import pytest
from unittest.mock import AsyncMock
-from memgpt.credentials import MemGPTCredentials
-from memgpt.server.ws_api.interface import SyncWebSocketInterface
+import pytest
+
import memgpt.presets.presets as presets
import memgpt.system as system
+from memgpt.credentials import MemGPTCredentials
from memgpt.data_types import AgentState
-
+from memgpt.server.ws_api.interface import SyncWebSocketInterface
# def test_websockets():
# # Create the websocket interface
diff --git a/tests/test_websocket_server.py b/tests/test_websocket_server.py
index 7b25a03c2..4dfff052f 100644
--- a/tests/test_websocket_server.py
+++ b/tests/test_websocket_server.py
@@ -1,13 +1,12 @@
import asyncio
import json
-import websockets
import pytest
+import websockets
from memgpt.constants import JSON_ENSURE_ASCII
from memgpt.server.constants import WS_DEFAULT_PORT
from memgpt.server.ws_api.server import WebSocketServer
-from memgpt.config import AgentConfig
@pytest.mark.asyncio
diff --git a/tests/utils.py b/tests/utils.py
index 413f72b29..35b4b0851 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,8 +1,8 @@
import datetime
-from typing import Dict, List, Tuple, Iterator
import os
+from typing import Dict, Iterator, List, Tuple
-from memgpt.cli.cli import quickstart, QuickstartChoice
+from memgpt.cli.cli import QuickstartChoice, quickstart
from memgpt.data_sources.connectors import DataConnector
from memgpt.data_types import Document
from tests import TEST_MEMGPT_CONFIG