From 4547edef0f452255b1eabedf24b145aa8b8d0900 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 10:13:40 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20refactor(api):=20remove=20unused?= =?UTF-8?q?=20flow=5Fstyles=20module=20and=20related=20code=20=F0=9F=94=A5?= =?UTF-8?q?=20refactor(api):=20remove=20unused=20flow=5Fstyles=20router=20?= =?UTF-8?q?and=20related=20endpoints=20=F0=9F=94=A5=20refactor(api):=20rem?= =?UTF-8?q?ove=20unused=20FlowStyle=20model=20and=20related=20code=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(api):=20remove=20unused=20FlowStyleCrea?= =?UTF-8?q?te,=20FlowStyleRead,=20and=20FlowStyleUpdate=20models=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(api):=20remove=20unused=20style=20relat?= =?UTF-8?q?ionship=20from=20Flow=20model=20=F0=9F=94=A5=20refactor(api):?= =?UTF-8?q?=20remove=20unused=20FlowReadWithStyle=20model=20=F0=9F=94=A5?= =?UTF-8?q?=20refactor(api):=20remove=20unused=20flow=5Fstyles=5Fid=20para?= =?UTF-8?q?meter=20from=20read=5Fflow=5Fstyle=20endpoint=20=F0=9F=94=A5=20?= =?UTF-8?q?refactor(api):=20remove=20unused=20update=5Fflow=5Fstyle=20endp?= =?UTF-8?q?oint=20=F0=9F=94=A5=20refactor(api):=20remove=20unused=20delete?= =?UTF-8?q?=5Fflow=5Fstyle=20endpoint=20=F0=9F=94=A5=20refactor(api):=20re?= =?UTF-8?q?move=20unused=20flow=5Fid=20parameter=20from=20delete=5Fflow=5F?= =?UTF-8?q?style=20endpoint=20=F0=9F=94=A5=20refactor(api):=20remove=20unu?= =?UTF-8?q?sed=20style=20parameter=20from=20create=5Fflow=5Fstyle=20endpoi?= =?UTF-8?q?nt=20=F0=9F=94=A5=20refactor(api):=20remove=20unused=20read=5Ff?= =?UTF-8?q?low=5Fstyles=20endpoint=20=F0=9F=94=A5=20refactor(api):=20remov?= =?UTF-8?q?e=20unused=20flow=5Fstyles=5Fid=20parameter=20from=20read=5Fflo?= =?UTF-8?q?w=5Fstyles=20endpoint=20=F0=9F=94=A5=20refactor(api):=20remove?= =?UTF-8?q?=20unused=20flow=5Fstyle=5Fid=20parameter=20from=20update=5Fflo?= =?UTF-8?q?w=5Fstyle=20endpoint=20=F0=9F=94=A5=20refactor(api):=20remove?= =?UTF-8?q?=20unused=20flow=5Fstyle=20parameter=20from=20update=5Fflow=5Fs?= =?UTF-8?q?tyle=20endpoint=20=F0=9F=94=A5=20refactor(api):=20remove=20unus?= =?UTF-8?q?ed=20flow=5Fstyle=20parameter=20from=20create=5Fflow=5Fstyle=20?= =?UTF-8?q?endpoint=20=F0=9F=94=A5=20refactor(api):=20remove=20unused=20fl?= =?UTF-8?q?ow=5Fstyles=5Frouter=20import=20=F0=9F=94=A5=20refactor(api):?= =?UTF-8?q?=20remove=20unused=20flow=5Fstyles=5Frouter=20variable=20?= =?UTF-8?q?=F0=9F=94=A5=20refactor(api):=20remove=20unused=20flow=5Fstyles?= =?UTF-8?q?=5Frouter=20prefix=20and=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/__init__.py | 2 - src/backend/langflow/api/v1/flow_styles.py | 83 ------------------- src/backend/langflow/api/v1/flows.py | 5 +- .../langflow/services/database/models/flow.py | 12 +-- .../services/database/models/flow_style.py | 33 -------- 5 files changed, 3 insertions(+), 132 deletions(-) delete mode 100644 src/backend/langflow/api/v1/flow_styles.py delete mode 100644 src/backend/langflow/services/database/models/flow_style.py diff --git a/src/backend/langflow/api/v1/__init__.py b/src/backend/langflow/api/v1/__init__.py index f001152a9..b6e7b36d8 100644 --- a/src/backend/langflow/api/v1/__init__.py +++ b/src/backend/langflow/api/v1/__init__.py @@ -2,7 +2,6 @@ from langflow.api.v1.endpoints import router as endpoints_router from langflow.api.v1.validate import router as validate_router from langflow.api.v1.chat import router as chat_router from langflow.api.v1.flows import router as flows_router -from langflow.api.v1.flow_styles import router as flow_styles_router from langflow.api.v1.components import router as component_router __all__ = [ @@ -11,5 +10,4 @@ __all__ = [ "component_router", "validate_router", "flows_router", - "flow_styles_router", ] diff --git a/src/backend/langflow/api/v1/flow_styles.py b/src/backend/langflow/api/v1/flow_styles.py deleted file mode 100644 index 6eacf8d86..000000000 --- a/src/backend/langflow/api/v1/flow_styles.py +++ /dev/null @@ -1,83 +0,0 @@ -from uuid import UUID -from langflow.services.database.models.flow_style import ( - FlowStyle, - FlowStyleCreate, - FlowStyleRead, - FlowStyleUpdate, -) -from langflow.services.utils import get_session -from sqlmodel import Session, select -from fastapi import APIRouter, Depends, HTTPException - - -# build router -router = APIRouter(prefix="/flow_styles", tags=["FlowStyles"]) - -# FlowStyleCreate: -# class FlowStyleBase(SQLModel): -# color: str = Field(index=True) -# emoji: str = Field(index=False) -# flow_id: UUID = Field(default=None, foreign_key="flow.id") - - -@router.post("/", response_model=FlowStyleRead) -def create_flow_style( - *, session: Session = Depends(get_session), flow_style: FlowStyleCreate -): - """Create a new flow_style.""" - db_flow_style = FlowStyle.from_orm(flow_style) - session.add(db_flow_style) - session.commit() - session.refresh(db_flow_style) - return db_flow_style - - -@router.get("/", response_model=list[FlowStyleRead]) -def read_flow_styles(*, session: Session = Depends(get_session)): - """Read all flows.""" - try: - flows = session.exec(select(FlowStyle)).all() - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) from e - return flows - - -@router.get("/{flow_styles_id}", response_model=FlowStyleRead) -def read_flow_style(*, session: Session = Depends(get_session), flow_styles_id: UUID): - """Read a flow_style.""" - if flow_style := session.get(FlowStyle, flow_styles_id): - return flow_style - else: - raise HTTPException(status_code=404, detail="FlowStyle not found") - - -@router.patch("/{flow_style_id}", response_model=FlowStyleRead) -def update_flow_style( - *, - session: Session = Depends(get_session), - flow_style_id: UUID, - flow_style: FlowStyleUpdate, -): - """Update a flow_style.""" - db_flow_style = session.get(FlowStyle, flow_style_id) - if not db_flow_style: - raise HTTPException(status_code=404, detail="FlowStyle not found") - flow_data = flow_style.dict(exclude_unset=True) - for key, value in flow_data.items(): - if hasattr(db_flow_style, key) and value is not None: - setattr(db_flow_style, key, value) - session.add(db_flow_style) - session.commit() - session.refresh(db_flow_style) - return db_flow_style - - -@router.delete("/{flow_id}") -def delete_flow_style(*, session: Session = Depends(get_session), flow_id: UUID): - """Delete a flow_style.""" - flow_style = session.get(FlowStyle, flow_id) - if not flow_style: - raise HTTPException(status_code=404, detail="FlowStyle not found") - session.delete(flow_style) - session.commit() - return {"message": "FlowStyle deleted successfully"} diff --git a/src/backend/langflow/api/v1/flows.py b/src/backend/langflow/api/v1/flows.py index 1ecbc85f4..3145ced3c 100644 --- a/src/backend/langflow/api/v1/flows.py +++ b/src/backend/langflow/api/v1/flows.py @@ -6,7 +6,6 @@ from langflow.services.database.models.flow import ( Flow, FlowCreate, FlowRead, - FlowReadWithStyle, FlowUpdate, ) from langflow.services.utils import get_session @@ -32,7 +31,7 @@ def create_flow(*, session: Session = Depends(get_session), flow: FlowCreate): return db_flow -@router.get("/", response_model=list[FlowReadWithStyle], status_code=200) +@router.get("/", response_model=list[FlowRead], status_code=200) def read_flows(*, session: Session = Depends(get_session)): """Read all flows.""" try: @@ -42,7 +41,7 @@ def read_flows(*, session: Session = Depends(get_session)): return [jsonable_encoder(flow) for flow in flows] -@router.get("/{flow_id}", response_model=FlowReadWithStyle, status_code=200) +@router.get("/{flow_id}", response_model=FlowRead, status_code=200) def read_flow(*, session: Session = Depends(get_session), flow_id: UUID): """Read a flow.""" if flow := session.get(Flow, flow_id): diff --git a/src/backend/langflow/services/database/models/flow.py b/src/backend/langflow/services/database/models/flow.py index 2b6c6879c..2bc83f9dc 100644 --- a/src/backend/langflow/services/database/models/flow.py +++ b/src/backend/langflow/services/database/models/flow.py @@ -2,12 +2,11 @@ from langflow.services.database.models.base import SQLModelSerializable from pydantic import validator -from sqlmodel import Field, Relationship, JSON, Column +from sqlmodel import Field, JSON, Column from uuid import UUID, uuid4 from typing import Dict, Optional # if TYPE_CHECKING: -from langflow.services.database.models.flow_style import FlowStyle, FlowStyleRead class FlowBase(SQLModelSerializable): @@ -35,11 +34,6 @@ class FlowBase(SQLModelSerializable): class Flow(FlowBase, table=True): id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True) data: Optional[Dict] = Field(default=None, sa_column=Column(JSON)) - style: Optional["FlowStyle"] = Relationship( - back_populates="flow", - # use "uselist=False" to make it a one-to-one relationship - sa_relationship_kwargs={"uselist": False}, - ) class FlowCreate(FlowBase): @@ -50,10 +44,6 @@ class FlowRead(FlowBase): id: UUID -class FlowReadWithStyle(FlowRead): - style: Optional["FlowStyleRead"] = None - - class FlowUpdate(SQLModelSerializable): name: Optional[str] = None description: Optional[str] = None diff --git a/src/backend/langflow/services/database/models/flow_style.py b/src/backend/langflow/services/database/models/flow_style.py deleted file mode 100644 index 3810c7cea..000000000 --- a/src/backend/langflow/services/database/models/flow_style.py +++ /dev/null @@ -1,33 +0,0 @@ -# Path: src/backend/langflow/database/models/flowstyle.py - -from langflow.services.database.models.base import SQLModelSerializable -from sqlmodel import Field, Relationship -from uuid import UUID, uuid4 -from typing import TYPE_CHECKING, Optional - -if TYPE_CHECKING: - from langflow.services.database.models.flow import Flow - - -class FlowStyleBase(SQLModelSerializable): - color: str - emoji: str - flow_id: UUID = Field(default=None, foreign_key="flow.id") - - -class FlowStyle(FlowStyleBase, table=True): - id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True) - flow: "Flow" = Relationship(back_populates="style") - - -class FlowStyleUpdate(SQLModelSerializable): - color: Optional[str] = None - emoji: Optional[str] = None - - -class FlowStyleCreate(FlowStyleBase): - pass - - -class FlowStyleRead(FlowStyleBase): - id: UUID