🔧 fix(__main__.py): add 'store' parameter to update_settings function to enable/disable store feature
✨ feat(__main__.py): add 'store' option to the run command to enable/disable store feature 🔧 fix(store.py): add check_if_store_is_enabled endpoint to check if store feature is enabled ✨ feat(store.py): add get_tags endpoint to retrieve tags from the store 🔧 fix(base.py): add STORE setting to enable/disable store feature 🔧 fix(schema.py): rename 'likes_count' field to 'liked_by_count' in ComponentResponse and ListComponentResponse 🔧 fix(service.py): change default sorting in query_components function to sort by 'count(liked_by)' ✅ test(test_store.py): update sort parameter in test_search_components to 'count(liked_by)'
This commit is contained in:
parent
785e8a6436
commit
d664131e6c
6 changed files with 57 additions and 14 deletions
|
|
@ -72,6 +72,7 @@ def update_settings(
|
|||
dev: bool = False,
|
||||
remove_api_keys: bool = False,
|
||||
components_path: Optional[Path] = None,
|
||||
store: bool = True,
|
||||
):
|
||||
"""Update the settings from a config file."""
|
||||
|
||||
|
|
@ -90,6 +91,9 @@ def update_settings(
|
|||
if components_path:
|
||||
logger.debug(f"Adding component path {components_path}")
|
||||
settings_service.settings.update_settings(COMPONENTS_PATH=components_path)
|
||||
if not store:
|
||||
logger.debug("Setting store to False")
|
||||
settings_service.settings.update_settings(STORE=False)
|
||||
|
||||
|
||||
@app.command()
|
||||
|
|
@ -126,13 +130,6 @@ def run(
|
|||
default=None,
|
||||
),
|
||||
dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"),
|
||||
# This variable does not work but is set by the .env file
|
||||
# and works with Pydantic
|
||||
# database_url: str = typer.Option(
|
||||
# None,
|
||||
# help="Database URL to connect to. If not provided, a local SQLite database will be used.",
|
||||
# envvar="LANGFLOW_DATABASE_URL",
|
||||
# ),
|
||||
path: str = typer.Option(
|
||||
None,
|
||||
help="Path to the frontend directory containing build files. This is for development purposes only.",
|
||||
|
|
@ -153,6 +150,11 @@ def run(
|
|||
help="Run only the backend server without the frontend.",
|
||||
envvar="LANGFLOW_BACKEND_ONLY",
|
||||
),
|
||||
store: bool = typer.Option(
|
||||
True,
|
||||
help="Enables the store features.",
|
||||
envvar="LANGFLOW_STORE",
|
||||
),
|
||||
):
|
||||
"""
|
||||
Run the Langflow.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from langflow.services.store.schema import (
|
|||
DownloadComponentResponse,
|
||||
ListComponentResponse,
|
||||
StoreComponentCreate,
|
||||
TagResponse,
|
||||
)
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
|
|
@ -44,6 +45,13 @@ def get_optional_user_store_api_key(
|
|||
return decrypted
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def check_if_store_is_enabled(
|
||||
settings_service=Depends(get_settings_service),
|
||||
):
|
||||
return {"enabled": settings_service.settings.STORE}
|
||||
|
||||
|
||||
@router.post("/components/", response_model=ComponentResponse, status_code=201)
|
||||
def create_component(
|
||||
component: StoreComponentCreate,
|
||||
|
|
@ -65,7 +73,16 @@ def list_components(
|
|||
store_api_Key: str = Depends(get_optional_user_store_api_key),
|
||||
):
|
||||
try:
|
||||
fields = ["id", "name", "description", "user_created.name", "is_component"]
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"description",
|
||||
"user_created.name",
|
||||
"is_component",
|
||||
"tags.tags_id.name",
|
||||
"tags.tags_id.id",
|
||||
"count(liked_by)",
|
||||
]
|
||||
result = store_service.query_components(
|
||||
store_api_Key,
|
||||
page,
|
||||
|
|
@ -143,3 +160,14 @@ async def search_endpoint(
|
|||
)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/tags", response_model=List[TagResponse])
|
||||
def get_tags(
|
||||
store_service: StoreService = Depends(get_store_service),
|
||||
store_api_Key: str = Depends(get_optional_user_store_api_key),
|
||||
):
|
||||
try:
|
||||
return store_service.get_tags(store_api_Key)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class Settings(BaseSettings):
|
|||
LANGFUSE_PUBLIC_KEY: Optional[str] = None
|
||||
LANGFUSE_HOST: Optional[str] = None
|
||||
|
||||
STORE: Optional[bool] = True
|
||||
STORE_URL: Optional[str] = None
|
||||
DOWNLOAD_WEBHOOK_URL: Optional[str] = None
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@ from typing import Optional, List
|
|||
from uuid import UUID
|
||||
|
||||
|
||||
class TagResponse(BaseModel):
|
||||
id: UUID
|
||||
name: Optional[str]
|
||||
|
||||
|
||||
class ComponentResponse(BaseModel):
|
||||
id: UUID
|
||||
status: Optional[str]
|
||||
|
|
@ -17,16 +22,15 @@ class ComponentResponse(BaseModel):
|
|||
description: Optional[str]
|
||||
data: Optional[dict]
|
||||
tags: Optional[List[int]]
|
||||
likes_count: Optional[List[UUID]]
|
||||
liked_by_count: Optional[List[UUID]]
|
||||
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]
|
||||
liked_by_count: Optional[int]
|
||||
is_component: Optional[bool]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class StoreService(Service):
|
|||
tags: Optional[List[str]] = None,
|
||||
date_from: Optional[datetime] = None,
|
||||
date_to: Optional[datetime] = None,
|
||||
sort: Optional[List[str]] = ["-likes"],
|
||||
sort: Optional[List[str]] = ["-count(liked_by)"],
|
||||
fields: Optional[List[str]] = None,
|
||||
filter_by_user: bool = False,
|
||||
) -> List[ComponentResponse]:
|
||||
|
|
@ -151,7 +151,9 @@ class StoreService(Service):
|
|||
params["fields"] = (
|
||||
",".join(fields)
|
||||
if fields
|
||||
else ",".join(["id", "name", "description", "count(likes)", "is_component"])
|
||||
else ",".join(
|
||||
["id", "name", "description", "count(liked_by)", "is_component"]
|
||||
)
|
||||
)
|
||||
# Only public components or the ones created by the user
|
||||
# check for "public" or "Public"
|
||||
|
|
@ -208,3 +210,9 @@ class StoreService(Service):
|
|||
except UnboundLocalError:
|
||||
pass
|
||||
raise ValueError(f"Upload failed: {exc}")
|
||||
|
||||
def get_tags(self, api_key: str) -> List[Dict[str, Any]]:
|
||||
url = f"{self.base_url}/items/tags"
|
||||
params = {"fields": ",".join(["id", "name"])}
|
||||
tags = self._get(url, api_key, params)
|
||||
return tags
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def test_search_components(mock_httpx: Mock, client):
|
|||
"filter[name][_like]": "test",
|
||||
"page": 1,
|
||||
"limit": 5,
|
||||
"sort": "likes",
|
||||
"sort": "count(liked_by)",
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue