From d4b6b7c4e8c9930003290c15d624d1f2c5bcd8a6 Mon Sep 17 00:00:00 2001 From: Jonathan Rohde Date: Tue, 25 Jun 2024 08:29:18 +0200 Subject: [PATCH] feat(sqlalchemy): reverted not needed api change --- backend/apps/webui/routers/models.py | 2 +- backend/test/apps/webui/routers/test_models.py | 4 ++-- backend/test/util/abstract_integration_test.py | 10 ++++++++-- src/lib/apis/models/index.ts | 5 ++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/apps/webui/routers/models.py b/backend/apps/webui/routers/models.py index eaf459d73..eeae9e1c4 100644 --- a/backend/apps/webui/routers/models.py +++ b/backend/apps/webui/routers/models.py @@ -56,7 +56,7 @@ async def add_new_model( ############################ -@router.get("/{id}", response_model=Optional[ModelModel]) +@router.get("/", response_model=Optional[ModelModel]) async def get_model_by_id(id: str, user=Depends(get_verified_user)): model = Models.get_model_by_id(id) diff --git a/backend/test/apps/webui/routers/test_models.py b/backend/test/apps/webui/routers/test_models.py index 991c83bee..a8495403b 100644 --- a/backend/test/apps/webui/routers/test_models.py +++ b/backend/test/apps/webui/routers/test_models.py @@ -42,9 +42,9 @@ class TestModels(AbstractPostgresTest): assert len(response.json()) == 1 with mock_webui_user(id="2"): - response = self.fast_api_client.get(self.create_url("/my-model")) + response = self.fast_api_client.get(self.create_url(query_params={"id": "my-model"})) assert response.status_code == 200 - data = response.json() + data = response.json()[0] assert data["id"] == "my-model" assert data["name"] == "Hello World" diff --git a/backend/test/util/abstract_integration_test.py b/backend/test/util/abstract_integration_test.py index 4e99dcc2f..8535221a8 100644 --- a/backend/test/util/abstract_integration_test.py +++ b/backend/test/util/abstract_integration_test.py @@ -23,14 +23,20 @@ def get_fast_api_client(): class AbstractIntegrationTest: BASE_PATH = None - def create_url(self, path): + def create_url(self, path="", query_params=None): if self.BASE_PATH is None: raise Exception("BASE_PATH is not set") parts = self.BASE_PATH.split("/") parts = [part.strip() for part in parts if part.strip() != ""] path_parts = path.split("/") path_parts = [part.strip() for part in path_parts if part.strip() != ""] - return "/".join(parts + path_parts) + query_parts = "" + if query_params: + query_parts = "&".join( + [f"{key}={value}" for key, value in query_params.items()] + ) + query_parts = f"?{query_parts}" + return "/".join(parts + path_parts) + query_parts @classmethod def setup_class(cls): diff --git a/src/lib/apis/models/index.ts b/src/lib/apis/models/index.ts index 17d11d816..9faa358d3 100644 --- a/src/lib/apis/models/index.ts +++ b/src/lib/apis/models/index.ts @@ -63,7 +63,10 @@ export const getModelInfos = async (token: string = '') => { export const getModelById = async (token: string, id: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/models/${id}`, { + const searchParams = new URLSearchParams(); + searchParams.append('id', id); + + const res = await fetch(`${WEBUI_API_BASE_URL}/models?${searchParams.toString()}`, { method: 'GET', headers: { Accept: 'application/json',