Add Flow model and related schemas
This commit is contained in:
parent
bbd92fc453
commit
5f9a09d4c3
2 changed files with 56 additions and 1 deletions
|
|
@ -3,7 +3,8 @@ import time
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query, WebSocket, WebSocketException, status
|
from fastapi import APIRouter, Depends, HTTPException, Query, WebSocket, WebSocketException, status
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
from langflow.api.utils import build_input_keys_response, format_elapsed_time
|
from langflow.api.utils import build_input_keys_response, format_elapsed_time
|
||||||
from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData
|
from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData, VerticesOrderResponse
|
||||||
|
from langflow.services.database.models.flow.flow import Flow
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.services.auth.utils import get_current_active_user, get_current_user_by_jwt
|
from langflow.services.auth.utils import get_current_active_user, get_current_user_by_jwt
|
||||||
from langflow.services.cache.service import BaseCacheService
|
from langflow.services.cache.service import BaseCacheService
|
||||||
|
|
|
||||||
54
src/backend/langflow/services/database/models/flow/flow.py
Normal file
54
src/backend/langflow/services/database/models/flow/flow.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Path: src/backend/langflow/database/models/flow.py
|
||||||
|
|
||||||
|
from langflow.services.database.models.base import SQLModelSerializable
|
||||||
|
from pydantic import validator
|
||||||
|
|
||||||
|
from sqlmodel import Field, JSON, Column, Relationship
|
||||||
|
from uuid import UUID, uuid4
|
||||||
|
from typing import Dict, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langflow.services.database.models.user import User
|
||||||
|
|
||||||
|
|
||||||
|
class FlowBase(SQLModelSerializable):
|
||||||
|
name: str = Field(index=True)
|
||||||
|
description: Optional[str] = Field(index=True)
|
||||||
|
data: Optional[Dict] = Field(default=None, nullable=True)
|
||||||
|
|
||||||
|
@validator("data")
|
||||||
|
def validate_json(v):
|
||||||
|
if not v:
|
||||||
|
return v
|
||||||
|
if not isinstance(v, dict):
|
||||||
|
raise ValueError("Flow must be a valid JSON")
|
||||||
|
|
||||||
|
# data must contain nodes and edges
|
||||||
|
if "nodes" not in v.keys():
|
||||||
|
raise ValueError("Flow must have nodes")
|
||||||
|
if "edges" not in v.keys():
|
||||||
|
raise ValueError("Flow must have edges")
|
||||||
|
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
user_id: UUID = Field(index=True, foreign_key="user.id")
|
||||||
|
user: "User" = Relationship(back_populates="flows")
|
||||||
|
|
||||||
|
|
||||||
|
class FlowCreate(FlowBase):
|
||||||
|
user_id: Optional[UUID] = None
|
||||||
|
|
||||||
|
|
||||||
|
class FlowRead(FlowBase):
|
||||||
|
id: UUID
|
||||||
|
user_id: UUID = Field()
|
||||||
|
|
||||||
|
|
||||||
|
class FlowUpdate(SQLModelSerializable):
|
||||||
|
name: Optional[str] = None
|
||||||
|
description: Optional[str] = None
|
||||||
|
data: Optional[Dict] = None
|
||||||
Loading…
Add table
Add a link
Reference in a new issue