Merge branch 'feature/store' of github.com:logspace-ai/langflow into feature/store
This commit is contained in:
commit
c477db5cac
2 changed files with 28 additions and 3 deletions
|
|
@ -17,7 +17,7 @@ from langflow.services.store.schema import (
|
||||||
UsersLikesResponse,
|
UsersLikesResponse,
|
||||||
)
|
)
|
||||||
from langflow.services.store.service import StoreService, user_data_context
|
from langflow.services.store.service import StoreService, user_data_context
|
||||||
from langflow.services.store.utils import update_components_with_user_data
|
from langflow.services.store.utils import get_lf_version_from_pypi, update_components_with_user_data
|
||||||
|
|
||||||
router = APIRouter(prefix="/store", tags=["Components Store"])
|
router = APIRouter(prefix="/store", tags=["Components Store"])
|
||||||
|
|
||||||
|
|
@ -67,6 +67,21 @@ def create_component(
|
||||||
store_api_Key: str = Depends(get_user_store_api_key),
|
store_api_Key: str = Depends(get_user_store_api_key),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
# Verify if this is the latest version of Langflow
|
||||||
|
# If not, raise an error
|
||||||
|
langflow_version = get_lf_version_from_pypi()
|
||||||
|
if langflow_version is None:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500,
|
||||||
|
detail="Unable to verify the latest version of Langflow",
|
||||||
|
)
|
||||||
|
elif langflow_version != component.last_tested_version:
|
||||||
|
# If the user is using an older version of Langflow, we need to raise an error
|
||||||
|
raise ValueError(
|
||||||
|
f"Your version of Langflow ({component.last_tested_version}) is outdated."
|
||||||
|
" Please update to the latest version ({langflow_version}) and try again."
|
||||||
|
)
|
||||||
|
|
||||||
return store_service.upload(store_api_Key, component)
|
return store_service.upload(store_api_Key, component)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=400, detail=str(exc))
|
raise HTTPException(status_code=400, detail=str(exc))
|
||||||
|
|
@ -190,8 +205,8 @@ async def like_component(
|
||||||
store_api_Key: str = Depends(get_user_store_api_key),
|
store_api_Key: str = Depends(get_user_store_api_key),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
result = await store_service.like_component(store_api_Key, component_id)
|
result = await store_service.like_component(store_api_Key, str(component_id))
|
||||||
likes_count = await store_service.get_component_likes_count(store_api_Key, component_id)
|
likes_count = await store_service.get_component_likes_count(store_api_Key, str(component_id))
|
||||||
|
|
||||||
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,13 @@ async def update_components_with_user_data(
|
||||||
component.liked_by_user = str(component.id) in liked_by_user_ids
|
component.liked_by_user = str(component.id) in liked_by_user_ids
|
||||||
|
|
||||||
return components
|
return components
|
||||||
|
|
||||||
|
|
||||||
|
# Get the latest released version of langflow (https://pypi.org/project/langflow/)
|
||||||
|
def get_lf_version_from_pypi():
|
||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("https://pypi.org/pypi/langflow/json")
|
||||||
|
if response.status_code != 200:
|
||||||
|
return None
|
||||||
|
return response.json()["info"]["version"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue