🔧 fix(store.py): flatten the tags in the list_components response to match the schema

🔧 fix(store.py): add user_created.id field to the list_components response to match the schema
🔧 fix(store.py): add count(downloads) field to the list_components response to match the schema
🔧 fix(store.py): add tags_id field to the TagsIdResponse schema to match the response structure
🔧 fix(service.py): add user_created.first_name and user_created.id fields to the list_components query to match the schema
🔧 fix(service.py): add count(downloads) field to the list_components query to match the schema
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-26 15:48:42 -03:00
commit 654a1de6c6
3 changed files with 33 additions and 2 deletions

View file

@ -79,10 +79,12 @@ def list_components(
"name",
"description",
"user_created.first_name",
"user_created.id",
"is_component",
"tags.tags_id.name",
"tags.tags_id.id",
"count(liked_by)",
"count(downloads)",
"metadata",
]
result = store_service.query_components(
@ -92,6 +94,9 @@ def list_components(
fields=fields,
filter_by_user=filter_by_user,
)
# tags comes as "tags" : [{"tags_id": {"name": "tag1", "id": 1}}]
# so we need to flatten it
return result
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc))

View file

@ -32,6 +32,10 @@ class ComponentResponse(BaseModel):
metadata: Optional[dict]
class TagsIdResponse(BaseModel):
tags_id: Optional[TagResponse]
class ListComponentResponse(BaseModel):
id: UUID
name: Optional[str]
@ -39,6 +43,8 @@ class ListComponentResponse(BaseModel):
liked_by_count: Optional[int]
is_component: Optional[bool]
metadata: Optional[dict]
user_created: Optional[dict]
tags: Optional[List[TagsIdResponse]] = None
class DownloadComponentResponse(BaseModel):

View file

@ -1,6 +1,7 @@
from datetime import datetime
import json
from uuid import UUID
from bs4 import Tag
from langflow.services.base import Service
from typing import TYPE_CHECKING, List, Dict, Any, Optional, Union
import httpx
@ -11,6 +12,7 @@ from langflow.services.store.schema import (
DownloadComponentResponse,
ListComponentResponse,
StoreComponentCreate,
TagResponse,
)
if TYPE_CHECKING:
@ -152,7 +154,19 @@ class StoreService(Service):
",".join(fields)
if fields
else ",".join(
["id", "name", "description", "count(liked_by)", "is_component"]
[
"id",
"name",
"description",
"user_created.first_name",
"user_created.id",
"is_component",
"tags.tags_id.name",
"tags.tags_id.id",
"count(liked_by)",
"count(downloads)",
"metadata",
]
)
)
# Only public components or the ones created by the user
@ -174,6 +188,7 @@ class StoreService(Service):
"tags.tags_id.name",
"tags.tags_id.id",
"count(liked_by)",
"count(downloads)",
"metadata",
]
else:
@ -182,7 +197,12 @@ class StoreService(Service):
)
results = self._get(self.components_url, api_key, params)
return [ListComponentResponse(**component) for component in results]
results_objects = [ListComponentResponse(**component) for component in results]
# Flatten the tags
for component in results_objects:
if component.tags:
component.tags = [tags_id.tags_id for tags_id in component.tags]
return results_objects
def download(self, api_key: str, component_id: str) -> DownloadComponentResponse:
url = f"{self.components_url}/{component_id}"