diff --git a/alembic/env.py b/alembic/env.py index e7dfe71c..767b7bbd 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,11 +1,12 @@ import os from logging.config import fileConfig +from sqlalchemy import engine_from_config, pool + from alembic import context from letta.config import LettaConfig from letta.orm import Base from letta.settings import settings -from sqlalchemy import engine_from_config, pool letta_config = LettaConfig.load() diff --git a/alembic/versions/08b2f8225812_adding_toolsagents_orm.py b/alembic/versions/08b2f8225812_adding_toolsagents_orm.py index d0e2cac8..0da80aae 100644 --- a/alembic/versions/08b2f8225812_adding_toolsagents_orm.py +++ b/alembic/versions/08b2f8225812_adding_toolsagents_orm.py @@ -9,6 +9,7 @@ Create Date: 2024-12-05 16:46:51.258831 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/1c8880d671ee_make_an_blocks_agents_mapping_table.py b/alembic/versions/1c8880d671ee_make_an_blocks_agents_mapping_table.py index 6890e0ed..ffcb0b67 100644 --- a/alembic/versions/1c8880d671ee_make_an_blocks_agents_mapping_table.py +++ b/alembic/versions/1c8880d671ee_make_an_blocks_agents_mapping_table.py @@ -9,6 +9,7 @@ Create Date: 2024-11-22 15:42:47.209229 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/3c683a662c82_migrate_jobs_to_the_orm.py b/alembic/versions/3c683a662c82_migrate_jobs_to_the_orm.py index 62b97e9d..4f9b746d 100644 --- a/alembic/versions/3c683a662c82_migrate_jobs_to_the_orm.py +++ b/alembic/versions/3c683a662c82_migrate_jobs_to_the_orm.py @@ -9,9 +9,10 @@ Create Date: 2024-12-04 15:59:41.708396 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "3c683a662c82" down_revision: Union[str, None] = "5987401b40ae" diff --git a/alembic/versions/4e88e702f85e_drop_api_tokens_table_in_oss.py b/alembic/versions/4e88e702f85e_drop_api_tokens_table_in_oss.py index b692e855..75a90445 100644 --- a/alembic/versions/4e88e702f85e_drop_api_tokens_table_in_oss.py +++ b/alembic/versions/4e88e702f85e_drop_api_tokens_table_in_oss.py @@ -9,6 +9,7 @@ Create Date: 2024-12-13 17:19:55.796210 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/54dec07619c4_divide_passage_table_into_.py b/alembic/versions/54dec07619c4_divide_passage_table_into_.py index ead70ec6..e164a997 100644 --- a/alembic/versions/54dec07619c4_divide_passage_table_into_.py +++ b/alembic/versions/54dec07619c4_divide_passage_table_into_.py @@ -9,11 +9,12 @@ Create Date: 2024-12-14 17:23:08.772554 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op -from letta.orm.custom_columns import EmbeddingConfigColumn from pgvector.sqlalchemy import Vector from sqlalchemy.dialects import postgresql +from alembic import op +from letta.orm.custom_columns import EmbeddingConfigColumn + # revision identifiers, used by Alembic. revision: str = "54dec07619c4" down_revision: Union[str, None] = "4e88e702f85e" diff --git a/alembic/versions/5987401b40ae_refactor_agent_memory.py b/alembic/versions/5987401b40ae_refactor_agent_memory.py index 84e4ebe2..889e9425 100644 --- a/alembic/versions/5987401b40ae_refactor_agent_memory.py +++ b/alembic/versions/5987401b40ae_refactor_agent_memory.py @@ -9,9 +9,10 @@ Create Date: 2024-11-25 14:35:00.896507 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "5987401b40ae" down_revision: Union[str, None] = "1c8880d671ee" diff --git a/alembic/versions/95badb46fdf9_migrate_messages_to_the_orm.py b/alembic/versions/95badb46fdf9_migrate_messages_to_the_orm.py index f200e65e..73254e39 100644 --- a/alembic/versions/95badb46fdf9_migrate_messages_to_the_orm.py +++ b/alembic/versions/95badb46fdf9_migrate_messages_to_the_orm.py @@ -9,9 +9,10 @@ Create Date: 2024-12-05 14:02:04.163150 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "95badb46fdf9" down_revision: Union[str, None] = "08b2f8225812" diff --git a/alembic/versions/9a505cc7eca9_create_a_baseline_migrations.py b/alembic/versions/9a505cc7eca9_create_a_baseline_migrations.py index 6ef44d47..21f6a396 100644 --- a/alembic/versions/9a505cc7eca9_create_a_baseline_migrations.py +++ b/alembic/versions/9a505cc7eca9_create_a_baseline_migrations.py @@ -8,12 +8,13 @@ Create Date: 2024-10-11 14:19:19.875656 from typing import Sequence, Union -import letta.orm import pgvector import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +import letta.orm +from alembic import op + # revision identifiers, used by Alembic. revision: str = "9a505cc7eca9" down_revision: Union[str, None] = None diff --git a/alembic/versions/a91994b9752f_add_column_to_tools_table_to_contain_.py b/alembic/versions/a91994b9752f_add_column_to_tools_table_to_contain_.py index 157e87ef..f8da3856 100644 --- a/alembic/versions/a91994b9752f_add_column_to_tools_table_to_contain_.py +++ b/alembic/versions/a91994b9752f_add_column_to_tools_table_to_contain_.py @@ -9,6 +9,7 @@ Create Date: 2024-12-09 18:27:25.650079 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op from letta.constants import FUNCTION_RETURN_CHAR_LIMIT diff --git a/alembic/versions/b6d7ca024aa9_add_agents_tags_table.py b/alembic/versions/b6d7ca024aa9_add_agents_tags_table.py index 638bc5b5..2aec8a09 100644 --- a/alembic/versions/b6d7ca024aa9_add_agents_tags_table.py +++ b/alembic/versions/b6d7ca024aa9_add_agents_tags_table.py @@ -9,6 +9,7 @@ Create Date: 2024-11-06 10:48:08.424108 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/c5d964280dff_add_passages_orm_drop_legacy_passages_.py b/alembic/versions/c5d964280dff_add_passages_orm_drop_legacy_passages_.py index fb0eafab..b6d2e6ba 100644 --- a/alembic/versions/c5d964280dff_add_passages_orm_drop_legacy_passages_.py +++ b/alembic/versions/c5d964280dff_add_passages_orm_drop_legacy_passages_.py @@ -9,9 +9,10 @@ Create Date: 2024-12-10 15:05:32.335519 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "c5d964280dff" down_revision: Union[str, None] = "a91994b9752f" diff --git a/alembic/versions/c85a3d07c028_move_files_to_orm.py b/alembic/versions/c85a3d07c028_move_files_to_orm.py index 7d853e6a..b05d7930 100644 --- a/alembic/versions/c85a3d07c028_move_files_to_orm.py +++ b/alembic/versions/c85a3d07c028_move_files_to_orm.py @@ -9,6 +9,7 @@ Create Date: 2024-11-12 13:58:57.221081 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/cda66b6cb0d6_move_sources_to_orm.py b/alembic/versions/cda66b6cb0d6_move_sources_to_orm.py index ae10edbd..f46bef6b 100644 --- a/alembic/versions/cda66b6cb0d6_move_sources_to_orm.py +++ b/alembic/versions/cda66b6cb0d6_move_sources_to_orm.py @@ -9,9 +9,10 @@ Create Date: 2024-11-07 13:29:57.186107 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "cda66b6cb0d6" down_revision: Union[str, None] = "b6d7ca024aa9" diff --git a/alembic/versions/d05669b60ebe_migrate_agents_to_orm.py b/alembic/versions/d05669b60ebe_migrate_agents_to_orm.py index 61b24f5e..d03652c8 100644 --- a/alembic/versions/d05669b60ebe_migrate_agents_to_orm.py +++ b/alembic/versions/d05669b60ebe_migrate_agents_to_orm.py @@ -9,9 +9,10 @@ Create Date: 2024-12-12 10:25:31.825635 from typing import Sequence, Union import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "d05669b60ebe" down_revision: Union[str, None] = "c5d964280dff" diff --git a/alembic/versions/d14ae606614c_move_organizations_users_tools_to_orm.py b/alembic/versions/d14ae606614c_move_organizations_users_tools_to_orm.py index 5c0dab19..e8733313 100644 --- a/alembic/versions/d14ae606614c_move_organizations_users_tools_to_orm.py +++ b/alembic/versions/d14ae606614c_move_organizations_users_tools_to_orm.py @@ -8,11 +8,12 @@ Create Date: 2024-11-05 15:03:12.350096 from typing import Sequence, Union -import letta import sqlalchemy as sa -from alembic import op from sqlalchemy.dialects import postgresql +import letta +from alembic import op + # revision identifiers, used by Alembic. revision: str = "d14ae606614c" down_revision: Union[str, None] = "9a505cc7eca9" diff --git a/alembic/versions/e1a625072dbf_tweak_created_at_field_for_messages.py b/alembic/versions/e1a625072dbf_tweak_created_at_field_for_messages.py index 4fd8abd2..fb425db3 100644 --- a/alembic/versions/e1a625072dbf_tweak_created_at_field_for_messages.py +++ b/alembic/versions/e1a625072dbf_tweak_created_at_field_for_messages.py @@ -8,9 +8,10 @@ Create Date: 2024-12-07 14:28:27.643583 from typing import Sequence, Union -from alembic import op from sqlalchemy.dialects import postgresql +from alembic import op + # revision identifiers, used by Alembic. revision: str = "e1a625072dbf" down_revision: Union[str, None] = "95badb46fdf9" diff --git a/alembic/versions/f7507eab4bb9_migrate_blocks_to_orm_model.py b/alembic/versions/f7507eab4bb9_migrate_blocks_to_orm_model.py index 37a67d88..9e7fa270 100644 --- a/alembic/versions/f7507eab4bb9_migrate_blocks_to_orm_model.py +++ b/alembic/versions/f7507eab4bb9_migrate_blocks_to_orm_model.py @@ -9,6 +9,7 @@ Create Date: 2024-11-18 15:40:13.149438 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/alembic/versions/f81ceea2c08d_create_sandbox_config_and_sandbox_env_.py b/alembic/versions/f81ceea2c08d_create_sandbox_config_and_sandbox_env_.py index 32a1b677..55332bfc 100644 --- a/alembic/versions/f81ceea2c08d_create_sandbox_config_and_sandbox_env_.py +++ b/alembic/versions/f81ceea2c08d_create_sandbox_config_and_sandbox_env_.py @@ -9,6 +9,7 @@ Create Date: 2024-11-14 17:51:27.263561 from typing import Sequence, Union import sqlalchemy as sa + from alembic import op # revision identifiers, used by Alembic. diff --git a/examples/swarm/simple.py b/examples/swarm/simple.py index 7bedb032..8e10c486 100644 --- a/examples/swarm/simple.py +++ b/examples/swarm/simple.py @@ -1,7 +1,8 @@ import typer -from letta import EmbeddingConfig, LLMConfig from swarm import Swarm +from letta import EmbeddingConfig, LLMConfig + """ This is an example of how to implement the basic example provided by OpenAI for tranferring a conversation between two agents: https://github.com/openai/swarm/tree/main?tab=readme-ov-file#usage diff --git a/examples/swarm/swarm.py b/examples/swarm/swarm.py index 40552997..ef080806 100644 --- a/examples/swarm/swarm.py +++ b/examples/swarm/swarm.py @@ -2,6 +2,7 @@ import json from typing import List, Optional import typer + from letta import AgentState, EmbeddingConfig, LLMConfig, create_client from letta.schemas.agent import AgentType from letta.schemas.memory import BasicBlockMemory, Block diff --git a/examples/tool_rule_usage.py b/examples/tool_rule_usage.py index 4e0193f8..54e051e2 100644 --- a/examples/tool_rule_usage.py +++ b/examples/tool_rule_usage.py @@ -4,10 +4,7 @@ import uuid from letta import create_client from letta.schemas.letta_message import ToolCallMessage from letta.schemas.tool_rule import ChildToolRule, InitToolRule, TerminalToolRule -from tests.helpers.endpoints_helper import ( - assert_invoked_send_message_with_keyword, - setup_agent, -) +from tests.helpers.endpoints_helper import assert_invoked_send_message_with_keyword, setup_agent from tests.helpers.utils import cleanup from tests.test_model_letta_perfomance import llm_config_dir diff --git a/letta/__init__.py b/letta/__init__.py index d7911ff5..46390abe 100644 --- a/letta/__init__.py +++ b/letta/__init__.py @@ -12,13 +12,7 @@ from letta.schemas.file import FileMetadata from letta.schemas.job import Job from letta.schemas.letta_message import LettaMessage from letta.schemas.llm_config import LLMConfig -from letta.schemas.memory import ( - ArchivalMemorySummary, - BasicBlockMemory, - ChatMemory, - Memory, - RecallMemorySummary, -) +from letta.schemas.memory import ArchivalMemorySummary, BasicBlockMemory, ChatMemory, Memory, RecallMemorySummary from letta.schemas.message import Message from letta.schemas.openai.chat_completion_response import UsageStatistics from letta.schemas.organization import Organization diff --git a/letta/agent.py b/letta/agent.py index 12515eba..f61ace90 100644 --- a/letta/agent.py +++ b/letta/agent.py @@ -7,17 +7,17 @@ from abc import ABC, abstractmethod from typing import List, Optional, Tuple, Union from letta.constants import ( - BASE_TOOLS, - CLI_WARNING_PREFIX, - ERROR_MESSAGE_PREFIX, - FIRST_MESSAGE_ATTEMPTS, - FUNC_FAILED_HEARTBEAT_MESSAGE, - LLM_MAX_TOKENS, - MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST, - MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC, - MESSAGE_SUMMARY_WARNING_FRAC, - O1_BASE_TOOLS, - REQ_HEARTBEAT_MESSAGE, + BASE_TOOLS, + CLI_WARNING_PREFIX, + ERROR_MESSAGE_PREFIX, + FIRST_MESSAGE_ATTEMPTS, + FUNC_FAILED_HEARTBEAT_MESSAGE, + LLM_MAX_TOKENS, + MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST, + MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC, + MESSAGE_SUMMARY_WARNING_FRAC, + O1_BASE_TOOLS, + REQ_HEARTBEAT_MESSAGE, ) from letta.errors import ContextWindowExceededError from letta.helpers import ToolRulesSolver @@ -33,44 +33,31 @@ from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.enums import MessageRole from letta.schemas.memory import ContextWindowOverview, Memory from letta.schemas.message import Message -from letta.schemas.openai.chat_completion_request import ( - Tool as ChatCompletionRequestTool, -) +from letta.schemas.openai.chat_completion_request import Tool as ChatCompletionRequestTool from letta.schemas.openai.chat_completion_response import ChatCompletionResponse -from letta.schemas.openai.chat_completion_response import ( - Message as ChatCompletionMessage, -) +from letta.schemas.openai.chat_completion_response import Message as ChatCompletionMessage from letta.schemas.openai.chat_completion_response import UsageStatistics from letta.schemas.tool import Tool from letta.schemas.tool_rule import TerminalToolRule from letta.schemas.usage import LettaUsageStatistics from letta.services.agent_manager import AgentManager from letta.services.block_manager import BlockManager -from letta.services.helpers.agent_manager_helper import ( - check_supports_structured_output, - compile_memory_metadata_block, -) +from letta.services.helpers.agent_manager_helper import check_supports_structured_output, compile_memory_metadata_block from letta.services.message_manager import MessageManager from letta.services.passage_manager import PassageManager from letta.services.tool_execution_sandbox import ToolExecutionSandbox from letta.streaming_interface import StreamingRefreshCLIInterface -from letta.system import ( - get_heartbeat, - get_token_limit_warning, - package_function_response, - package_summarize_message, - package_user_message, -) +from letta.system import get_heartbeat, get_token_limit_warning, package_function_response, package_summarize_message, package_user_message from letta.utils import ( - count_tokens, - get_friendly_error_msg, - get_tool_call_id, - get_utc_time, - json_dumps, - json_loads, - parse_json, - printd, - validate_function_response, + count_tokens, + get_friendly_error_msg, + get_tool_call_id, + get_utc_time, + json_dumps, + json_loads, + parse_json, + printd, + validate_function_response, ) diff --git a/letta/benchmark/benchmark.py b/letta/benchmark/benchmark.py index b7c01ab7..7109210e 100644 --- a/letta/benchmark/benchmark.py +++ b/letta/benchmark/benchmark.py @@ -5,6 +5,7 @@ import uuid from typing import Annotated, Union import typer + from letta import LocalClient, RESTClient, create_client from letta.benchmark.constants import HUMAN, PERSONA, PROMPTS, TRIES from letta.config import LettaConfig diff --git a/letta/cli/cli.py b/letta/cli/cli.py index b385a01c..4441190b 100644 --- a/letta/cli/cli.py +++ b/letta/cli/cli.py @@ -3,18 +3,14 @@ import sys from enum import Enum from typing import Annotated, Optional -import letta.utils as utils import questionary import typer + +import letta.utils as utils from letta import create_client from letta.agent import Agent, save_agent from letta.config import LettaConfig -from letta.constants import ( - CLI_WARNING_PREFIX, - CORE_MEMORY_BLOCK_CHAR_LIMIT, - LETTA_DIR, - MIN_CONTEXT_WINDOW, -) +from letta.constants import CLI_WARNING_PREFIX, CORE_MEMORY_BLOCK_CHAR_LIMIT, LETTA_DIR, MIN_CONTEXT_WINDOW from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL from letta.log import get_logger from letta.schemas.enums import OptionState @@ -22,9 +18,7 @@ from letta.schemas.memory import ChatMemory, Memory from letta.server.server import logger as server_logger # from letta.interface import CLIInterface as interface # for printing to terminal -from letta.streaming_interface import ( - StreamingRefreshCLIInterface as interface, # for printing to terminal -) +from letta.streaming_interface import StreamingRefreshCLIInterface as interface # for printing to terminal from letta.utils import open_folder_in_explorer, printd logger = get_logger(__name__) diff --git a/letta/cli/cli_config.py b/letta/cli/cli_config.py index f70b466b..8278d553 100644 --- a/letta/cli/cli_config.py +++ b/letta/cli/cli_config.py @@ -5,10 +5,11 @@ from typing import Annotated, List, Optional import questionary import typer -from letta import utils from prettytable.colortable import ColorTable, Themes from tqdm import tqdm +from letta import utils + app = typer.Typer() diff --git a/letta/cli/cli_load.py b/letta/cli/cli_load.py index e1d7b1b8..b27da4d8 100644 --- a/letta/cli/cli_load.py +++ b/letta/cli/cli_load.py @@ -13,6 +13,7 @@ from typing import Annotated, List, Optional import questionary import typer + from letta import create_client from letta.data_sources.connectors import DirectoryConnector diff --git a/letta/client/client.py b/letta/client/client.py index eb1b906f..9931628c 100644 --- a/letta/client/client.py +++ b/letta/client/client.py @@ -2,16 +2,10 @@ import logging import time from typing import Callable, Dict, Generator, List, Optional, Union -import letta.utils import requests -from letta.constants import ( - ADMIN_PREFIX, - BASE_MEMORY_TOOLS, - BASE_TOOLS, - DEFAULT_HUMAN, - DEFAULT_PERSONA, - FUNCTION_RETURN_CHAR_LIMIT, -) + +import letta.utils +from letta.constants import ADMIN_PREFIX, BASE_MEMORY_TOOLS, BASE_TOOLS, DEFAULT_HUMAN, DEFAULT_PERSONA, FUNCTION_RETURN_CHAR_LIMIT from letta.data_sources.connectors import DataConnector from letta.functions.functions import parse_source_code from letta.orm.errors import NoResultFound @@ -26,26 +20,20 @@ from letta.schemas.job import Job from letta.schemas.letta_request import LettaRequest, LettaStreamingRequest from letta.schemas.letta_response import LettaResponse, LettaStreamingResponse from letta.schemas.llm_config import LLMConfig -from letta.schemas.memory import ( - ArchivalMemorySummary, - ChatMemory, - CreateArchivalMemory, - Memory, - RecallMemorySummary, -) +from letta.schemas.memory import ArchivalMemorySummary, ChatMemory, CreateArchivalMemory, Memory, RecallMemorySummary from letta.schemas.message import Message, MessageCreate, MessageUpdate from letta.schemas.openai.chat_completions import ToolCall from letta.schemas.organization import Organization from letta.schemas.passage import Passage from letta.schemas.sandbox_config import ( - E2BSandboxConfig, - LocalSandboxConfig, - SandboxConfig, - SandboxConfigCreate, - SandboxConfigUpdate, - SandboxEnvironmentVariable, - SandboxEnvironmentVariableCreate, - SandboxEnvironmentVariableUpdate, + E2BSandboxConfig, + LocalSandboxConfig, + SandboxConfig, + SandboxConfigCreate, + SandboxConfigUpdate, + SandboxEnvironmentVariable, + SandboxEnvironmentVariableCreate, + SandboxEnvironmentVariableUpdate, ) from letta.schemas.source import Source, SourceCreate, SourceUpdate from letta.schemas.tool import Tool, ToolCreate, ToolUpdate diff --git a/letta/client/streaming.py b/letta/client/streaming.py index 130e8ef2..86be5c41 100644 --- a/letta/client/streaming.py +++ b/letta/client/streaming.py @@ -3,14 +3,11 @@ from typing import Generator import httpx from httpx_sse import SSEError, connect_sse + from letta.constants import OPENAI_CONTEXT_WINDOW_ERROR_SUBSTRING from letta.errors import LLMError from letta.schemas.enums import MessageStreamStatus -from letta.schemas.letta_message import ( - ReasoningMessage, - ToolCallMessage, - ToolReturnMessage, -) +from letta.schemas.letta_message import ReasoningMessage, ToolCallMessage, ToolReturnMessage from letta.schemas.letta_response import LettaStreamingResponse from letta.schemas.usage import LettaUsageStatistics diff --git a/letta/client/utils.py b/letta/client/utils.py index 1588f7d1..f823ee87 100644 --- a/letta/client/utils.py +++ b/letta/client/utils.py @@ -3,12 +3,10 @@ from datetime import datetime from typing import Optional from IPython.display import HTML, display -from letta.local_llm.constants import ( - ASSISTANT_MESSAGE_CLI_SYMBOL, - INNER_THOUGHTS_CLI_SYMBOL, -) from sqlalchemy.testing.plugin.plugin_base import warnings +from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL, INNER_THOUGHTS_CLI_SYMBOL + def pprint(messages): """Utility function for pretty-printing the output of client.send_message in notebooks""" diff --git a/letta/config.py b/letta/config.py index a50154a6..ed9e8668 100644 --- a/letta/config.py +++ b/letta/config.py @@ -5,12 +5,12 @@ from typing import Optional import letta from letta.constants import ( - CORE_MEMORY_HUMAN_CHAR_LIMIT, - CORE_MEMORY_PERSONA_CHAR_LIMIT, - DEFAULT_HUMAN, - DEFAULT_PERSONA, - DEFAULT_PRESET, - LETTA_DIR, + CORE_MEMORY_HUMAN_CHAR_LIMIT, + CORE_MEMORY_PERSONA_CHAR_LIMIT, + DEFAULT_HUMAN, + DEFAULT_PERSONA, + DEFAULT_PRESET, + LETTA_DIR, ) from letta.log import get_logger from letta.schemas.embedding_config import EmbeddingConfig diff --git a/letta/data_sources/connectors.py b/letta/data_sources/connectors.py index 274e2524..8ae67f88 100644 --- a/letta/data_sources/connectors.py +++ b/letta/data_sources/connectors.py @@ -1,11 +1,8 @@ from typing import Dict, Iterator, List, Tuple import typer -from letta.data_sources.connectors_helper import ( - assert_all_files_exist_locally, - extract_metadata_from_files, - get_filenames_in_dir, -) + +from letta.data_sources.connectors_helper import assert_all_files_exist_locally, extract_metadata_from_files, get_filenames_in_dir from letta.embeddings import embedding_model from letta.schemas.file import FileMetadata from letta.schemas.passage import Passage diff --git a/letta/embeddings.py b/letta/embeddings.py index 56f01631..e588f17a 100644 --- a/letta/embeddings.py +++ b/letta/embeddings.py @@ -3,11 +3,8 @@ from typing import Any, List, Optional import numpy as np import tiktoken -from letta.constants import ( - EMBEDDING_TO_TOKENIZER_DEFAULT, - EMBEDDING_TO_TOKENIZER_MAP, - MAX_EMBEDDING_DIM, -) + +from letta.constants import EMBEDDING_TO_TOKENIZER_DEFAULT, EMBEDDING_TO_TOKENIZER_MAP, MAX_EMBEDDING_DIM from letta.schemas.embedding_config import EmbeddingConfig from letta.utils import is_valid_url, printd diff --git a/letta/functions/function_sets/extras.py b/letta/functions/function_sets/extras.py index c8edc93c..d5d21644 100644 --- a/letta/functions/function_sets/extras.py +++ b/letta/functions/function_sets/extras.py @@ -3,10 +3,8 @@ import uuid from typing import Optional import requests -from letta.constants import ( - MESSAGE_CHATGPT_FUNCTION_MODEL, - MESSAGE_CHATGPT_FUNCTION_SYSTEM_MESSAGE, -) + +from letta.constants import MESSAGE_CHATGPT_FUNCTION_MODEL, MESSAGE_CHATGPT_FUNCTION_SYSTEM_MESSAGE from letta.llm_api.llm_api_tools import create from letta.schemas.message import Message from letta.utils import json_dumps, json_loads diff --git a/letta/helpers/tool_rule_solver.py b/letta/helpers/tool_rule_solver.py index b9370bf7..cba8a0ca 100644 --- a/letta/helpers/tool_rule_solver.py +++ b/letta/helpers/tool_rule_solver.py @@ -1,16 +1,11 @@ import json from typing import List, Optional, Union -from letta.schemas.enums import ToolRuleType -from letta.schemas.tool_rule import ( - BaseToolRule, - ChildToolRule, - ConditionalToolRule, - InitToolRule, - TerminalToolRule, -) from pydantic import BaseModel, Field +from letta.schemas.enums import ToolRuleType +from letta.schemas.tool_rule import BaseToolRule, ChildToolRule, ConditionalToolRule, InitToolRule, TerminalToolRule + class ToolRuleValidationError(Exception): """Custom exception for tool rule validation errors in ToolRulesSolver.""" diff --git a/letta/interface.py b/letta/interface.py index 22e9678c..28cb0264 100644 --- a/letta/interface.py +++ b/letta/interface.py @@ -3,11 +3,9 @@ from abc import ABC, abstractmethod from typing import List, Optional from colorama import Fore, Style, init + from letta.constants import CLI_WARNING_PREFIX -from letta.local_llm.constants import ( - ASSISTANT_MESSAGE_CLI_SYMBOL, - INNER_THOUGHTS_CLI_SYMBOL, -) +from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL, INNER_THOUGHTS_CLI_SYMBOL from letta.schemas.message import Message from letta.utils import json_loads, printd diff --git a/letta/llm_api/anthropic.py b/letta/llm_api/anthropic.py index 059c0881..fb42e696 100644 --- a/letta/llm_api/anthropic.py +++ b/letta/llm_api/anthropic.py @@ -5,13 +5,9 @@ from typing import List, Optional, Union from letta.llm_api.helpers import make_post_request from letta.schemas.message import Message from letta.schemas.openai.chat_completion_request import ChatCompletionRequest, Tool +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - FunctionCall, -) -from letta.schemas.openai.chat_completion_response import ( - Message as ChoiceMessage, # NOTE: avoid conflict with our own Letta Message datatype + Message as ChoiceMessage, # NOTE: avoid conflict with our own Letta Message datatype ) from letta.schemas.openai.chat_completion_response import ToolCall, UsageStatistics from letta.utils import get_utc_time, smart_urljoin diff --git a/letta/llm_api/azure_openai.py b/letta/llm_api/azure_openai.py index 047f2f86..e60b547b 100644 --- a/letta/llm_api/azure_openai.py +++ b/letta/llm_api/azure_openai.py @@ -1,6 +1,7 @@ from collections import defaultdict import requests + from letta.llm_api.helpers import make_post_request from letta.schemas.llm_config import LLMConfig from letta.schemas.openai.chat_completion_response import ChatCompletionResponse diff --git a/letta/llm_api/cohere.py b/letta/llm_api/cohere.py index 7ea633e0..0259f6fe 100644 --- a/letta/llm_api/cohere.py +++ b/letta/llm_api/cohere.py @@ -3,16 +3,13 @@ import uuid from typing import List, Optional, Union import requests + from letta.local_llm.utils import count_tokens from letta.schemas.message import Message from letta.schemas.openai.chat_completion_request import ChatCompletionRequest, Tool +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - FunctionCall, -) -from letta.schemas.openai.chat_completion_response import ( - Message as ChoiceMessage, # NOTE: avoid conflict with our own Letta Message datatype + Message as ChoiceMessage, # NOTE: avoid conflict with our own Letta Message datatype ) from letta.schemas.openai.chat_completion_response import ToolCall, UsageStatistics from letta.utils import get_tool_call_id, get_utc_time, json_dumps, smart_urljoin @@ -275,10 +272,7 @@ def convert_tools_to_cohere_format(tools: List[Tool], inner_thoughts_in_kwargs: if inner_thoughts_in_kwargs: # NOTE: since Cohere doesn't allow "text" in the response when a tool call happens, if we want # a simultaneous CoT + tool call we need to put it inside a kwarg - from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, - ) + from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION for cohere_tool in tools_dict_list: cohere_tool["parameter_definitions"][INNER_THOUGHTS_KWARG] = { diff --git a/letta/llm_api/google_ai.py b/letta/llm_api/google_ai.py index 483a319f..1eec3eaa 100644 --- a/letta/llm_api/google_ai.py +++ b/letta/llm_api/google_ai.py @@ -2,19 +2,13 @@ import uuid from typing import List, Optional, Tuple import requests + from letta.constants import NON_USER_MSG_PREFIX from letta.llm_api.helpers import make_post_request from letta.local_llm.json_parser import clean_json_string_extra_backslash from letta.local_llm.utils import count_tokens from letta.schemas.openai.chat_completion_request import Tool -from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - FunctionCall, - Message, - ToolCall, - UsageStatistics, -) +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall, Message, ToolCall, UsageStatistics from letta.utils import get_tool_call_id, get_utc_time, json_dumps @@ -229,10 +223,7 @@ def convert_tools_to_google_ai_format(tools: List[Tool], inner_thoughts_in_kwarg param_fields["type"] = param_fields["type"].upper() # Add inner thoughts if inner_thoughts_in_kwargs: - from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, - ) + from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION func["parameters"]["properties"][INNER_THOUGHTS_KWARG] = { "type": "STRING", diff --git a/letta/llm_api/helpers.py b/letta/llm_api/helpers.py index 25f77e24..1244b6ff 100644 --- a/letta/llm_api/helpers.py +++ b/letta/llm_api/helpers.py @@ -5,6 +5,7 @@ from collections import OrderedDict from typing import Any, List, Union import requests + from letta.constants import OPENAI_CONTEXT_WINDOW_ERROR_SUBSTRING from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice from letta.utils import json_dumps, printd diff --git a/letta/llm_api/llm_api_tools.py b/letta/llm_api/llm_api_tools.py index 9acb1f01..030d7375 100644 --- a/letta/llm_api/llm_api_tools.py +++ b/letta/llm_api/llm_api_tools.py @@ -3,42 +3,27 @@ import time from typing import List, Optional, Union import requests + from letta.constants import CLI_WARNING_PREFIX from letta.errors import LettaConfigurationError, RateLimitExceededError from letta.llm_api.anthropic import anthropic_chat_completions_request from letta.llm_api.azure_openai import azure_openai_chat_completions_request -from letta.llm_api.google_ai import ( - convert_tools_to_google_ai_format, - google_ai_chat_completions_request, -) -from letta.llm_api.helpers import ( - add_inner_thoughts_to_functions, - unpack_all_inner_thoughts_from_kwargs, -) +from letta.llm_api.google_ai import convert_tools_to_google_ai_format, google_ai_chat_completions_request +from letta.llm_api.helpers import add_inner_thoughts_to_functions, unpack_all_inner_thoughts_from_kwargs from letta.llm_api.openai import ( - build_openai_chat_completions_request, - openai_chat_completions_process_stream, - openai_chat_completions_request, + build_openai_chat_completions_request, + openai_chat_completions_process_stream, + openai_chat_completions_request, ) from letta.local_llm.chat_completion_proxy import get_chat_completion -from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, -) +from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION from letta.local_llm.utils import num_tokens_from_functions, num_tokens_from_messages from letta.schemas.llm_config import LLMConfig from letta.schemas.message import Message -from letta.schemas.openai.chat_completion_request import ( - ChatCompletionRequest, - Tool, - cast_message_to_subtype, -) +from letta.schemas.openai.chat_completion_request import ChatCompletionRequest, Tool, cast_message_to_subtype from letta.schemas.openai.chat_completion_response import ChatCompletionResponse from letta.settings import ModelSettings -from letta.streaming_interface import ( - AgentChunkStreamingInterface, - AgentRefreshStreamingInterface, -) +from letta.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface LLM_API_PROVIDER_OPTIONS = ["openai", "azure", "anthropic", "google_ai", "cohere", "local", "groq"] diff --git a/letta/llm_api/mistral.py b/letta/llm_api/mistral.py index b53d76ed..932cf874 100644 --- a/letta/llm_api/mistral.py +++ b/letta/llm_api/mistral.py @@ -1,4 +1,5 @@ import requests + from letta.utils import printd, smart_urljoin diff --git a/letta/llm_api/openai.py b/letta/llm_api/openai.py index 3ad3cf2a..bb355756 100644 --- a/letta/llm_api/openai.py +++ b/letta/llm_api/openai.py @@ -6,44 +6,29 @@ import httpx import requests from httpx_sse import connect_sse from httpx_sse._exceptions import SSEError + from letta.constants import OPENAI_CONTEXT_WINDOW_ERROR_SUBSTRING from letta.errors import LLMError -from letta.llm_api.helpers import ( - add_inner_thoughts_to_functions, - convert_to_structured_output, - make_post_request, -) -from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, -) +from letta.llm_api.helpers import add_inner_thoughts_to_functions, convert_to_structured_output, make_post_request +from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION from letta.local_llm.utils import num_tokens_from_functions, num_tokens_from_messages from letta.schemas.llm_config import LLMConfig from letta.schemas.message import Message as _Message from letta.schemas.message import MessageRole as _MessageRole from letta.schemas.openai.chat_completion_request import ChatCompletionRequest -from letta.schemas.openai.chat_completion_request import ( - FunctionCall as ToolFunctionChoiceFunctionCall, -) -from letta.schemas.openai.chat_completion_request import ( - Tool, - ToolFunctionChoice, - cast_message_to_subtype, -) +from letta.schemas.openai.chat_completion_request import FunctionCall as ToolFunctionChoiceFunctionCall +from letta.schemas.openai.chat_completion_request import Tool, ToolFunctionChoice, cast_message_to_subtype from letta.schemas.openai.chat_completion_response import ( - ChatCompletionChunkResponse, - ChatCompletionResponse, - Choice, - FunctionCall, - Message, - ToolCall, - UsageStatistics, + ChatCompletionChunkResponse, + ChatCompletionResponse, + Choice, + FunctionCall, + Message, + ToolCall, + UsageStatistics, ) from letta.schemas.openai.embedding_response import EmbeddingResponse -from letta.streaming_interface import ( - AgentChunkStreamingInterface, - AgentRefreshStreamingInterface, -) +from letta.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface from letta.utils import get_tool_call_id, smart_urljoin OPENAI_SSE_DONE = "[DONE]" diff --git a/letta/local_llm/chat_completion_proxy.py b/letta/local_llm/chat_completion_proxy.py index aa173181..184489c8 100644 --- a/letta/local_llm/chat_completion_proxy.py +++ b/letta/local_llm/chat_completion_proxy.py @@ -3,14 +3,12 @@ import uuid import requests + from letta.constants import CLI_WARNING_PREFIX from letta.errors import LocalLLMConnectionError, LocalLLMError from letta.local_llm.constants import DEFAULT_WRAPPER from letta.local_llm.function_parser import patch_function -from letta.local_llm.grammars.gbnf_grammar_generator import ( - create_dynamic_model_from_function, - generate_gbnf_grammar_and_documentation, -) +from letta.local_llm.grammars.gbnf_grammar_generator import create_dynamic_model_from_function, generate_gbnf_grammar_and_documentation from letta.local_llm.koboldcpp.api import get_koboldcpp_completion from letta.local_llm.llamacpp.api import get_llamacpp_completion from letta.local_llm.llm_chat_completion_wrappers import simple_summary_wrapper @@ -19,17 +17,9 @@ from letta.local_llm.ollama.api import get_ollama_completion from letta.local_llm.utils import count_tokens, get_available_wrappers from letta.local_llm.vllm.api import get_vllm_completion from letta.local_llm.webui.api import get_webui_completion -from letta.local_llm.webui.legacy_api import ( - get_webui_completion as get_webui_completion_legacy, -) +from letta.local_llm.webui.legacy_api import get_webui_completion as get_webui_completion_legacy from letta.prompts.gpt_summarize import SYSTEM as SUMMARIZE_SYSTEM_MESSAGE -from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - Message, - ToolCall, - UsageStatistics, -) +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, Message, ToolCall, UsageStatistics from letta.utils import get_tool_call_id, get_utc_time, json_dumps has_shown_warning = False diff --git a/letta/local_llm/constants.py b/letta/local_llm/constants.py index 4552f103..03abcc81 100644 --- a/letta/local_llm/constants.py +++ b/letta/local_llm/constants.py @@ -1,7 +1,5 @@ # import letta.local_llm.llm_chat_completion_wrappers.airoboros as airoboros -from letta.local_llm.llm_chat_completion_wrappers.chatml import ( - ChatMLInnerMonologueWrapper, -) +from letta.local_llm.llm_chat_completion_wrappers.chatml import ChatMLInnerMonologueWrapper DEFAULT_ENDPOINTS = { # Local diff --git a/letta/local_llm/grammars/gbnf_grammar_generator.py b/letta/local_llm/grammars/gbnf_grammar_generator.py index ce3ace73..402b21bf 100644 --- a/letta/local_llm/grammars/gbnf_grammar_generator.py +++ b/letta/local_llm/grammars/gbnf_grammar_generator.py @@ -5,23 +5,13 @@ from copy import copy 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 typing import Any, Callable, List, Optional, Tuple, Type, Union, _GenericAlias, get_args, get_origin from docstring_parser import parse -from letta.utils import json_dumps from pydantic import BaseModel, create_model +from letta.utils import json_dumps + class PydanticDataType(Enum): """ diff --git a/letta/local_llm/llm_chat_completion_wrappers/chatml.py b/letta/local_llm/llm_chat_completion_wrappers/chatml.py index 583b77b9..2c1ebaf7 100644 --- a/letta/local_llm/llm_chat_completion_wrappers/chatml.py +++ b/letta/local_llm/llm_chat_completion_wrappers/chatml.py @@ -1,8 +1,6 @@ from letta.errors import LLMJSONParsingError from letta.local_llm.json_parser import clean_json -from letta.local_llm.llm_chat_completion_wrappers.wrapper_base import ( - LLMChatCompletionWrapper, -) +from letta.local_llm.llm_chat_completion_wrappers.wrapper_base import LLMChatCompletionWrapper from letta.schemas.enums import MessageRole from letta.utils import json_dumps, json_loads @@ -75,10 +73,7 @@ class ChatMLInnerMonologueWrapper(LLMChatCompletionWrapper): func_str += f"\n description: {schema['description']}" func_str += f"\n params:" if add_inner_thoughts: - from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, - ) + from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION func_str += f"\n {INNER_THOUGHTS_KWARG}: {INNER_THOUGHTS_KWARG_DESCRIPTION}" for param_k, param_v in schema["parameters"]["properties"].items(): diff --git a/letta/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py b/letta/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py index 4b41d7a5..19f25668 100644 --- a/letta/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py +++ b/letta/local_llm/llm_chat_completion_wrappers/configurable_wrapper.py @@ -1,4 +1,5 @@ import yaml + from letta.utils import json_dumps, json_loads from ...errors import LLMJSONParsingError diff --git a/letta/local_llm/llm_chat_completion_wrappers/llama3.py b/letta/local_llm/llm_chat_completion_wrappers/llama3.py index 43174dd5..804e90db 100644 --- a/letta/local_llm/llm_chat_completion_wrappers/llama3.py +++ b/letta/local_llm/llm_chat_completion_wrappers/llama3.py @@ -1,8 +1,6 @@ from letta.errors import LLMJSONParsingError from letta.local_llm.json_parser import clean_json -from letta.local_llm.llm_chat_completion_wrappers.wrapper_base import ( - LLMChatCompletionWrapper, -) +from letta.local_llm.llm_chat_completion_wrappers.wrapper_base import LLMChatCompletionWrapper from letta.utils import json_dumps, json_loads PREFIX_HINT = """# Reminders: @@ -74,10 +72,7 @@ class LLaMA3InnerMonologueWrapper(LLMChatCompletionWrapper): func_str += f"\n description: {schema['description']}" func_str += "\n params:" if add_inner_thoughts: - from letta.local_llm.constants import ( - INNER_THOUGHTS_KWARG, - INNER_THOUGHTS_KWARG_DESCRIPTION, - ) + from letta.local_llm.constants import INNER_THOUGHTS_KWARG, INNER_THOUGHTS_KWARG_DESCRIPTION func_str += f"\n {INNER_THOUGHTS_KWARG}: {INNER_THOUGHTS_KWARG_DESCRIPTION}" for param_k, param_v in schema["parameters"]["properties"].items(): diff --git a/letta/local_llm/settings/settings.py b/letta/local_llm/settings/settings.py index 8a3fcbe8..9efbcf6a 100644 --- a/letta/local_llm/settings/settings.py +++ b/letta/local_llm/settings/settings.py @@ -2,9 +2,7 @@ import json import os from letta.constants import LETTA_DIR -from letta.local_llm.settings.deterministic_mirostat import ( - settings as det_miro_settings, -) +from letta.local_llm.settings.deterministic_mirostat import settings as det_miro_settings from letta.local_llm.settings.simple import settings as simple_settings DEFAULT = "simple" diff --git a/letta/local_llm/utils.py b/letta/local_llm/utils.py index 796b3c57..b0529c35 100644 --- a/letta/local_llm/utils.py +++ b/letta/local_llm/utils.py @@ -2,14 +2,15 @@ import os import warnings from typing import List, Union +import requests +import tiktoken + import letta.local_llm.llm_chat_completion_wrappers.airoboros as airoboros import letta.local_llm.llm_chat_completion_wrappers.chatml as chatml import letta.local_llm.llm_chat_completion_wrappers.configurable_wrapper as configurable_wrapper import letta.local_llm.llm_chat_completion_wrappers.dolphin as dolphin import letta.local_llm.llm_chat_completion_wrappers.llama3 as llama3 import letta.local_llm.llm_chat_completion_wrappers.zephyr as zephyr -import requests -import tiktoken from letta.schemas.openai.chat_completion_request import Tool, ToolCall diff --git a/letta/main.py b/letta/main.py index bbcd56e5..de1b4028 100644 --- a/letta/main.py +++ b/letta/main.py @@ -2,12 +2,14 @@ import os import sys import traceback -import letta.agent as agent -import letta.errors as errors -import letta.system as system import questionary import requests import typer +from rich.console import Console + +import letta.agent as agent +import letta.errors as errors +import letta.system as system # import benchmark from letta import create_client @@ -20,7 +22,6 @@ from letta.constants import FUNC_FAILED_HEARTBEAT_MESSAGE, REQ_HEARTBEAT_MESSAGE # from letta.interface import CLIInterface as interface # for printing to terminal from letta.streaming_interface import AgentRefreshStreamingInterface -from rich.console import Console # interface = interface() diff --git a/letta/orm/agent.py b/letta/orm/agent.py index b8c541e2..353d4fe7 100644 --- a/letta/orm/agent.py +++ b/letta/orm/agent.py @@ -1,12 +1,11 @@ import uuid from typing import TYPE_CHECKING, List, Optional +from sqlalchemy import JSON, String, UniqueConstraint +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.block import Block -from letta.orm.custom_columns import ( - EmbeddingConfigColumn, - LLMConfigColumn, - ToolRulesColumn, -) +from letta.orm.custom_columns import EmbeddingConfigColumn, LLMConfigColumn, ToolRulesColumn from letta.orm.message import Message from letta.orm.mixins import OrganizationMixin from letta.orm.organization import Organization @@ -17,8 +16,6 @@ from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.llm_config import LLMConfig from letta.schemas.memory import Memory from letta.schemas.tool_rule import ToolRule -from sqlalchemy import JSON, String, UniqueConstraint -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm.agents_tags import AgentsTags diff --git a/letta/orm/agents_tags.py b/letta/orm/agents_tags.py index 5041f629..76ff9011 100644 --- a/letta/orm/agents_tags.py +++ b/letta/orm/agents_tags.py @@ -1,7 +1,8 @@ -from letta.orm.base import Base from sqlalchemy import ForeignKey, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship +from letta.orm.base import Base + class AgentsTags(Base): __tablename__ = "agents_tags" diff --git a/letta/orm/base.py b/letta/orm/base.py index f740ef45..62951741 100644 --- a/letta/orm/base.py +++ b/letta/orm/base.py @@ -2,13 +2,7 @@ from datetime import datetime from typing import Optional from sqlalchemy import Boolean, DateTime, String, func, text -from sqlalchemy.orm import ( - DeclarativeBase, - Mapped, - declarative_mixin, - declared_attr, - mapped_column, -) +from sqlalchemy.orm import DeclarativeBase, Mapped, declarative_mixin, declared_attr, mapped_column class Base(DeclarativeBase): diff --git a/letta/orm/block.py b/letta/orm/block.py index 6759596d..99cfa29b 100644 --- a/letta/orm/block.py +++ b/letta/orm/block.py @@ -1,13 +1,14 @@ from typing import TYPE_CHECKING, Optional, Type +from sqlalchemy import JSON, BigInteger, Integer, UniqueConstraint, event +from sqlalchemy.orm import Mapped, attributes, mapped_column, relationship + from letta.constants import CORE_MEMORY_BLOCK_CHAR_LIMIT from letta.orm.blocks_agents import BlocksAgents from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.block import Block as PydanticBlock from letta.schemas.block import Human, Persona -from sqlalchemy import JSON, BigInteger, Integer, UniqueConstraint, event -from sqlalchemy.orm import Mapped, attributes, mapped_column, relationship if TYPE_CHECKING: from letta.orm import Organization diff --git a/letta/orm/blocks_agents.py b/letta/orm/blocks_agents.py index 86a75e9a..4774783b 100644 --- a/letta/orm/blocks_agents.py +++ b/letta/orm/blocks_agents.py @@ -1,7 +1,8 @@ -from letta.orm.base import Base from sqlalchemy import ForeignKey, ForeignKeyConstraint, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column +from letta.orm.base import Base + class BlocksAgents(Base): """Agents must have one or many blocks to make up their core memory.""" diff --git a/letta/orm/custom_columns.py b/letta/orm/custom_columns.py index 05113a6a..f53169d9 100644 --- a/letta/orm/custom_columns.py +++ b/letta/orm/custom_columns.py @@ -2,18 +2,14 @@ import base64 from typing import List, Union import numpy as np +from sqlalchemy import JSON +from sqlalchemy.types import BINARY, TypeDecorator + from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.enums import ToolRuleType from letta.schemas.llm_config import LLMConfig from letta.schemas.openai.chat_completions import ToolCall, ToolCallFunction -from letta.schemas.tool_rule import ( - ChildToolRule, - ConditionalToolRule, - InitToolRule, - TerminalToolRule, -) -from sqlalchemy import JSON -from sqlalchemy.types import BINARY, TypeDecorator +from letta.schemas.tool_rule import ChildToolRule, ConditionalToolRule, InitToolRule, TerminalToolRule class EmbeddingConfigColumn(TypeDecorator): diff --git a/letta/orm/file.py b/letta/orm/file.py index 4216a01a..88342700 100644 --- a/letta/orm/file.py +++ b/letta/orm/file.py @@ -1,10 +1,11 @@ from typing import TYPE_CHECKING, List, Optional +from sqlalchemy import Integer, String +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.mixins import OrganizationMixin, SourceMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.file import FileMetadata as PydanticFileMetadata -from sqlalchemy import Integer, String -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm.organization import Organization diff --git a/letta/orm/job.py b/letta/orm/job.py index fabdb918..d95abe44 100644 --- a/letta/orm/job.py +++ b/letta/orm/job.py @@ -1,12 +1,13 @@ from datetime import datetime from typing import TYPE_CHECKING, Optional +from sqlalchemy import JSON, String +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.mixins import UserMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.enums import JobStatus from letta.schemas.job import Job as PydanticJob -from sqlalchemy import JSON, String -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm.user import User diff --git a/letta/orm/message.py b/letta/orm/message.py index 6e2194f5..a8bbb900 100644 --- a/letta/orm/message.py +++ b/letta/orm/message.py @@ -1,12 +1,13 @@ from typing import Optional +from sqlalchemy import Index +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.custom_columns import ToolCallColumn from letta.orm.mixins import AgentMixin, OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.message import Message as PydanticMessage from letta.schemas.openai.chat_completions import ToolCall -from sqlalchemy import Index -from sqlalchemy.orm import Mapped, mapped_column, relationship class Message(SqlalchemyBase, OrganizationMixin, AgentMixin): diff --git a/letta/orm/mixins.py b/letta/orm/mixins.py index 3e82f4d6..febf84de 100644 --- a/letta/orm/mixins.py +++ b/letta/orm/mixins.py @@ -1,10 +1,11 @@ from typing import Optional from uuid import UUID -from letta.orm.base import Base from sqlalchemy import ForeignKey, String from sqlalchemy.orm import Mapped, mapped_column +from letta.orm.base import Base + def is_valid_uuid4(uuid_string: str) -> bool: """Check if a string is a valid UUID4.""" diff --git a/letta/orm/organization.py b/letta/orm/organization.py index 9bcc09b2..335a15d0 100644 --- a/letta/orm/organization.py +++ b/letta/orm/organization.py @@ -1,8 +1,9 @@ from typing import TYPE_CHECKING, List, Union +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.organization import Organization as PydanticOrganization -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: diff --git a/letta/orm/passage.py b/letta/orm/passage.py index 8237ed61..492c6021 100644 --- a/letta/orm/passage.py +++ b/letta/orm/passage.py @@ -1,5 +1,8 @@ from typing import TYPE_CHECKING +from sqlalchemy import JSON, Column, Index +from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship + from letta.config import LettaConfig from letta.constants import MAX_EMBEDDING_DIM from letta.orm.custom_columns import CommonVector, EmbeddingConfigColumn @@ -7,8 +10,6 @@ from letta.orm.mixins import AgentMixin, FileMixin, OrganizationMixin, SourceMix from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.passage import Passage as PydanticPassage from letta.settings import settings -from sqlalchemy import JSON, Column, Index -from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship config = LettaConfig() diff --git a/letta/orm/sandbox_config.py b/letta/orm/sandbox_config.py index 600e0c8a..9058657f 100644 --- a/letta/orm/sandbox_config.py +++ b/letta/orm/sandbox_config.py @@ -1,17 +1,16 @@ from typing import TYPE_CHECKING, Dict, List, Optional -from letta.orm.mixins import OrganizationMixin, SandboxConfigMixin -from letta.orm.sqlalchemy_base import SqlalchemyBase -from letta.schemas.sandbox_config import SandboxConfig as PydanticSandboxConfig -from letta.schemas.sandbox_config import ( - SandboxEnvironmentVariable as PydanticSandboxEnvironmentVariable, -) -from letta.schemas.sandbox_config import SandboxType from sqlalchemy import JSON from sqlalchemy import Enum as SqlEnum from sqlalchemy import String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship +from letta.orm.mixins import OrganizationMixin, SandboxConfigMixin +from letta.orm.sqlalchemy_base import SqlalchemyBase +from letta.schemas.sandbox_config import SandboxConfig as PydanticSandboxConfig +from letta.schemas.sandbox_config import SandboxEnvironmentVariable as PydanticSandboxEnvironmentVariable +from letta.schemas.sandbox_config import SandboxType + if TYPE_CHECKING: from letta.orm.organization import Organization diff --git a/letta/orm/source.py b/letta/orm/source.py index 838f4c78..e7443ea6 100644 --- a/letta/orm/source.py +++ b/letta/orm/source.py @@ -1,13 +1,14 @@ from typing import TYPE_CHECKING, List, Optional +from sqlalchemy import JSON +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm import FileMetadata from letta.orm.custom_columns import EmbeddingConfigColumn from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.source import Source as PydanticSource -from sqlalchemy import JSON -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm.agent import Agent diff --git a/letta/orm/sources_agents.py b/letta/orm/sources_agents.py index 2da5003f..ffe8a9d0 100644 --- a/letta/orm/sources_agents.py +++ b/letta/orm/sources_agents.py @@ -1,7 +1,8 @@ -from letta.orm.base import Base from sqlalchemy import ForeignKey, String from sqlalchemy.orm import Mapped, mapped_column +from letta.orm.base import Base + class SourcesAgents(Base): """Agents can have zero to many sources""" diff --git a/letta/orm/sqlalchemy_base.py b/letta/orm/sqlalchemy_base.py index 3e307bc4..c5240f3c 100644 --- a/letta/orm/sqlalchemy_base.py +++ b/letta/orm/sqlalchemy_base.py @@ -3,19 +3,15 @@ from enum import Enum from functools import wraps from typing import TYPE_CHECKING, List, Literal, Optional -from letta.log import get_logger -from letta.orm.base import Base, CommonSqlalchemyMetaMixins -from letta.orm.errors import ( - DatabaseTimeoutError, - ForeignKeyConstraintViolationError, - NoResultFound, - UniqueConstraintViolationError, -) -from letta.orm.sqlite_functions import adapt_array from sqlalchemy import String, desc, func, or_, select from sqlalchemy.exc import DBAPIError, IntegrityError, TimeoutError from sqlalchemy.orm import Mapped, Session, mapped_column +from letta.log import get_logger +from letta.orm.base import Base, CommonSqlalchemyMetaMixins +from letta.orm.errors import DatabaseTimeoutError, ForeignKeyConstraintViolationError, NoResultFound, UniqueConstraintViolationError +from letta.orm.sqlite_functions import adapt_array + if TYPE_CHECKING: from pydantic import BaseModel from sqlalchemy.orm import Session diff --git a/letta/orm/sqlite_functions.py b/letta/orm/sqlite_functions.py index 50c257a0..f5957cd6 100644 --- a/letta/orm/sqlite_functions.py +++ b/letta/orm/sqlite_functions.py @@ -3,10 +3,11 @@ import sqlite3 from typing import Optional, Union import numpy as np -from letta.constants import MAX_EMBEDDING_DIM from sqlalchemy import event from sqlalchemy.engine import Engine +from letta.constants import MAX_EMBEDDING_DIM + def adapt_array(arr): """ diff --git a/letta/orm/tool.py b/letta/orm/tool.py index 50d47506..a25c7ebb 100644 --- a/letta/orm/tool.py +++ b/letta/orm/tool.py @@ -1,12 +1,13 @@ from typing import TYPE_CHECKING, List, Optional +from sqlalchemy import JSON, String, UniqueConstraint +from sqlalchemy.orm import Mapped, mapped_column, relationship + # TODO everything in functions should live in this model from letta.orm.enums import ToolSourceType from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.tool import Tool as PydanticTool -from sqlalchemy import JSON, String, UniqueConstraint -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm.organization import Organization diff --git a/letta/orm/tools_agents.py b/letta/orm/tools_agents.py index 50668d94..52c1e0a1 100644 --- a/letta/orm/tools_agents.py +++ b/letta/orm/tools_agents.py @@ -1,7 +1,8 @@ -from letta.orm import Base from sqlalchemy import ForeignKey, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column +from letta.orm import Base + class ToolsAgents(Base): """Agents can have one or many tools associated with them.""" diff --git a/letta/orm/user.py b/letta/orm/user.py index 23c2b268..9f626b10 100644 --- a/letta/orm/user.py +++ b/letta/orm/user.py @@ -1,9 +1,10 @@ from typing import TYPE_CHECKING, List +from sqlalchemy.orm import Mapped, mapped_column, relationship + from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.user import User as PydanticUser -from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from letta.orm import Job, Organization diff --git a/letta/providers.py b/letta/providers.py index 23964c62..87a7557d 100644 --- a/letta/providers.py +++ b/letta/providers.py @@ -1,14 +1,12 @@ from typing import List, Optional +from pydantic import BaseModel, Field, model_validator + from letta.constants import LLM_MAX_TOKENS, MIN_CONTEXT_WINDOW -from letta.llm_api.azure_openai import ( - get_azure_chat_completions_endpoint, - get_azure_embeddings_endpoint, -) +from letta.llm_api.azure_openai import get_azure_chat_completions_endpoint, get_azure_embeddings_endpoint from letta.llm_api.azure_openai_constants import AZURE_MODEL_TO_CONTEXT_LENGTH from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.llm_config import LLMConfig -from pydantic import BaseModel, Field, model_validator class Provider(BaseModel): @@ -567,9 +565,7 @@ class AzureProvider(Provider): return values def list_llm_models(self) -> List[LLMConfig]: - from letta.llm_api.azure_openai import ( - azure_openai_get_chat_completion_model_list, - ) + from letta.llm_api.azure_openai import azure_openai_get_chat_completion_model_list model_options = azure_openai_get_chat_completion_model_list(self.base_url, api_key=self.api_key, api_version=self.api_version) configs = [] diff --git a/letta/schemas/agent.py b/letta/schemas/agent.py index 06fe5860..03d40350 100644 --- a/letta/schemas/agent.py +++ b/letta/schemas/agent.py @@ -1,6 +1,8 @@ from enum import Enum from typing import Dict, List, Optional +from pydantic import BaseModel, Field, field_validator + from letta.constants import DEFAULT_EMBEDDING_CHUNK_SIZE from letta.schemas.block import CreateBlock from letta.schemas.embedding_config import EmbeddingConfig @@ -13,7 +15,6 @@ from letta.schemas.source import Source from letta.schemas.tool import Tool from letta.schemas.tool_rule import ToolRule from letta.utils import create_random_username -from pydantic import BaseModel, Field, field_validator class AgentType(str, Enum): diff --git a/letta/schemas/block.py b/letta/schemas/block.py index bd905bd2..25e84b7d 100644 --- a/letta/schemas/block.py +++ b/letta/schemas/block.py @@ -1,9 +1,10 @@ from typing import Optional +from pydantic import BaseModel, Field, model_validator +from typing_extensions import Self + from letta.constants import CORE_MEMORY_BLOCK_CHAR_LIMIT from letta.schemas.letta_base import LettaBase -from pydantic import BaseModel, Field, model_validator -from typing_extensions import Self # block of the LLM context diff --git a/letta/schemas/file.py b/letta/schemas/file.py index 0671bc3e..b43eb64c 100644 --- a/letta/schemas/file.py +++ b/letta/schemas/file.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import Optional -from letta.schemas.letta_base import LettaBase from pydantic import Field +from letta.schemas.letta_base import LettaBase + class FileMetadataBase(LettaBase): """Base class for FileMetadata schemas""" diff --git a/letta/schemas/job.py b/letta/schemas/job.py index b767b567..17c2b98d 100644 --- a/letta/schemas/job.py +++ b/letta/schemas/job.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import Optional +from pydantic import Field + from letta.schemas.enums import JobStatus from letta.schemas.letta_base import OrmMetadataBase -from pydantic import Field class JobBase(OrmMetadataBase): diff --git a/letta/schemas/letta_request.py b/letta/schemas/letta_request.py index 73f956ff..123d817c 100644 --- a/letta/schemas/letta_request.py +++ b/letta/schemas/letta_request.py @@ -1,8 +1,9 @@ from typing import List +from pydantic import BaseModel, Field + from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG from letta.schemas.message import MessageCreate -from pydantic import BaseModel, Field class LettaRequest(BaseModel): diff --git a/letta/schemas/letta_response.py b/letta/schemas/letta_response.py index 7084c3ba..c6a1e8be 100644 --- a/letta/schemas/letta_response.py +++ b/letta/schemas/letta_response.py @@ -3,11 +3,12 @@ import json import re from typing import List, Union +from pydantic import BaseModel, Field + from letta.schemas.enums import MessageStreamStatus from letta.schemas.letta_message import LettaMessage, LettaMessageUnion from letta.schemas.usage import LettaUsageStatistics from letta.utils import json_dumps -from pydantic import BaseModel, Field # TODO: consider moving into own file diff --git a/letta/schemas/message.py b/letta/schemas/message.py index 9697b550..ea46f3f8 100644 --- a/letta/schemas/message.py +++ b/letta/schemas/message.py @@ -4,25 +4,17 @@ import warnings from datetime import datetime, timezone from typing import List, Literal, Optional -from letta.constants import ( - DEFAULT_MESSAGE_TOOL, - DEFAULT_MESSAGE_TOOL_KWARG, - TOOL_CALL_ID_MAX_LEN, -) +from pydantic import BaseModel, Field, field_validator + +from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG, TOOL_CALL_ID_MAX_LEN from letta.local_llm.constants import INNER_THOUGHTS_KWARG from letta.schemas.enums import MessageRole from letta.schemas.letta_base import OrmMetadataBase -from letta.schemas.letta_message import ( - AssistantMessage, - LettaMessage, - ReasoningMessage, - SystemMessage, -) +from letta.schemas.letta_message import AssistantMessage, LettaMessage, ReasoningMessage, SystemMessage from letta.schemas.letta_message import ToolCall as LettaToolCall from letta.schemas.letta_message import ToolCallMessage, ToolReturnMessage, UserMessage from letta.schemas.openai.chat_completions import ToolCall, ToolCallFunction from letta.utils import get_utc_time, is_utc_datetime, json_dumps -from pydantic import BaseModel, Field, field_validator def add_inner_thoughts_to_tool_call( diff --git a/letta/schemas/organization.py b/letta/schemas/organization.py index 6220b987..35784ad0 100644 --- a/letta/schemas/organization.py +++ b/letta/schemas/organization.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import Optional +from pydantic import Field + from letta.schemas.letta_base import LettaBase from letta.utils import create_random_username, get_utc_time -from pydantic import Field class OrganizationBase(LettaBase): diff --git a/letta/schemas/passage.py b/letta/schemas/passage.py index c613c2e1..c1ec13be 100644 --- a/letta/schemas/passage.py +++ b/letta/schemas/passage.py @@ -1,11 +1,12 @@ from datetime import datetime from typing import Dict, List, Optional +from pydantic import Field, field_validator + from letta.constants import MAX_EMBEDDING_DIM from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.letta_base import OrmMetadataBase from letta.utils import get_utc_time -from pydantic import Field, field_validator class PassageBase(OrmMetadataBase): diff --git a/letta/schemas/sandbox_config.py b/letta/schemas/sandbox_config.py index 993711cc..f86233fa 100644 --- a/letta/schemas/sandbox_config.py +++ b/letta/schemas/sandbox_config.py @@ -3,10 +3,11 @@ import json from enum import Enum from typing import Any, Dict, List, Literal, Optional, Union +from pydantic import BaseModel, Field, model_validator + from letta.schemas.agent import AgentState from letta.schemas.letta_base import LettaBase, OrmMetadataBase from letta.settings import tool_settings -from pydantic import BaseModel, Field, model_validator # Sandbox Config diff --git a/letta/schemas/source.py b/letta/schemas/source.py index d6a14d79..0a458dfd 100644 --- a/letta/schemas/source.py +++ b/letta/schemas/source.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import Optional +from pydantic import Field + from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.letta_base import LettaBase -from pydantic import Field class BaseSource(LettaBase): diff --git a/letta/schemas/tool.py b/letta/schemas/tool.py index cee04fef..8066f9b2 100644 --- a/letta/schemas/tool.py +++ b/letta/schemas/tool.py @@ -1,15 +1,13 @@ from typing import Dict, List, Optional +from pydantic import Field, model_validator + from letta.constants import FUNCTION_RETURN_CHAR_LIMIT from letta.functions.functions import derive_openai_json_schema -from letta.functions.helpers import ( - generate_composio_tool_wrapper, - generate_langchain_tool_wrapper, -) +from letta.functions.helpers import generate_composio_tool_wrapper, generate_langchain_tool_wrapper from letta.functions.schema_generator import generate_schema_from_args_schema_v2 from letta.schemas.letta_base import LettaBase from letta.schemas.openai.chat_completions import ToolCall -from pydantic import Field, model_validator class BaseTool(LettaBase): diff --git a/letta/schemas/tool_rule.py b/letta/schemas/tool_rule.py index e88ff290..1ab313a7 100644 --- a/letta/schemas/tool_rule.py +++ b/letta/schemas/tool_rule.py @@ -1,8 +1,9 @@ from typing import Any, Dict, List, Optional, Union +from pydantic import Field + from letta.schemas.enums import ToolRuleType from letta.schemas.letta_base import LettaBase -from pydantic import Field class BaseToolRule(LettaBase): diff --git a/letta/schemas/user.py b/letta/schemas/user.py index b2bcb933..59a4594e 100644 --- a/letta/schemas/user.py +++ b/letta/schemas/user.py @@ -1,9 +1,10 @@ from datetime import datetime from typing import Optional +from pydantic import Field + from letta.schemas.letta_base import LettaBase from letta.services.organization_manager import OrganizationManager -from pydantic import Field class UserBase(LettaBase): diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py index bb183935..8e2b7fb7 100644 --- a/letta/server/rest_api/app.py +++ b/letta/server/rest_api/app.py @@ -8,44 +8,30 @@ from typing import Optional import uvicorn from fastapi import FastAPI, Request from fastapi.responses import JSONResponse +from starlette.middleware.base import BaseHTTPMiddleware +from starlette.middleware.cors import CORSMiddleware + from letta.__init__ import __version__ from letta.constants import ADMIN_PREFIX, API_PREFIX, OPENAI_API_PREFIX from letta.errors import LettaAgentNotFoundError, LettaUserNotFoundError from letta.log import get_logger -from letta.orm.errors import ( - DatabaseTimeoutError, - ForeignKeyConstraintViolationError, - NoResultFound, - UniqueConstraintViolationError, -) +from letta.orm.errors import DatabaseTimeoutError, ForeignKeyConstraintViolationError, NoResultFound, UniqueConstraintViolationError from letta.schemas.letta_response import LettaResponse from letta.server.constants import REST_DEFAULT_PORT # NOTE(charles): these are extra routes that are not part of v1 but we still need to mount to pass tests -from letta.server.rest_api.auth.index import ( - setup_auth_router, # TODO: probably remove right? -) +from letta.server.rest_api.auth.index import setup_auth_router # TODO: probably remove right? from letta.server.rest_api.interface import StreamingServerInterface -from letta.server.rest_api.routers.openai.assistants.assistants import ( - router as openai_assistants_router, -) -from letta.server.rest_api.routers.openai.chat_completions.chat_completions import ( - router as openai_chat_completions_router, -) +from letta.server.rest_api.routers.openai.assistants.assistants import router as openai_assistants_router +from letta.server.rest_api.routers.openai.chat_completions.chat_completions import router as openai_chat_completions_router # from letta.orm.utilities import get_db_session # TODO(ethan) reenable once we merge ORM from letta.server.rest_api.routers.v1 import ROUTERS as v1_routes -from letta.server.rest_api.routers.v1.organizations import ( - router as organizations_router, -) -from letta.server.rest_api.routers.v1.users import ( - router as users_router, # TODO: decide on admin -) +from letta.server.rest_api.routers.v1.organizations import router as organizations_router +from letta.server.rest_api.routers.v1.users import router as users_router # TODO: decide on admin from letta.server.rest_api.static_files import mount_static_files from letta.server.server import SyncServer from letta.settings import settings -from starlette.middleware.base import BaseHTTPMiddleware -from starlette.middleware.cors import CORSMiddleware # TODO(ethan) # NOTE(charles): @ethan I had to add this to get the global as the bottom to work diff --git a/letta/server/rest_api/auth/index.py b/letta/server/rest_api/auth/index.py index 7a29f6b4..28d22435 100644 --- a/letta/server/rest_api/auth/index.py +++ b/letta/server/rest_api/auth/index.py @@ -2,10 +2,11 @@ from typing import Optional from uuid import UUID from fastapi import APIRouter +from pydantic import BaseModel, Field + from letta.log import get_logger from letta.server.rest_api.interface import QueuingInterface from letta.server.server import SyncServer -from pydantic import BaseModel, Field logger = get_logger(__name__) router = APIRouter() diff --git a/letta/server/rest_api/auth_token.py b/letta/server/rest_api/auth_token.py index 72387bbd..40e26d80 100644 --- a/letta/server/rest_api/auth_token.py +++ b/letta/server/rest_api/auth_token.py @@ -2,6 +2,7 @@ import uuid from fastapi import Depends, HTTPException from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer + from letta.server.server import SyncServer security = HTTPBearer() diff --git a/letta/server/rest_api/interface.py b/letta/server/rest_api/interface.py index ffc46edd..9fd8fb1c 100644 --- a/letta/server/rest_api/interface.py +++ b/letta/server/rest_api/interface.py @@ -11,23 +11,20 @@ from letta.interface import AgentInterface from letta.local_llm.constants import INNER_THOUGHTS_KWARG from letta.schemas.enums import MessageStreamStatus from letta.schemas.letta_message import ( - AssistantMessage, - LegacyFunctionCallMessage, - LegacyLettaMessage, - LettaMessage, - ReasoningMessage, - ToolCall, - ToolCallDelta, - ToolCallMessage, - ToolReturnMessage, + AssistantMessage, + LegacyFunctionCallMessage, + LegacyLettaMessage, + LettaMessage, + ReasoningMessage, + ToolCall, + ToolCallDelta, + ToolCallMessage, + ToolReturnMessage, ) from letta.schemas.message import Message from letta.schemas.openai.chat_completion_response import ChatCompletionChunkResponse from letta.streaming_interface import AgentChunkStreamingInterface -from letta.streaming_utils import ( - FunctionArgumentsStreamHandler, - JSONInnerThoughtsExtractor, -) +from letta.streaming_utils import FunctionArgumentsStreamHandler, JSONInnerThoughtsExtractor from letta.utils import is_utc_datetime diff --git a/letta/server/rest_api/routers/openai/assistants/assistants.py b/letta/server/rest_api/routers/openai/assistants/assistants.py index 95f8f01e..2b646f93 100644 --- a/letta/server/rest_api/routers/openai/assistants/assistants.py +++ b/letta/server/rest_api/routers/openai/assistants/assistants.py @@ -1,13 +1,14 @@ from typing import List from fastapi import APIRouter, Body, HTTPException, Path, Query + from letta.constants import DEFAULT_PRESET from letta.schemas.openai.openai import AssistantFile, OpenAIAssistant from letta.server.rest_api.routers.openai.assistants.schemas import ( - CreateAssistantFileRequest, - CreateAssistantRequest, - DeleteAssistantFileResponse, - DeleteAssistantResponse, + CreateAssistantFileRequest, + CreateAssistantRequest, + DeleteAssistantFileResponse, + DeleteAssistantResponse, ) from letta.utils import get_utc_time diff --git a/letta/server/rest_api/routers/openai/assistants/schemas.py b/letta/server/rest_api/routers/openai/assistants/schemas.py index 069a4d97..07263ff2 100644 --- a/letta/server/rest_api/routers/openai/assistants/schemas.py +++ b/letta/server/rest_api/routers/openai/assistants/schemas.py @@ -1,14 +1,9 @@ from typing import List, Optional -from letta.schemas.openai.openai import ( - MessageRoleType, - OpenAIMessage, - OpenAIThread, - ToolCall, - ToolCallOutput, -) from pydantic import BaseModel, Field +from letta.schemas.openai.openai import MessageRoleType, OpenAIMessage, OpenAIThread, ToolCall, ToolCallOutput + class CreateAssistantRequest(BaseModel): model: str = Field(..., description="The model to use for the assistant.") diff --git a/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py b/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py index 9127787f..4809fa19 100644 --- a/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py +++ b/letta/server/rest_api/routers/openai/chat_completions/chat_completions.py @@ -2,15 +2,11 @@ import json from typing import TYPE_CHECKING, Optional from fastapi import APIRouter, Body, Depends, Header, HTTPException + from letta.schemas.enums import MessageRole from letta.schemas.letta_message import LettaMessage, ToolCall from letta.schemas.openai.chat_completion_request import ChatCompletionRequest -from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - Message, - UsageStatistics, -) +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, Message, UsageStatistics # TODO this belongs in a controller! from letta.server.rest_api.routers.v1.agents import send_message_to_agent diff --git a/letta/server/rest_api/routers/v1/__init__.py b/letta/server/rest_api/routers/v1/__init__.py index bcebeb26..0617f4a9 100644 --- a/letta/server/rest_api/routers/v1/__init__.py +++ b/letta/server/rest_api/routers/v1/__init__.py @@ -3,9 +3,7 @@ from letta.server.rest_api.routers.v1.blocks import router as blocks_router from letta.server.rest_api.routers.v1.health import router as health_router from letta.server.rest_api.routers.v1.jobs import router as jobs_router from letta.server.rest_api.routers.v1.llms import router as llm_router -from letta.server.rest_api.routers.v1.sandbox_configs import ( - router as sandbox_configs_router, -) +from letta.server.rest_api.routers.v1.sandbox_configs import router as sandbox_configs_router from letta.server.rest_api.routers.v1.sources import router as sources_router from letta.server.rest_api.routers.v1.tools import router as tools_router diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.py index a1162653..6f78fbfa 100644 --- a/letta/server/rest_api/routers/v1/agents.py +++ b/letta/server/rest_api/routers/v1/agents.py @@ -3,42 +3,21 @@ import warnings from datetime import datetime from typing import List, Optional, Union -from fastapi import ( - APIRouter, - BackgroundTasks, - Body, - Depends, - Header, - HTTPException, - Query, - status, -) +from fastapi import APIRouter, BackgroundTasks, Body, Depends, Header, HTTPException, Query, status from fastapi.responses import JSONResponse, StreamingResponse +from pydantic import Field + from letta.constants import DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG from letta.log import get_logger from letta.orm.errors import NoResultFound from letta.schemas.agent import AgentState, CreateAgent, UpdateAgent -from letta.schemas.block import ( # , BlockLabelUpdate, BlockLimitUpdate - Block, - BlockUpdate, - CreateBlock, -) +from letta.schemas.block import Block, BlockUpdate, CreateBlock # , BlockLabelUpdate, BlockLimitUpdate from letta.schemas.enums import MessageStreamStatus from letta.schemas.job import Job, JobStatus, JobUpdate -from letta.schemas.letta_message import ( - LegacyLettaMessage, - LettaMessage, - LettaMessageUnion, -) +from letta.schemas.letta_message import LegacyLettaMessage, LettaMessage, LettaMessageUnion from letta.schemas.letta_request import LettaRequest, LettaStreamingRequest from letta.schemas.letta_response import LettaResponse -from letta.schemas.memory import ( - ArchivalMemorySummary, - ContextWindowOverview, - CreateArchivalMemory, - Memory, - RecallMemorySummary, -) +from letta.schemas.memory import ArchivalMemorySummary, ContextWindowOverview, CreateArchivalMemory, Memory, RecallMemorySummary from letta.schemas.message import Message, MessageCreate, MessageUpdate from letta.schemas.passage import Passage from letta.schemas.source import Source @@ -47,7 +26,6 @@ from letta.schemas.user import User from letta.server.rest_api.interface import StreamingServerInterface from letta.server.rest_api.utils import get_letta_server, sse_async_generator from letta.server.server import SyncServer -from pydantic import Field # These can be forward refs, but because Fastapi needs them at runtime the must be imported normally diff --git a/letta/server/rest_api/routers/v1/blocks.py b/letta/server/rest_api/routers/v1/blocks.py index 9d2a937d..d9213233 100644 --- a/letta/server/rest_api/routers/v1/blocks.py +++ b/letta/server/rest_api/routers/v1/blocks.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING, List, Optional from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response + from letta.orm.errors import NoResultFound from letta.schemas.block import Block, BlockUpdate, CreateBlock from letta.server.rest_api.utils import get_letta_server diff --git a/letta/server/rest_api/routers/v1/health.py b/letta/server/rest_api/routers/v1/health.py index 81bb41e0..99fce66d 100644 --- a/letta/server/rest_api/routers/v1/health.py +++ b/letta/server/rest_api/routers/v1/health.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING from fastapi import APIRouter + from letta.cli.cli import version from letta.schemas.health import Health diff --git a/letta/server/rest_api/routers/v1/jobs.py b/letta/server/rest_api/routers/v1/jobs.py index bec22625..4245d2f9 100644 --- a/letta/server/rest_api/routers/v1/jobs.py +++ b/letta/server/rest_api/routers/v1/jobs.py @@ -1,6 +1,7 @@ from typing import List, Optional from fastapi import APIRouter, Depends, Header, HTTPException, Query + from letta.orm.errors import NoResultFound from letta.schemas.enums import JobStatus from letta.schemas.job import Job diff --git a/letta/server/rest_api/routers/v1/llms.py b/letta/server/rest_api/routers/v1/llms.py index f0bf9f42..4536ae49 100644 --- a/letta/server/rest_api/routers/v1/llms.py +++ b/letta/server/rest_api/routers/v1/llms.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING, List from fastapi import APIRouter, Depends + from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.llm_config import LLMConfig from letta.server.rest_api.utils import get_letta_server diff --git a/letta/server/rest_api/routers/v1/organizations.py b/letta/server/rest_api/routers/v1/organizations.py index 8fbead6d..2f4cdb1b 100644 --- a/letta/server/rest_api/routers/v1/organizations.py +++ b/letta/server/rest_api/routers/v1/organizations.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING, List, Optional from fastapi import APIRouter, Body, Depends, HTTPException, Query + from letta.schemas.organization import Organization, OrganizationCreate from letta.server.rest_api.utils import get_letta_server diff --git a/letta/server/rest_api/routers/v1/sandbox_configs.py b/letta/server/rest_api/routers/v1/sandbox_configs.py index 822ca4f5..436d9b8e 100644 --- a/letta/server/rest_api/routers/v1/sandbox_configs.py +++ b/letta/server/rest_api/routers/v1/sandbox_configs.py @@ -1,14 +1,11 @@ from typing import List, Optional from fastapi import APIRouter, Depends, Query + from letta.schemas.sandbox_config import SandboxConfig as PydanticSandboxConfig from letta.schemas.sandbox_config import SandboxConfigCreate, SandboxConfigUpdate from letta.schemas.sandbox_config import SandboxEnvironmentVariable as PydanticEnvVar -from letta.schemas.sandbox_config import ( - SandboxEnvironmentVariableCreate, - SandboxEnvironmentVariableUpdate, - SandboxType, -) +from letta.schemas.sandbox_config import SandboxEnvironmentVariableCreate, SandboxEnvironmentVariableUpdate, SandboxType from letta.server.rest_api.utils import get_letta_server, get_user_id from letta.server.server import SyncServer diff --git a/letta/server/rest_api/routers/v1/sources.py b/letta/server/rest_api/routers/v1/sources.py index 399942da..59b933cf 100644 --- a/letta/server/rest_api/routers/v1/sources.py +++ b/letta/server/rest_api/routers/v1/sources.py @@ -2,15 +2,8 @@ import os import tempfile from typing import List, Optional -from fastapi import ( - APIRouter, - BackgroundTasks, - Depends, - Header, - HTTPException, - Query, - UploadFile, -) +from fastapi import APIRouter, BackgroundTasks, Depends, Header, HTTPException, Query, UploadFile + from letta.schemas.file import FileMetadata from letta.schemas.job import Job from letta.schemas.passage import Passage diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.py index bb297a36..ffc2b212 100644 --- a/letta/server/rest_api/routers/v1/tools.py +++ b/letta/server/rest_api/routers/v1/tools.py @@ -6,6 +6,7 @@ from composio.client.enums.base import EnumStringNotFound from composio.exceptions import ApiKeyNotProvidedError, ComposioSDKError from composio.tools.base.abs import InvalidClassDefinition from fastapi import APIRouter, Body, Depends, Header, HTTPException + from letta.errors import LettaToolCreateError from letta.orm.errors import UniqueConstraintViolationError from letta.schemas.letta_message import ToolReturnMessage diff --git a/letta/server/rest_api/routers/v1/users.py b/letta/server/rest_api/routers/v1/users.py index 2dfeb06b..27a2feeb 100644 --- a/letta/server/rest_api/routers/v1/users.py +++ b/letta/server/rest_api/routers/v1/users.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING, List, Optional from fastapi import APIRouter, Body, Depends, HTTPException, Query + from letta.schemas.user import User, UserCreate, UserUpdate from letta.server.rest_api.utils import get_letta_server diff --git a/letta/server/rest_api/utils.py b/letta/server/rest_api/utils.py index 650f0e3e..bb5dc034 100644 --- a/letta/server/rest_api/utils.py +++ b/letta/server/rest_api/utils.py @@ -6,11 +6,12 @@ from enum import Enum from typing import AsyncGenerator, Optional, Union from fastapi import Header +from pydantic import BaseModel + from letta.errors import ContextWindowExceededError, RateLimitExceededError from letta.schemas.usage import LettaUsageStatistics from letta.server.rest_api.interface import StreamingServerInterface from letta.server.server import SyncServer -from pydantic import BaseModel # from letta.orm.user import User # from letta.orm.utilities import get_db_session diff --git a/letta/server/server.py b/letta/server/server.py index 226d8d84..03604a89 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -7,12 +7,13 @@ from abc import abstractmethod from datetime import datetime from typing import Callable, List, Optional, Tuple, Union -import letta.constants as constants -import letta.server.utils as server_utils -import letta.system as system from composio.client import Composio from composio.client.collections import ActionModel, AppModel from fastapi import HTTPException + +import letta.constants as constants +import letta.server.utils as server_utils +import letta.system as system from letta.agent import Agent, save_agent from letta.chat_only_agent import ChatOnlyAgent from letta.credentials import LettaCredentials @@ -27,17 +28,17 @@ from letta.offline_memory_agent import OfflineMemoryAgent from letta.orm import Base from letta.orm.errors import NoResultFound from letta.providers import ( - AnthropicProvider, - AzureProvider, - GoogleAIProvider, - GroqProvider, - LettaProvider, - OllamaProvider, - OpenAIProvider, - Provider, - TogetherProvider, - VLLMChatCompletionsProvider, - VLLMCompletionsProvider, + AnthropicProvider, + AzureProvider, + GoogleAIProvider, + GroqProvider, + LettaProvider, + OllamaProvider, + OpenAIProvider, + Provider, + TogetherProvider, + VLLMChatCompletionsProvider, + VLLMCompletionsProvider, ) from letta.schemas.agent import AgentState, AgentType, CreateAgent from letta.schemas.block import BlockUpdate @@ -48,12 +49,7 @@ from letta.schemas.enums import JobStatus from letta.schemas.job import Job, JobUpdate from letta.schemas.letta_message import LettaMessage, ToolReturnMessage from letta.schemas.llm_config import LLMConfig -from letta.schemas.memory import ( - ArchivalMemorySummary, - ContextWindowOverview, - Memory, - RecallMemorySummary, -) +from letta.schemas.memory import ArchivalMemorySummary, ContextWindowOverview, Memory, RecallMemorySummary from letta.schemas.message import Message, MessageCreate, MessageRole, MessageUpdate from letta.schemas.organization import Organization from letta.schemas.passage import Passage @@ -138,16 +134,17 @@ class Server(object): from contextlib import contextmanager -from letta.config import LettaConfig - -# NOTE: hack to see if single session management works -from letta.settings import model_settings, settings, tool_settings from rich.console import Console from rich.panel import Panel from rich.text import Text from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker +from letta.config import LettaConfig + +# NOTE: hack to see if single session management works +from letta.settings import model_settings, settings, tool_settings + config = LettaConfig.load() diff --git a/letta/server/ws_api/example_client.py b/letta/server/ws_api/example_client.py index fdfdd660..a7fc57b5 100644 --- a/letta/server/ws_api/example_client.py +++ b/letta/server/ws_api/example_client.py @@ -1,7 +1,8 @@ import asyncio -import letta.server.ws_api.protocol as protocol import websockets + +import letta.server.ws_api.protocol as protocol from letta.server.constants import WS_CLIENT_TIMEOUT, WS_DEFAULT_PORT from letta.server.utils import condition_to_stop_receiving, print_server_response diff --git a/letta/server/ws_api/server.py b/letta/server/ws_api/server.py index b3dcc2ba..e2408dda 100644 --- a/letta/server/ws_api/server.py +++ b/letta/server/ws_api/server.py @@ -3,8 +3,9 @@ import signal import sys import traceback -import letta.server.ws_api.protocol as protocol import websockets + +import letta.server.ws_api.protocol as protocol from letta.server.constants import WS_DEFAULT_PORT from letta.server.server import SyncServer from letta.server.ws_api.interface import SyncWebSocketInterface diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py index 96973391..4e6b80ec 100644 --- a/letta/services/agent_manager.py +++ b/letta/services/agent_manager.py @@ -2,6 +2,8 @@ from datetime import datetime from typing import Dict, List, Optional import numpy as np +from sqlalchemy import Select, func, literal, select, union_all + from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS, MAX_EMBEDDING_DIM from letta.embeddings import embedding_model from letta.log import get_logger @@ -25,20 +27,19 @@ from letta.schemas.tool_rule import ToolRule as PydanticToolRule from letta.schemas.user import User as PydanticUser from letta.services.block_manager import BlockManager from letta.services.helpers.agent_manager_helper import ( - _process_relationship, - _process_tags, - check_supports_structured_output, - compile_system_message, - derive_system_message, - initialize_message_sequence, - package_initial_message_sequence, + _process_relationship, + _process_tags, + check_supports_structured_output, + compile_system_message, + derive_system_message, + initialize_message_sequence, + package_initial_message_sequence, ) from letta.services.message_manager import MessageManager from letta.services.source_manager import SourceManager from letta.services.tool_manager import ToolManager from letta.settings import settings from letta.utils import enforce_types, get_utc_time, united_diff -from sqlalchemy import Select, func, literal, select, union_all logger = get_logger(__name__) diff --git a/letta/services/sandbox_config_manager.py b/letta/services/sandbox_config_manager.py index 270b1761..9e47612e 100644 --- a/letta/services/sandbox_config_manager.py +++ b/letta/services/sandbox_config_manager.py @@ -9,11 +9,7 @@ from letta.schemas.sandbox_config import LocalSandboxConfig from letta.schemas.sandbox_config import SandboxConfig as PydanticSandboxConfig from letta.schemas.sandbox_config import SandboxConfigCreate, SandboxConfigUpdate from letta.schemas.sandbox_config import SandboxEnvironmentVariable as PydanticEnvVar -from letta.schemas.sandbox_config import ( - SandboxEnvironmentVariableCreate, - SandboxEnvironmentVariableUpdate, - SandboxType, -) +from letta.schemas.sandbox_config import SandboxEnvironmentVariableCreate, SandboxEnvironmentVariableUpdate, SandboxType from letta.schemas.user import User as PydanticUser from letta.utils import enforce_types, printd diff --git a/letta/settings.py b/letta/settings.py index 3b9af801..1b6ba44b 100644 --- a/letta/settings.py +++ b/letta/settings.py @@ -1,10 +1,11 @@ from pathlib import Path from typing import Optional -from letta.local_llm.constants import DEFAULT_WRAPPER_NAME from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict +from letta.local_llm.constants import DEFAULT_WRAPPER_NAME + class ToolSettings(BaseSettings): composio_api_key: Optional[str] = None diff --git a/letta/streaming_interface.py b/letta/streaming_interface.py index 9dfcfd46..2949b94e 100644 --- a/letta/streaming_interface.py +++ b/letta/streaming_interface.py @@ -3,22 +3,16 @@ from abc import ABC, abstractmethod from datetime import datetime from typing import List, Optional -from letta.interface import CLIInterface -from letta.local_llm.constants import ( - ASSISTANT_MESSAGE_CLI_SYMBOL, - INNER_THOUGHTS_CLI_SYMBOL, -) -from letta.schemas.message import Message -from letta.schemas.openai.chat_completion_response import ( - ChatCompletionChunkResponse, - ChatCompletionResponse, -) - # from colorama import Fore, Style, init from rich.console import Console from rich.live import Live from rich.markup import escape +from letta.interface import CLIInterface +from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL, INNER_THOUGHTS_CLI_SYMBOL +from letta.schemas.message import Message +from letta.schemas.openai.chat_completion_response import ChatCompletionChunkResponse, ChatCompletionResponse + # init(autoreset=True) # DEBUG = True # puts full message outputs in the terminal diff --git a/letta/system.py b/letta/system.py index 89755c31..d903bf1f 100644 --- a/letta/system.py +++ b/letta/system.py @@ -3,10 +3,10 @@ import uuid from typing import Optional from .constants import ( - INITIAL_BOOT_MESSAGE, - INITIAL_BOOT_MESSAGE_SEND_MESSAGE_FIRST_MSG, - INITIAL_BOOT_MESSAGE_SEND_MESSAGE_THOUGHT, - MESSAGE_SUMMARY_WARNING_STR, + INITIAL_BOOT_MESSAGE, + INITIAL_BOOT_MESSAGE_SEND_MESSAGE_FIRST_MSG, + INITIAL_BOOT_MESSAGE_SEND_MESSAGE_THOUGHT, + MESSAGE_SUMMARY_WARNING_STR, ) from .utils import get_local_time, json_dumps diff --git a/letta/utils.py b/letta/utils.py index 4e7771c9..5d2eb513 100644 --- a/letta/utils.py +++ b/letta/utils.py @@ -19,20 +19,21 @@ from typing import List, Union, _GenericAlias, get_args, get_origin, get_type_hi from urllib.parse import urljoin, urlparse import demjson3 as demjson -import letta import pytz import tiktoken +from pathvalidate import sanitize_filename as pathvalidate_sanitize_filename + +import letta from letta.constants import ( - CLI_WARNING_PREFIX, - CORE_MEMORY_HUMAN_CHAR_LIMIT, - CORE_MEMORY_PERSONA_CHAR_LIMIT, - ERROR_MESSAGE_PREFIX, - LETTA_DIR, - MAX_FILENAME_LENGTH, - TOOL_CALL_ID_MAX_LEN, + CLI_WARNING_PREFIX, + CORE_MEMORY_HUMAN_CHAR_LIMIT, + CORE_MEMORY_PERSONA_CHAR_LIMIT, + ERROR_MESSAGE_PREFIX, + LETTA_DIR, + MAX_FILENAME_LENGTH, + TOOL_CALL_ID_MAX_LEN, ) from letta.schemas.openai.chat_completion_response import ChatCompletionResponse -from pathvalidate import sanitize_filename as pathvalidate_sanitize_filename DEBUG = False if "LOG_LEVEL" in os.environ: diff --git a/locust_test.py b/locust_test.py index bf32fb48..570e6eef 100644 --- a/locust_test.py +++ b/locust_test.py @@ -1,6 +1,8 @@ import random import string +from locust import HttpUser, between, task + from letta.constants import BASE_TOOLS, DEFAULT_HUMAN, DEFAULT_PERSONA from letta.schemas.agent import AgentState, CreateAgent from letta.schemas.letta_request import LettaRequest @@ -8,7 +10,6 @@ from letta.schemas.letta_response import LettaResponse from letta.schemas.memory import ChatMemory from letta.schemas.message import MessageCreate, MessageRole from letta.utils import get_human_text, get_persona_text -from locust import HttpUser, between, task class LettaUser(HttpUser): diff --git a/paper_experiments/doc_qa_task/doc_qa.py b/paper_experiments/doc_qa_task/doc_qa.py index 205fa0d0..e07060d1 100644 --- a/paper_experiments/doc_qa_task/doc_qa.py +++ b/paper_experiments/doc_qa_task/doc_qa.py @@ -23,6 +23,9 @@ import uuid from typing import List from icml_experiments.utils import get_experiment_config, load_gzipped_file +from openai import OpenAI +from tqdm import tqdm + from letta import utils from letta.agent_store.storage import StorageConnector, TableType from letta.cli.cli_config import delete @@ -30,8 +33,6 @@ from letta.config import LettaConfig from letta.credentials import LettaCredentials from letta.embeddings import embedding_model from letta.utils import count_tokens -from openai import OpenAI -from tqdm import tqdm DATA_SOURCE_NAME = "wikipedia" DOC_QA_PERSONA = "You are Letta 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 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 18d907a3..c6ff6cfe 100644 --- a/paper_experiments/doc_qa_task/llm_judge_doc_qa.py +++ b/paper_experiments/doc_qa_task/llm_judge_doc_qa.py @@ -2,10 +2,11 @@ import argparse import json import re -from letta.credentials import LettaCredentials from openai import OpenAI from tqdm import tqdm +from letta.credentials import LettaCredentials + # Note: did not end up using since no cases of cheating were observed # CHEATING_PROMPT = \ # """ diff --git a/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py b/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py index e80e7e9b..94b98143 100644 --- a/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py +++ b/paper_experiments/doc_qa_task/load_wikipedia_embeddings.py @@ -8,10 +8,11 @@ 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 letta.agent_store.storage import StorageConnector, TableType from letta.cli.cli_config import delete from letta.data_types import Passage -from tqdm import tqdm # Create an empty list to store the JSON objects source_name = "wikipedia" diff --git a/paper_experiments/nested_kv_task/nested_kv.py b/paper_experiments/nested_kv_task/nested_kv.py index 64fa06a2..04c95ac5 100644 --- a/paper_experiments/nested_kv_task/nested_kv.py +++ b/paper_experiments/nested_kv_task/nested_kv.py @@ -29,10 +29,11 @@ from typing import Optional import openai from icml_experiments.utils import get_experiment_config, load_gzipped_file +from tqdm import tqdm + from letta import utils from letta.cli.cli_config import delete from letta.config import LettaConfig -from tqdm import tqdm # TODO: update personas NESTED_PERSONA = "You are Letta 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/pyproject.toml b/pyproject.toml index 0a8c7332..5aa60a0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,3 +100,11 @@ extend-exclude = "examples/*" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.isort] +profile = "black" +line_length = 140 +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true \ No newline at end of file diff --git a/scripts/migrate_tools.py b/scripts/migrate_tools.py index 91e16071..53578c69 100644 --- a/scripts/migrate_tools.py +++ b/scripts/migrate_tools.py @@ -1,7 +1,8 @@ +from tqdm import tqdm + from letta.schemas.user import User from letta.services.organization_manager import OrganizationManager from letta.services.tool_manager import ToolManager -from tqdm import tqdm def deprecated_tool(): diff --git a/tests/helpers/endpoints_helper.py b/tests/helpers/endpoints_helper.py index 4ed80146..82b2ed1c 100644 --- a/tests/helpers/endpoints_helper.py +++ b/tests/helpers/endpoints_helper.py @@ -14,12 +14,7 @@ from letta.agent import Agent from letta.config import LettaConfig from letta.constants import DEFAULT_HUMAN, DEFAULT_PERSONA from letta.embeddings import embedding_model -from letta.errors import ( - InvalidInnerMonologueError, - InvalidToolCallError, - MissingInnerMonologueError, - MissingToolCallError, -) +from letta.errors import InvalidInnerMonologueError, InvalidToolCallError, MissingInnerMonologueError, MissingToolCallError from letta.llm_api.llm_api_tools import create from letta.local_llm.constants import INNER_THOUGHTS_KWARG from letta.schemas.agent import AgentState @@ -28,12 +23,7 @@ from letta.schemas.letta_message import LettaMessage, ReasoningMessage, ToolCall from letta.schemas.letta_response import LettaResponse from letta.schemas.llm_config import LLMConfig from letta.schemas.memory import ChatMemory -from letta.schemas.openai.chat_completion_response import ( - ChatCompletionResponse, - Choice, - FunctionCall, - Message, -) +from letta.schemas.openai.chat_completion_response import ChatCompletionResponse, Choice, FunctionCall, Message from letta.utils import get_human_text, get_persona_text, json_dumps from tests.helpers.utils import cleanup diff --git a/tests/integration_test_agent_tool_graph.py b/tests/integration_test_agent_tool_graph.py index 4144c347..64486ad3 100644 --- a/tests/integration_test_agent_tool_graph.py +++ b/tests/integration_test_agent_tool_graph.py @@ -2,19 +2,15 @@ import time import uuid import pytest + from letta import create_client from letta.schemas.letta_message import ToolCallMessage -from letta.schemas.tool_rule import ( - ChildToolRule, - ConditionalToolRule, - InitToolRule, - TerminalToolRule, -) +from letta.schemas.tool_rule import ChildToolRule, ConditionalToolRule, InitToolRule, TerminalToolRule from tests.helpers.endpoints_helper import ( - assert_invoked_function_call, - assert_invoked_send_message_with_keyword, - assert_sanity_checks, - setup_agent, + assert_invoked_function_call, + assert_invoked_send_message_with_keyword, + assert_sanity_checks, + setup_agent, ) from tests.helpers.utils import cleanup diff --git a/tests/integration_test_offline_memory_agent.py b/tests/integration_test_offline_memory_agent.py index 01b04693..15d4161d 100644 --- a/tests/integration_test_offline_memory_agent.py +++ b/tests/integration_test_offline_memory_agent.py @@ -1,13 +1,14 @@ import pytest + from letta import BasicBlockMemory from letta.client.client import Block, create_client from letta.constants import DEFAULT_HUMAN, DEFAULT_PERSONA from letta.offline_memory_agent import ( - finish_rethinking_memory, - finish_rethinking_memory_convo, - rethink_memory, - rethink_memory_convo, - trigger_rethink_memory, + finish_rethinking_memory, + finish_rethinking_memory_convo, + rethink_memory, + rethink_memory_convo, + trigger_rethink_memory, ) from letta.prompts import gpt_system from letta.schemas.agent import AgentType diff --git a/tests/integration_test_summarizer.py b/tests/integration_test_summarizer.py index ce6c41b2..b4de0043 100644 --- a/tests/integration_test_summarizer.py +++ b/tests/integration_test_summarizer.py @@ -4,6 +4,7 @@ import uuid from typing import List import pytest + from letta import create_client from letta.agent import Agent from letta.client.client import LocalClient diff --git a/tests/integration_test_tool_execution_sandbox.py b/tests/integration_test_tool_execution_sandbox.py index 699185c9..97346021 100644 --- a/tests/integration_test_tool_execution_sandbox.py +++ b/tests/integration_test_tool_execution_sandbox.py @@ -5,6 +5,8 @@ from pathlib import Path from unittest.mock import patch import pytest +from sqlalchemy import delete + from letta import create_client from letta.functions.function_sets.base import core_memory_append, core_memory_replace from letta.orm import SandboxConfig, SandboxEnvironmentVariable @@ -14,12 +16,12 @@ from letta.schemas.llm_config import LLMConfig from letta.schemas.memory import ChatMemory from letta.schemas.organization import Organization from letta.schemas.sandbox_config import ( - E2BSandboxConfig, - LocalSandboxConfig, - SandboxConfigCreate, - SandboxConfigUpdate, - SandboxEnvironmentVariableCreate, - SandboxType, + E2BSandboxConfig, + LocalSandboxConfig, + SandboxConfigCreate, + SandboxConfigUpdate, + SandboxEnvironmentVariableCreate, + SandboxType, ) from letta.schemas.tool import Tool, ToolCreate from letta.schemas.user import User @@ -29,7 +31,6 @@ from letta.services.tool_execution_sandbox import ToolExecutionSandbox from letta.services.tool_manager import ToolManager from letta.services.user_manager import UserManager from letta.settings import tool_settings -from sqlalchemy import delete from tests.helpers.utils import create_tool_from_func # Constants @@ -211,9 +212,7 @@ def clear_core_memory_tool(test_user): @pytest.fixture def external_codebase_tool(test_user): - from tests.test_tool_sandbox.restaurant_management_system.adjust_menu_prices import ( - adjust_menu_prices, - ) + from tests.test_tool_sandbox.restaurant_management_system.adjust_menu_prices import adjust_menu_prices tool = create_tool_from_func(adjust_menu_prices) tool = ToolManager().create_or_update_tool(tool, test_user) diff --git a/tests/test_base_functions.py b/tests/test_base_functions.py index 007d2bf9..5b5bec6f 100644 --- a/tests/test_base_functions.py +++ b/tests/test_base_functions.py @@ -1,5 +1,6 @@ -import letta.functions.function_sets.base as base_functions import pytest + +import letta.functions.function_sets.base as base_functions from letta import LocalClient, create_client from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.llm_config import LLMConfig diff --git a/tests/test_cli.py b/tests/test_cli.py index c5595a00..c6497f50 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,10 +4,8 @@ import sys import pexpect import pytest -from letta.local_llm.constants import ( - ASSISTANT_MESSAGE_CLI_SYMBOL, - INNER_THOUGHTS_CLI_SYMBOL, -) + +from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL, INNER_THOUGHTS_CLI_SYMBOL original_letta_path = os.path.expanduser("~/.letta") backup_letta_path = os.path.expanduser("~/.letta_backup") diff --git a/tests/test_client.py b/tests/test_client.py index 71f7216c..cc391235 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -8,6 +8,8 @@ from typing import List, Union import pytest from dotenv import load_dotenv +from sqlalchemy import delete + from letta import LocalClient, RESTClient, create_client from letta.orm import SandboxConfig, SandboxEnvironmentVariable from letta.schemas.agent import AgentState @@ -18,7 +20,6 @@ from letta.schemas.letta_message import ToolReturnMessage from letta.schemas.llm_config import LLMConfig from letta.schemas.sandbox_config import LocalSandboxConfig, SandboxType from letta.utils import create_random_username -from sqlalchemy import delete # Constants SERVER_PORT = 8283 diff --git a/tests/test_client_legacy.py b/tests/test_client_legacy.py index b578d847..3d907fa3 100644 --- a/tests/test_client_legacy.py +++ b/tests/test_client_legacy.py @@ -7,6 +7,8 @@ from typing import List, Union import pytest from dotenv import load_dotenv +from sqlalchemy import delete + from letta import create_client from letta.client.client import LocalClient, RESTClient from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS, DEFAULT_PRESET @@ -15,13 +17,13 @@ from letta.schemas.agent import AgentState from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.enums import MessageRole, MessageStreamStatus from letta.schemas.letta_message import ( - AssistantMessage, - LettaMessage, - ReasoningMessage, - SystemMessage, - ToolCallMessage, - ToolReturnMessage, - UserMessage, + AssistantMessage, + LettaMessage, + ReasoningMessage, + SystemMessage, + ToolCallMessage, + ToolReturnMessage, + UserMessage, ) from letta.schemas.letta_response import LettaResponse, LettaStreamingResponse from letta.schemas.llm_config import LLMConfig @@ -32,7 +34,6 @@ from letta.services.organization_manager import OrganizationManager from letta.services.user_manager import UserManager from letta.settings import model_settings from letta.utils import get_utc_time -from sqlalchemy import delete from tests.helpers.client_helper import upload_file_using_client # from tests.utils import create_config diff --git a/tests/test_local_client.py b/tests/test_local_client.py index 8b0c7617..da5e533c 100644 --- a/tests/test_local_client.py +++ b/tests/test_local_client.py @@ -1,6 +1,7 @@ import uuid import pytest + from letta import create_client from letta.client.client import LocalClient from letta.schemas.agent import AgentState diff --git a/tests/test_managers.py b/tests/test_managers.py index 052a1819..388d477c 100644 --- a/tests/test_managers.py +++ b/tests/test_managers.py @@ -3,27 +3,30 @@ import time from datetime import datetime, timedelta import pytest +from sqlalchemy import delete +from sqlalchemy.exc import IntegrityError + from letta.config import LettaConfig from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS from letta.embeddings import embedding_model from letta.functions.functions import derive_openai_json_schema, parse_source_code from letta.orm import ( - Agent, - AgentPassage, - Block, - BlocksAgents, - FileMetadata, - Job, - Message, - Organization, - SandboxConfig, - SandboxEnvironmentVariable, - Source, - SourcePassage, - SourcesAgents, - Tool, - ToolsAgents, - User, + Agent, + AgentPassage, + Block, + BlocksAgents, + FileMetadata, + Job, + Message, + Organization, + SandboxConfig, + SandboxEnvironmentVariable, + Source, + SourcePassage, + SourcesAgents, + Tool, + ToolsAgents, + User, ) from letta.orm.agents_tags import AgentsTags from letta.orm.errors import NoResultFound, UniqueConstraintViolationError @@ -41,13 +44,13 @@ from letta.schemas.message import MessageCreate, MessageUpdate from letta.schemas.organization import Organization as PydanticOrganization from letta.schemas.passage import Passage as PydanticPassage from letta.schemas.sandbox_config import ( - E2BSandboxConfig, - LocalSandboxConfig, - SandboxConfigCreate, - SandboxConfigUpdate, - SandboxEnvironmentVariableCreate, - SandboxEnvironmentVariableUpdate, - SandboxType, + E2BSandboxConfig, + LocalSandboxConfig, + SandboxConfigCreate, + SandboxConfigUpdate, + SandboxEnvironmentVariableCreate, + SandboxEnvironmentVariableUpdate, + SandboxType, ) from letta.schemas.source import Source as PydanticSource from letta.schemas.source import SourceUpdate @@ -60,8 +63,6 @@ from letta.server.server import SyncServer from letta.services.block_manager import BlockManager from letta.services.organization_manager import OrganizationManager from letta.settings import tool_settings -from sqlalchemy import delete -from sqlalchemy.exc import IntegrityError from tests.helpers.utils import comprehensive_agent_checks DEFAULT_EMBEDDING_CONFIG = EmbeddingConfig( diff --git a/tests/test_model_letta_perfomance.py b/tests/test_model_letta_perfomance.py index 59bc90af..d45654ea 100644 --- a/tests/test_model_letta_perfomance.py +++ b/tests/test_model_letta_perfomance.py @@ -3,15 +3,15 @@ import os import time from tests.helpers.endpoints_helper import ( - check_agent_archival_memory_insert, - check_agent_archival_memory_retrieval, - check_agent_edit_core_memory, - check_agent_recall_chat_memory, - check_agent_summarize_memory_simple, - check_agent_uses_external_tool, - check_first_response_is_valid_for_llm_endpoint, - check_response_contains_keyword, - run_embedding_endpoint, + check_agent_archival_memory_insert, + check_agent_archival_memory_retrieval, + check_agent_edit_core_memory, + check_agent_recall_chat_memory, + check_agent_summarize_memory_simple, + check_agent_uses_external_tool, + check_first_response_is_valid_for_llm_endpoint, + check_response_contains_keyword, + run_embedding_endpoint, ) # directories diff --git a/tests/test_providers.py b/tests/test_providers.py index 8e4ea5cc..228e3352 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -1,14 +1,14 @@ import os from letta.providers import ( - AnthropicProvider, - AzureProvider, - GoogleAIProvider, - GroqProvider, - MistralProvider, - OllamaProvider, - OpenAIProvider, - TogetherProvider, + AnthropicProvider, + AzureProvider, + GoogleAIProvider, + GroqProvider, + MistralProvider, + OllamaProvider, + OpenAIProvider, + TogetherProvider, ) from letta.settings import model_settings diff --git a/tests/test_server.py b/tests/test_server.py index e0d51ffc..2f205a7e 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -3,19 +3,13 @@ import uuid import warnings from typing import List, Tuple -import letta.utils as utils import pytest + +import letta.utils as utils from letta.constants import BASE_MEMORY_TOOLS, BASE_TOOLS from letta.schemas.block import CreateBlock from letta.schemas.enums import MessageRole -from letta.schemas.letta_message import ( - LettaMessage, - ReasoningMessage, - SystemMessage, - ToolCallMessage, - ToolReturnMessage, - UserMessage, -) +from letta.schemas.letta_message import LettaMessage, ReasoningMessage, SystemMessage, ToolCallMessage, ToolReturnMessage, UserMessage from letta.schemas.user import User utils.DEBUG = True diff --git a/tests/test_stream_buffer_readers.py b/tests/test_stream_buffer_readers.py index 92335cc7..9a0bb5e8 100644 --- a/tests/test_stream_buffer_readers.py +++ b/tests/test_stream_buffer_readers.py @@ -1,6 +1,7 @@ import json import pytest + from letta.streaming_utils import JSONInnerThoughtsExtractor diff --git a/tests/test_tool_rule_solver.py b/tests/test_tool_rule_solver.py index 8a9e9353..dcb66e1b 100644 --- a/tests/test_tool_rule_solver.py +++ b/tests/test_tool_rule_solver.py @@ -1,12 +1,8 @@ import pytest + from letta.helpers import ToolRulesSolver from letta.helpers.tool_rule_solver import ToolRuleValidationError -from letta.schemas.tool_rule import ( - ChildToolRule, - ConditionalToolRule, - InitToolRule, - TerminalToolRule, -) +from letta.schemas.tool_rule import ChildToolRule, ConditionalToolRule, InitToolRule, TerminalToolRule # Constants for tool names used in the tests START_TOOL = "start_tool" diff --git a/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py b/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py index 1e5c090e..57adc163 100644 --- a/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py +++ b/tests/test_tool_sandbox/restaurant_management_system/adjust_menu_prices.py @@ -8,6 +8,7 @@ def adjust_menu_prices(percentage: float) -> str: str: A formatted string summarizing the price adjustments. """ import cowsay + from core.menu import Menu, MenuItem # Import a class from the codebase from core.utils import format_currency # Use a utility function to test imports diff --git a/tests/test_tool_schema_parsing.py b/tests/test_tool_schema_parsing.py index 6eed18f1..f6738a06 100644 --- a/tests/test_tool_schema_parsing.py +++ b/tests/test_tool_schema_parsing.py @@ -2,6 +2,7 @@ import json import os import pytest + from letta.functions.functions import derive_openai_json_schema from letta.llm_api.helpers import convert_to_structured_output, make_post_request diff --git a/tests/test_utils.py b/tests/test_utils.py index f8fd42dd..904e903e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ import pytest + from letta.constants import MAX_FILENAME_LENGTH from letta.utils import sanitize_filename diff --git a/tests/test_v1_routes.py b/tests/test_v1_routes.py index 6877031c..5093fe93 100644 --- a/tests/test_v1_routes.py +++ b/tests/test_v1_routes.py @@ -1,13 +1,9 @@ from unittest.mock import MagicMock, Mock, patch import pytest -from composio.client.collections import ( - ActionModel, - ActionParametersModel, - ActionResponseModel, - AppModel, -) +from composio.client.collections import ActionModel, ActionParametersModel, ActionResponseModel, AppModel from fastapi.testclient import TestClient + from letta.schemas.tool import ToolCreate, ToolUpdate from letta.server.rest_api.app import app from letta.server.rest_api.utils import get_letta_server diff --git a/tests/test_vector_embeddings.py b/tests/test_vector_embeddings.py index 8640f628..e65e6b9b 100644 --- a/tests/test_vector_embeddings.py +++ b/tests/test_vector_embeddings.py @@ -1,4 +1,5 @@ import numpy as np + from letta.orm.sqlalchemy_base import adapt_array from letta.orm.sqlite_functions import convert_array, verify_embedding_dimension diff --git a/tests/utils.py b/tests/utils.py index 3ce1cb62..19a05a09 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,6 +5,7 @@ from importlib import util from typing import Dict, Iterator, List, Tuple import requests + from letta.config import LettaConfig from letta.data_sources.connectors import DataConnector from letta.schemas.file import FileMetadata