diff --git a/src/leapfrogai_api/backend/__init__.py b/src/leapfrogai_api/backend/__init__.py index e69de29bb..ca18ccd8d 100644 --- a/src/leapfrogai_api/backend/__init__.py +++ b/src/leapfrogai_api/backend/__init__.py @@ -0,0 +1,5 @@ +from .constants import ( + THIRTY_DAYS_SECONDS as THIRTY_DAYS_SECONDS, + DEFAULT_MAX_COMPLETION_TOKENS as DEFAULT_MAX_COMPLETION_TOKENS, + DEFAULT_MAX_PROMPT_TOKENS as DEFAULT_MAX_PROMPT_TOKENS, +) diff --git a/src/leapfrogai_api/backend/thread_runner.py b/src/leapfrogai_api/backend/composer.py similarity index 99% rename from src/leapfrogai_api/backend/thread_runner.py rename to src/leapfrogai_api/backend/composer.py index 850ba001b..c1cc31e56 100644 --- a/src/leapfrogai_api/backend/thread_runner.py +++ b/src/leapfrogai_api/backend/composer.py @@ -53,7 +53,7 @@ from leapfrogai_api.typedef.vectorstores import SearchResponse -class ThreadRunner(BaseModel): +class Composer(BaseModel): @staticmethod async def list_messages(thread_id: str, session: Session) -> list[Message]: """List all the messages in a thread.""" diff --git a/src/leapfrogai_api/typedef/constants.py b/src/leapfrogai_api/backend/constants.py similarity index 76% rename from src/leapfrogai_api/typedef/constants.py rename to src/leapfrogai_api/backend/constants.py index 6a6340152..3a647df54 100644 --- a/src/leapfrogai_api/typedef/constants.py +++ b/src/leapfrogai_api/backend/constants.py @@ -1,6 +1,6 @@ # This file defines application constants not set by environment variables or configuration files. -THIRTY_DAYS = 60 * 60 * 24 * 30 # in seconds +THIRTY_DAYS_SECONDS = 60 * 60 * 24 * 30 # in seconds DEFAULT_MAX_COMPLETION_TOKENS = 4096 DEFAULT_MAX_PROMPT_TOKENS = 4096 diff --git a/src/leapfrogai_api/data/crud_api_key.py b/src/leapfrogai_api/data/crud_api_key.py index a460e8553..5a9840e41 100644 --- a/src/leapfrogai_api/data/crud_api_key.py +++ b/src/leapfrogai_api/data/crud_api_key.py @@ -7,7 +7,7 @@ from leapfrogai_api.data.crud_base import CRUDBase from leapfrogai_api.backend.security.api_key import APIKey, KEY_PREFIX -from leapfrogai_api.typedef.constants import THIRTY_DAYS +from leapfrogai_api.backend.constants import THIRTY_DAYS_SECONDS class APIKeyItem(BaseModel): @@ -31,7 +31,7 @@ class APIKeyItem(BaseModel): ) expires_at: int = Field( description="The time at which the API key expires, in seconds since the Unix epoch.", - examples=[int(time.time()) + THIRTY_DAYS], + examples=[int(time.time()) + THIRTY_DAYS_SECONDS], ) diff --git a/src/leapfrogai_api/routers/openai/runs.py b/src/leapfrogai_api/routers/openai/runs.py index 20baf5b97..c52ee7bc9 100644 --- a/src/leapfrogai_api/routers/openai/runs.py +++ b/src/leapfrogai_api/routers/openai/runs.py @@ -15,7 +15,7 @@ ) from leapfrogai_api.typedef.threads import ThreadRunCreateParamsRequest from leapfrogai_api.typedef.runs import RunCreateParamsRequest, ModifyRunRequest -from leapfrogai_api.backend.thread_runner import ThreadRunner +from leapfrogai_api.backend.composer import Composer router = APIRouter(prefix="/openai/v1/threads", tags=["openai/threads/runs"]) @@ -55,7 +55,7 @@ async def create_run( ) try: - return await ThreadRunner().generate_response( + return await Composer().generate_response( request=request, existing_thread=existing_thread, new_run=new_run, @@ -84,7 +84,7 @@ async def create_thread_and_run( ) try: - return await ThreadRunner().generate_response( + return await Composer().generate_response( request=request, exising_thread=new_thread, new_run=new_run, session=session ) except Exception as exc: diff --git a/src/leapfrogai_api/typedef/auth/auth_types.py b/src/leapfrogai_api/typedef/auth/auth_types.py index f3f335867..f49dd5bac 100644 --- a/src/leapfrogai_api/typedef/auth/auth_types.py +++ b/src/leapfrogai_api/typedef/auth/auth_types.py @@ -1,7 +1,7 @@ from pydantic import BaseModel, Field import time -from leapfrogai_api.typedef.constants import THIRTY_DAYS +from leapfrogai_api.backend.constants import THIRTY_DAYS_SECONDS class CreateAPIKeyRequest(BaseModel): @@ -14,9 +14,9 @@ class CreateAPIKeyRequest(BaseModel): ) expires_at: int = Field( - default=int(time.time()) + THIRTY_DAYS, + default=int(time.time()) + THIRTY_DAYS_SECONDS, description="The time at which the API key expires, in seconds since the Unix epoch.", - examples=[int(time.time()) + THIRTY_DAYS], + examples=[int(time.time()) + THIRTY_DAYS_SECONDS], ) @@ -32,5 +32,5 @@ class ModifyAPIKeyRequest(BaseModel): expires_at: int | None = Field( default=None, description="The time at which the API key expires, in seconds since the Unix epoch. If not provided, the expiration time will not be changed.", - examples=[int(time.time()) + THIRTY_DAYS], + examples=[int(time.time()) + THIRTY_DAYS_SECONDS], ) diff --git a/src/leapfrogai_api/typedef/chat/chat_types.py b/src/leapfrogai_api/typedef/chat/chat_types.py index c851681ad..9f8e7028d 100644 --- a/src/leapfrogai_api/typedef/chat/chat_types.py +++ b/src/leapfrogai_api/typedef/chat/chat_types.py @@ -3,7 +3,7 @@ from openai.types.beta.threads.text_content_block_param import TextContentBlockParam from ..common import Usage -from ..constants import DEFAULT_MAX_COMPLETION_TOKENS +from ...backend.constants import DEFAULT_MAX_COMPLETION_TOKENS class ChatFunction(BaseModel): diff --git a/src/leapfrogai_api/typedef/common.py b/src/leapfrogai_api/typedef/common.py index d050636c1..879dc0855 100644 --- a/src/leapfrogai_api/typedef/common.py +++ b/src/leapfrogai_api/typedef/common.py @@ -1,5 +1,5 @@ from pydantic import BaseModel, Field -from leapfrogai_api.typedef.constants import DEFAULT_MAX_COMPLETION_TOKENS +from leapfrogai_api.backend.constants import DEFAULT_MAX_COMPLETION_TOKENS class Usage(BaseModel): diff --git a/src/leapfrogai_api/typedef/completion/completion_types.py b/src/leapfrogai_api/typedef/completion/completion_types.py index 810920a60..2e406db6a 100644 --- a/src/leapfrogai_api/typedef/completion/completion_types.py +++ b/src/leapfrogai_api/typedef/completion/completion_types.py @@ -2,7 +2,7 @@ from typing import Literal from ..common import Usage -from ..constants import DEFAULT_MAX_COMPLETION_TOKENS +from ...backend.constants import DEFAULT_MAX_COMPLETION_TOKENS class CompletionChoice(BaseModel): diff --git a/src/leapfrogai_api/typedef/runs/run_create_base.py b/src/leapfrogai_api/typedef/runs/run_create_base.py index e593c8024..cd83fda65 100644 --- a/src/leapfrogai_api/typedef/runs/run_create_base.py +++ b/src/leapfrogai_api/typedef/runs/run_create_base.py @@ -22,7 +22,7 @@ from openai.types.beta.threads.run_create_params import TruncationStrategy from pydantic import BaseModel, Field, ValidationError -from leapfrogai_api.typedef.constants import ( +from leapfrogai_api.backend.constants import ( DEFAULT_MAX_COMPLETION_TOKENS, DEFAULT_MAX_PROMPT_TOKENS, ) diff --git a/tests/conformance/test_conformance_runs.py b/tests/conformance/test_conformance_runs.py index 7a4447bfc..18b79b6b1 100644 --- a/tests/conformance/test_conformance_runs.py +++ b/tests/conformance/test_conformance_runs.py @@ -1,7 +1,7 @@ import pytest from openai.types.beta.threads import Run, Message, TextContentBlock, Text -from .utils import client_config_factory +from ..utils.client import client_config_factory def make_mock_message_object(role, message_text): diff --git a/tests/integration/api/test_auth.py b/tests/integration/api/test_auth.py index 834dc8756..ec4aca178 100644 --- a/tests/integration/api/test_auth.py +++ b/tests/integration/api/test_auth.py @@ -5,7 +5,11 @@ import pytest from fastapi import status, HTTPException from fastapi.testclient import TestClient -from leapfrogai_api.routers.leapfrogai.auth import router, THIRTY_DAYS, APIKeyItem +from leapfrogai_api.routers.leapfrogai.auth import ( + router, + THIRTY_DAYS_SECONDS, + APIKeyItem, +) from leapfrogai_api.backend.security.api_key import APIKey @@ -32,7 +36,7 @@ def create_api_key(): request = { "name": "API Keys Are Cool!", - "expires_at": int(time.time()) + THIRTY_DAYS, + "expires_at": int(time.time()) + THIRTY_DAYS_SECONDS, } response = client.post("/leapfrogai/v1/auth/api-keys", json=request)