Skip to content

Commit

Permalink
fixes from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alekst23 committed Sep 6, 2024
1 parent 8bbdf1a commit 39749c2
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/leapfrogai_api/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/leapfrogai_api/data/crud_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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],
)


Expand Down
6 changes: 3 additions & 3 deletions src/leapfrogai_api/routers/openai/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/leapfrogai_api/typedef/auth/auth_types.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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],
)


Expand All @@ -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],
)
2 changes: 1 addition & 1 deletion src/leapfrogai_api/typedef/chat/chat_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/leapfrogai_api/typedef/common.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/leapfrogai_api/typedef/completion/completion_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/leapfrogai_api/typedef/runs/run_create_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/test_conformance_runs.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down

0 comments on commit 39749c2

Please sign in to comment.