🐛 fix(store.py): import missing schema classes in store.py to fix NameError
✨ feat(store.py): change response models for list_components and read_component endpoints to use new schema classes for improved consistency and clarity 🐛 fix(schema.py): add missing ListComponentResponse and DownloadComponentResponse classes to schema.py to fix NameError ✨ feat(service.py): change return types of list_components and download methods in StoreService to use new schema classes for improved consistency and clarity
This commit is contained in:
parent
2b9ac7c3ac
commit
8b9267b2e8
3 changed files with 38 additions and 11 deletions
|
|
@ -3,11 +3,15 @@ from uuid import UUID
|
|||
from langflow.services.auth import utils as auth_utils
|
||||
from langflow.services.database.models.user.user import User
|
||||
from langflow.services.deps import (
|
||||
get_session,
|
||||
get_store_service,
|
||||
get_settings_service,
|
||||
)
|
||||
from langflow.services.store.schema import ComponentResponse, StoreComponentCreate
|
||||
from langflow.services.store.schema import (
|
||||
ComponentResponse,
|
||||
DownloadComponentResponse,
|
||||
ListComponentResponse,
|
||||
StoreComponentCreate,
|
||||
)
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from datetime import datetime
|
||||
|
|
@ -46,7 +50,7 @@ def create_component(
|
|||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/components/", response_model=List[ComponentResponse])
|
||||
@router.get("/components/", response_model=List[ListComponentResponse])
|
||||
def list_components(
|
||||
page: int = 1,
|
||||
limit: int = 10,
|
||||
|
|
@ -66,13 +70,12 @@ def list_components(
|
|||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/components/{component_id}", response_model=ComponentResponse)
|
||||
@router.get("/components/{component_id}", response_model=DownloadComponentResponse)
|
||||
def read_component(
|
||||
component_id: UUID,
|
||||
store_service: StoreService = Depends(get_store_service),
|
||||
store_api_Key: str = Depends(get_user_store_api_key),
|
||||
settings_service=Depends(get_settings_service),
|
||||
session=Depends(get_session),
|
||||
):
|
||||
# If the component is from the store, we need to get it from the store
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,23 @@ class ComponentResponse(BaseModel):
|
|||
parent: Optional[UUID]
|
||||
|
||||
|
||||
class ListComponentResponse(BaseModel):
|
||||
(["id", "name", "description", "count(likes)", "is_component"])
|
||||
id: UUID
|
||||
name: Optional[str]
|
||||
description: Optional[str]
|
||||
likes_count: Optional[int]
|
||||
is_component: Optional[bool]
|
||||
|
||||
|
||||
class DownloadComponentResponse(BaseModel):
|
||||
id: UUID
|
||||
name: Optional[str]
|
||||
description: Optional[str]
|
||||
data: Optional[dict]
|
||||
is_component: Optional[bool]
|
||||
|
||||
|
||||
class StoreComponentCreate(BaseModel):
|
||||
name: str
|
||||
description: Optional[str]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ from langflow.services.base import Service
|
|||
from typing import TYPE_CHECKING, List, Dict, Any, Optional
|
||||
import httpx
|
||||
from httpx import HTTPError
|
||||
from langflow.services.store.schema import ComponentResponse, StoreComponentCreate
|
||||
from langflow.services.store.schema import (
|
||||
ComponentResponse,
|
||||
DownloadComponentResponse,
|
||||
ListComponentResponse,
|
||||
StoreComponentCreate,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.settings.service import SettingsService
|
||||
|
|
@ -91,7 +96,7 @@ class StoreService(Service):
|
|||
page: int = 1,
|
||||
limit: int = 10,
|
||||
fields: Optional[List[str]] = None,
|
||||
) -> List[ComponentResponse]:
|
||||
) -> List[ListComponentResponse]:
|
||||
params = {"page": page, "limit": limit}
|
||||
# ?aggregate[count]=likes
|
||||
params["fields"] = (
|
||||
|
|
@ -101,13 +106,15 @@ class StoreService(Service):
|
|||
)
|
||||
|
||||
results = self._get(self.components_url, api_key, params)
|
||||
return [ComponentResponse(**component) for component in results]
|
||||
return [ListComponentResponse(**component) for component in results]
|
||||
|
||||
def download(self, api_key: str, id: str) -> ComponentResponse:
|
||||
def download(self, api_key: str, id: str) -> DownloadComponentResponse:
|
||||
url = f"{self.components_url}/{id}"
|
||||
params = {"fields": ",".join(["id", "name", "description", "data"])}
|
||||
params = {
|
||||
"fields": ",".join(["id", "name", "description", "data", "is_component"])
|
||||
}
|
||||
component = self._get(url, api_key, params)
|
||||
return ComponentResponse(**component)
|
||||
return DownloadComponentResponse(**component)
|
||||
|
||||
def upload(
|
||||
self, api_key: str, component_data: StoreComponentCreate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue