From 9691485493dffa9e432a8c32e26a63fab05e3eff Mon Sep 17 00:00:00 2001 From: Leon Lam Nilsson Date: Fri, 19 Apr 2024 14:43:38 +0200 Subject: [PATCH 1/2] add endpoint for getting all models returns a list of the id and name of the current llm models, endpoint is currently in the app, not in its own router --- apps/api/src/__init__.py | 7 ++++++- apps/api/src/interfaces/db.py | 7 +++++++ apps/api/src/models/__init__.py | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/api/src/__init__.py b/apps/api/src/__init__.py index 83122438..4ea3aa55 100644 --- a/apps/api/src/__init__.py +++ b/apps/api/src/__init__.py @@ -18,7 +18,7 @@ ) from .improver import PromptType, improve_prompt from .interfaces import db -from .models import Profile +from .models import Profile, LLMModel from .routers import agents, api_key_types, api_keys from .routers import auth as auth_router from .routers import ( @@ -114,3 +114,8 @@ def auto_build_crew(general_task: str) -> str: @app.get("/me") def get_profile_from_header(current_user=Depends(get_current_user)) -> Profile: return current_user + + +@app.get("/models") +def get_models() -> list[LLMModel]: + return db.get_models() \ No newline at end of file diff --git a/apps/api/src/interfaces/db.py b/apps/api/src/interfaces/db.py index 3d69629d..5fe90601 100644 --- a/apps/api/src/interfaces/db.py +++ b/apps/api/src/interfaces/db.py @@ -43,6 +43,7 @@ Tool, ToolInsertRequest, ToolUpdateRequest, + LLMModel ) from src.models.tiers import TierGetRequest @@ -869,6 +870,12 @@ def delete_profile(profile_id: UUID) -> Profile: return Profile(**response.data[0]) +def get_models(): + supabase: Client = create_client(url, key) + response = supabase.table("models").select("*").execute() + return [LLMModel(**data) for data in response.data] + + if __name__ == "__main__": from src.models import Session diff --git a/apps/api/src/models/__init__.py b/apps/api/src/models/__init__.py index d41a62d4..58c97cf7 100644 --- a/apps/api/src/models/__init__.py +++ b/apps/api/src/models/__init__.py @@ -4,6 +4,7 @@ AgentGetRequest, AgentInsertRequest, AgentUpdateModel, + LLMModel, ) from .api_key import ( APIKey, @@ -108,4 +109,5 @@ "BillingInsertRequest", "BillingUpdateRequest", "ValidCrew", + "LLMModel", ] From 68e343dcd90207ed7eb98f6d596cabe2704155f6 Mon Sep 17 00:00:00 2001 From: Leon Lam Nilsson Date: Fri, 19 Apr 2024 14:46:16 +0200 Subject: [PATCH 2/2] add return type to db function --- apps/api/src/interfaces/db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/interfaces/db.py b/apps/api/src/interfaces/db.py index 5fe90601..4f688b0e 100644 --- a/apps/api/src/interfaces/db.py +++ b/apps/api/src/interfaces/db.py @@ -870,7 +870,7 @@ def delete_profile(profile_id: UUID) -> Profile: return Profile(**response.data[0]) -def get_models(): +def get_models() -> list[LLMModel]: supabase: Client = create_client(url, key) response = supabase.table("models").select("*").execute() return [LLMModel(**data) for data in response.data]