refactor(api): change variable type annotations (#3592)
* refactor(log_router.py): change variable type annotation from List to list for better consistency refactor(utils.py): change variable type annotation from Dict to dict for better consistency refactor(base.py): change variable type annotation from Optional to Union for better clarity refactor(callback.py): change variable type annotation from Dict to dict for better consistency refactor(chat.py): change variable type annotation from Optional to Union for better clarity refactor(endpoints.py): change variable type annotation from Optional to Union for better clarity refactor(flows.py): change variable type annotation from List to list for better consistency refactor(api): update response_model annotations to use lowercase list for consistency and improve readability refactor(store.py): update type annotations for query parameters in get_components endpoint to improve code readability and maintainability feat(store.py): add support for type hinting Union and list types in query parameters for better data validation and documentation * run make format
This commit is contained in:
parent
7641e81ca3
commit
d7dbf1ae78
12 changed files with 116 additions and 124 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
from typing import List, Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Query, HTTPException, Request
|
from fastapi import APIRouter, Query, HTTPException, Request
|
||||||
from fastapi.responses import JSONResponse, StreamingResponse
|
from fastapi.responses import JSONResponse, StreamingResponse
|
||||||
|
|
@ -15,7 +15,7 @@ async def event_generator(request: Request):
|
||||||
last_read_item = None
|
last_read_item = None
|
||||||
current_not_sent = 0
|
current_not_sent = 0
|
||||||
while not await request.is_disconnected():
|
while not await request.is_disconnected():
|
||||||
to_write: List[Any] = []
|
to_write: list[Any] = []
|
||||||
with log_buffer.get_write_lock():
|
with log_buffer.get_write_lock():
|
||||||
if last_read_item is None:
|
if last_read_item is None:
|
||||||
last_read_item = log_buffer.buffer[len(log_buffer.buffer) - 1]
|
last_read_item = log_buffer.buffer[len(log_buffer.buffer) - 1]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
import warnings
|
||||||
from typing import TYPE_CHECKING, Any, Optional, Dict
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from sqlmodel import Session
|
from sqlmodel import Session
|
||||||
|
|
@ -122,7 +122,7 @@ def format_elapsed_time(elapsed_time: float) -> str:
|
||||||
return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}"
|
return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}"
|
||||||
|
|
||||||
|
|
||||||
async def build_graph_from_data(flow_id: str, payload: Dict, **kwargs):
|
async def build_graph_from_data(flow_id: str, payload: dict, **kwargs):
|
||||||
"""Build and cache the graph."""
|
"""Build and cache the graph."""
|
||||||
graph = Graph.from_payload(payload, flow_id, **kwargs)
|
graph = Graph.from_payload(payload, flow_id, **kwargs)
|
||||||
for vertex_id in graph._has_session_id_vertices:
|
for vertex_id in graph._has_session_id_vertices:
|
||||||
|
|
@ -141,7 +141,7 @@ async def build_graph_from_data(flow_id: str, payload: Dict, **kwargs):
|
||||||
|
|
||||||
async def build_graph_from_db_no_cache(flow_id: str, session: Session):
|
async def build_graph_from_db_no_cache(flow_id: str, session: Session):
|
||||||
"""Build and cache the graph."""
|
"""Build and cache the graph."""
|
||||||
flow: Optional[Flow] = session.get(Flow, flow_id)
|
flow: Flow | None = session.get(Flow, flow_id)
|
||||||
if not flow or not flow.data:
|
if not flow or not flow.data:
|
||||||
raise ValueError("Invalid flow ID")
|
raise ValueError("Invalid flow ID")
|
||||||
return await build_graph_from_data(flow_id, flow.data, flow_name=flow.name, user_id=str(flow.user_id))
|
return await build_graph_from_data(flow_id, flow.data, flow_name=flow.name, user_id=str(flow.user_id))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from pydantic import BaseModel, field_validator, model_serializer
|
from pydantic import BaseModel, field_validator, model_serializer
|
||||||
|
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
from langflow.template.frontend_node.base import FrontendNode
|
||||||
|
|
@ -26,8 +24,8 @@ class FrontendNodeRequest(FrontendNode):
|
||||||
class ValidatePromptRequest(BaseModel):
|
class ValidatePromptRequest(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
template: str
|
template: str
|
||||||
custom_fields: Optional[dict] = None
|
custom_fields: dict | None = None
|
||||||
frontend_node: Optional[FrontendNodeRequest] = None
|
frontend_node: FrontendNodeRequest | None = None
|
||||||
|
|
||||||
|
|
||||||
# Build ValidationResponse class for {"imports": {"errors": []}, "function": {"errors": []}}
|
# Build ValidationResponse class for {"imports": {"errors": []}, "function": {"errors": []}}
|
||||||
|
|
@ -49,4 +47,4 @@ class CodeValidationResponse(BaseModel):
|
||||||
class PromptValidationResponse(BaseModel):
|
class PromptValidationResponse(BaseModel):
|
||||||
input_variables: list
|
input_variables: list
|
||||||
# object return for tweak call
|
# object return for tweak call
|
||||||
frontend_node: Optional[FrontendNodeRequest] = None
|
frontend_node: FrontendNodeRequest | None = None
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
from typing import TYPE_CHECKING, Any
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from langchain_core.callbacks.base import AsyncCallbackHandler
|
from langchain_core.callbacks.base import AsyncCallbackHandler
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
@ -32,7 +32,7 @@ class AsyncStreamingLLMCallbackHandleSIO(AsyncCallbackHandler):
|
||||||
resp = ChatResponse(message=token, type="stream", intermediate_steps="")
|
resp = ChatResponse(message=token, type="stream", intermediate_steps="")
|
||||||
await self.socketio_service.emit_token(to=self.sid, data=resp.model_dump())
|
await self.socketio_service.emit_token(to=self.sid, data=resp.model_dump())
|
||||||
|
|
||||||
async def on_tool_start(self, serialized: Dict[str, Any], input_str: str, **kwargs: Any) -> Any:
|
async def on_tool_start(self, serialized: dict[str, Any], input_str: str, **kwargs: Any) -> Any:
|
||||||
"""Run when tool starts running."""
|
"""Run when tool starts running."""
|
||||||
resp = ChatResponse(
|
resp = ChatResponse(
|
||||||
message="",
|
message="",
|
||||||
|
|
@ -79,8 +79,8 @@ class AsyncStreamingLLMCallbackHandleSIO(AsyncCallbackHandler):
|
||||||
error: BaseException,
|
error: BaseException,
|
||||||
*,
|
*,
|
||||||
run_id: UUID,
|
run_id: UUID,
|
||||||
parent_run_id: Optional[UUID] = None,
|
parent_run_id: UUID | None = None,
|
||||||
tags: Optional[List[str]] = None,
|
tags: list[str] | None = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run when tool errors."""
|
"""Run when tool errors."""
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
import typing
|
import typing
|
||||||
import uuid
|
import uuid
|
||||||
from typing import TYPE_CHECKING, Annotated, Optional
|
from typing import TYPE_CHECKING, Annotated
|
||||||
|
|
||||||
from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException
|
from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
@ -68,9 +68,9 @@ async def try_running_celery_task(vertex, user_id):
|
||||||
async def retrieve_vertices_order(
|
async def retrieve_vertices_order(
|
||||||
flow_id: uuid.UUID,
|
flow_id: uuid.UUID,
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
data: Optional[Annotated[Optional[FlowDataRequest], Body(embed=True)]] = None,
|
data: Annotated[FlowDataRequest | None, Body(embed=True)] | None = None,
|
||||||
stop_component_id: Optional[str] = None,
|
stop_component_id: str | None = None,
|
||||||
start_component_id: Optional[str] = None,
|
start_component_id: str | None = None,
|
||||||
chat_service: "ChatService" = Depends(get_chat_service),
|
chat_service: "ChatService" = Depends(get_chat_service),
|
||||||
session=Depends(get_session),
|
session=Depends(get_session),
|
||||||
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
||||||
|
|
@ -141,12 +141,12 @@ async def retrieve_vertices_order(
|
||||||
async def build_flow(
|
async def build_flow(
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
flow_id: uuid.UUID,
|
flow_id: uuid.UUID,
|
||||||
inputs: Annotated[Optional[InputValueRequest], Body(embed=True)] = None,
|
inputs: Annotated[InputValueRequest | None, Body(embed=True)] = None,
|
||||||
data: Annotated[Optional[FlowDataRequest], Body(embed=True)] = None,
|
data: Annotated[FlowDataRequest | None, Body(embed=True)] = None,
|
||||||
files: Optional[list[str]] = None,
|
files: list[str] | None = None,
|
||||||
stop_component_id: Optional[str] = None,
|
stop_component_id: str | None = None,
|
||||||
start_component_id: Optional[str] = None,
|
start_component_id: str | None = None,
|
||||||
log_builds: Optional[bool] = True,
|
log_builds: bool | None = True,
|
||||||
chat_service: "ChatService" = Depends(get_chat_service),
|
chat_service: "ChatService" = Depends(get_chat_service),
|
||||||
current_user=Depends(get_current_active_user),
|
current_user=Depends(get_current_active_user),
|
||||||
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
||||||
|
|
@ -434,7 +434,7 @@ class DisconnectHandlerStreamingResponse(StreamingResponse):
|
||||||
headers: typing.Mapping[str, str] | None = None,
|
headers: typing.Mapping[str, str] | None = None,
|
||||||
media_type: str | None = None,
|
media_type: str | None = None,
|
||||||
background: BackgroundTask | None = None,
|
background: BackgroundTask | None = None,
|
||||||
on_disconnect: Optional[typing.Callable] = None,
|
on_disconnect: typing.Callable | None = None,
|
||||||
):
|
):
|
||||||
super().__init__(content, status_code, headers, media_type, background)
|
super().__init__(content, status_code, headers, media_type, background)
|
||||||
self.on_disconnect = on_disconnect
|
self.on_disconnect = on_disconnect
|
||||||
|
|
@ -453,8 +453,8 @@ async def build_vertex(
|
||||||
flow_id: uuid.UUID,
|
flow_id: uuid.UUID,
|
||||||
vertex_id: str,
|
vertex_id: str,
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
inputs: Annotated[Optional[InputValueRequest], Body(embed=True)] = None,
|
inputs: Annotated[InputValueRequest | None, Body(embed=True)] = None,
|
||||||
files: Optional[list[str]] = None,
|
files: list[str] | None = None,
|
||||||
chat_service: "ChatService" = Depends(get_chat_service),
|
chat_service: "ChatService" = Depends(get_chat_service),
|
||||||
current_user=Depends(get_current_active_user),
|
current_user=Depends(get_current_active_user),
|
||||||
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
|
||||||
|
|
@ -606,7 +606,7 @@ async def build_vertex(
|
||||||
async def build_vertex_stream(
|
async def build_vertex_stream(
|
||||||
flow_id: uuid.UUID,
|
flow_id: uuid.UUID,
|
||||||
vertex_id: str,
|
vertex_id: str,
|
||||||
session_id: Optional[str] = None,
|
session_id: str | None = None,
|
||||||
chat_service: "ChatService" = Depends(get_chat_service),
|
chat_service: "ChatService" = Depends(get_chat_service),
|
||||||
session_service: "SessionService" = Depends(get_session_service),
|
session_service: "SessionService" = Depends(get_session_service),
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import time
|
import time
|
||||||
from asyncio import Lock
|
from asyncio import Lock
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import TYPE_CHECKING, Annotated, List, Optional, Union
|
from typing import TYPE_CHECKING, Annotated
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
@ -108,12 +108,12 @@ async def simple_run_flow(
|
||||||
flow: Flow,
|
flow: Flow,
|
||||||
input_request: SimplifiedAPIRequest,
|
input_request: SimplifiedAPIRequest,
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
api_key_user: Optional[User] = None,
|
api_key_user: User | None = None,
|
||||||
):
|
):
|
||||||
if input_request.input_value is not None and input_request.tweaks is not None:
|
if input_request.input_value is not None and input_request.tweaks is not None:
|
||||||
validate_input_and_tweaks(input_request)
|
validate_input_and_tweaks(input_request)
|
||||||
try:
|
try:
|
||||||
task_result: List[RunOutputs] = []
|
task_result: list[RunOutputs] = []
|
||||||
user_id = api_key_user.id if api_key_user else None
|
user_id = api_key_user.id if api_key_user else None
|
||||||
flow_id_str = str(flow.id)
|
flow_id_str = str(flow.id)
|
||||||
if flow.data is None:
|
if flow.data is None:
|
||||||
|
|
@ -155,7 +155,7 @@ async def simple_run_flow_task(
|
||||||
flow: Flow,
|
flow: Flow,
|
||||||
input_request: SimplifiedAPIRequest,
|
input_request: SimplifiedAPIRequest,
|
||||||
stream: bool = False,
|
stream: bool = False,
|
||||||
api_key_user: Optional[User] = None,
|
api_key_user: User | None = None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Run a flow task as a BackgroundTask, therefore it should not throw exceptions.
|
Run a flow task as a BackgroundTask, therefore it should not throw exceptions.
|
||||||
|
|
@ -362,11 +362,11 @@ async def webhook_run_flow(
|
||||||
async def experimental_run_flow(
|
async def experimental_run_flow(
|
||||||
session: Annotated[Session, Depends(get_session)],
|
session: Annotated[Session, Depends(get_session)],
|
||||||
flow_id: UUID,
|
flow_id: UUID,
|
||||||
inputs: Optional[List[InputValueRequest]] = [InputValueRequest(components=[], input_value="")],
|
inputs: list[InputValueRequest] | None = [InputValueRequest(components=[], input_value="")],
|
||||||
outputs: Optional[List[str]] = [],
|
outputs: list[str] | None = [],
|
||||||
tweaks: Annotated[Optional[Tweaks], Body(embed=True)] = None, # noqa: F821
|
tweaks: Annotated[Tweaks | None, Body(embed=True)] = None, # noqa: F821
|
||||||
stream: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
stream: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
||||||
session_id: Annotated[Union[None, str], Body(embed=True)] = None, # noqa: F821
|
session_id: Annotated[None | str, Body(embed=True)] = None, # noqa: F821
|
||||||
api_key_user: UserRead = Depends(api_key_security),
|
api_key_user: UserRead = Depends(api_key_security),
|
||||||
session_service: SessionService = Depends(get_session_service),
|
session_service: SessionService = Depends(get_session_service),
|
||||||
):
|
):
|
||||||
|
|
@ -476,10 +476,10 @@ async def experimental_run_flow(
|
||||||
async def process(
|
async def process(
|
||||||
session: Annotated[Session, Depends(get_session)],
|
session: Annotated[Session, Depends(get_session)],
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
inputs: Optional[Union[List[dict], dict]] = None,
|
inputs: list[dict] | dict | None = None,
|
||||||
tweaks: Optional[dict] = None,
|
tweaks: dict | None = None,
|
||||||
clear_cache: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
clear_cache: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
||||||
session_id: Annotated[Union[None, str], Body(embed=True)] = None, # noqa: F821
|
session_id: Annotated[None | str, Body(embed=True)] = None, # noqa: F821
|
||||||
task_service: "TaskService" = Depends(get_task_service),
|
task_service: "TaskService" = Depends(get_task_service),
|
||||||
api_key_user: UserRead = Depends(api_key_security),
|
api_key_user: UserRead = Depends(api_key_security),
|
||||||
sync: Annotated[bool, Body(embed=True)] = True, # noqa: F821
|
sync: Annotated[bool, Body(embed=True)] = True, # noqa: F821
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import json
|
||||||
import re
|
import re
|
||||||
import zipfile
|
import zipfile
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
|
|
@ -273,7 +272,7 @@ def delete_flow(
|
||||||
return {"message": "Flow deleted successfully"}
|
return {"message": "Flow deleted successfully"}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/batch/", response_model=List[FlowRead], status_code=201)
|
@router.post("/batch/", response_model=list[FlowRead], status_code=201)
|
||||||
def create_flows(
|
def create_flows(
|
||||||
*,
|
*,
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
|
|
@ -293,7 +292,7 @@ def create_flows(
|
||||||
return db_flows
|
return db_flows
|
||||||
|
|
||||||
|
|
||||||
@router.post("/upload/", response_model=List[FlowRead], status_code=201)
|
@router.post("/upload/", response_model=list[FlowRead], status_code=201)
|
||||||
async def upload_file(
|
async def upload_file(
|
||||||
*,
|
*,
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
|
|
@ -322,7 +321,7 @@ async def upload_file(
|
||||||
|
|
||||||
@router.delete("/")
|
@router.delete("/")
|
||||||
async def delete_multiple_flows(
|
async def delete_multiple_flows(
|
||||||
flow_ids: List[UUID], user: User = Depends(get_current_active_user), db: Session = Depends(get_session)
|
flow_ids: list[UUID], user: User = Depends(get_current_active_user), db: Session = Depends(get_session)
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Delete multiple flows by their IDs.
|
Delete multiple flows by their IDs.
|
||||||
|
|
@ -357,7 +356,7 @@ async def delete_multiple_flows(
|
||||||
|
|
||||||
@router.post("/download/", status_code=200)
|
@router.post("/download/", status_code=200)
|
||||||
async def download_multiple_file(
|
async def download_multiple_file(
|
||||||
flow_ids: List[UUID],
|
flow_ids: list[UUID],
|
||||||
user: User = Depends(get_current_active_user),
|
user: User = Depends(get_current_active_user),
|
||||||
db: Session = Depends(get_session),
|
db: Session = Depends(get_session),
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
from fastapi import APIRouter, Depends, File, HTTPException, Response, UploadFile, status
|
from fastapi import APIRouter, Depends, File, HTTPException, Response, UploadFile, status
|
||||||
from sqlalchemy import or_, update
|
from sqlalchemy import or_, update
|
||||||
|
|
@ -78,7 +76,7 @@ def create_folder(
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=List[FolderRead], status_code=200)
|
@router.get("/", response_model=list[FolderRead], status_code=200)
|
||||||
def read_folders(
|
def read_folders(
|
||||||
*,
|
*,
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
|
|
@ -211,7 +209,7 @@ async def download_file(
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.post("/upload/", response_model=List[FlowRead], status_code=201)
|
@router.post("/upload/", response_model=list[FlowRead], status_code=201)
|
||||||
async def upload_file(
|
async def upload_file(
|
||||||
*,
|
*,
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from typing import List, Optional
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
|
|
@ -44,13 +43,13 @@ async def delete_vertex_builds(
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/messages", response_model=List[MessageModelResponse])
|
@router.get("/messages", response_model=list[MessageModelResponse])
|
||||||
async def get_messages(
|
async def get_messages(
|
||||||
flow_id: Optional[str] = Query(None),
|
flow_id: str | None = Query(None),
|
||||||
session_id: Optional[str] = Query(None),
|
session_id: str | None = Query(None),
|
||||||
sender: Optional[str] = Query(None),
|
sender: str | None = Query(None),
|
||||||
sender_name: Optional[str] = Query(None),
|
sender_name: str | None = Query(None),
|
||||||
order_by: Optional[str] = Query("timestamp"),
|
order_by: str | None = Query("timestamp"),
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
|
@ -74,7 +73,7 @@ async def get_messages(
|
||||||
|
|
||||||
@router.delete("/messages", status_code=204)
|
@router.delete("/messages", status_code=204)
|
||||||
async def delete_messages(
|
async def delete_messages(
|
||||||
message_ids: List[UUID],
|
message_ids: list[UUID],
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
current_user: User = Depends(get_current_active_user),
|
current_user: User = Depends(get_current_active_user),
|
||||||
):
|
):
|
||||||
|
|
@ -125,7 +124,7 @@ async def delete_messages_session(
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/transactions", response_model=List[TransactionReadResponse])
|
@router.get("/transactions", response_model=list[TransactionReadResponse])
|
||||||
async def get_transactions(
|
async def get_transactions(
|
||||||
flow_id: UUID = Query(),
|
flow_id: UUID = Query(),
|
||||||
session: Session = Depends(get_session),
|
session: Session = Depends(get_session),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator, model_serializer
|
from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator, model_serializer
|
||||||
|
|
@ -28,7 +28,7 @@ class BuildStatus(Enum):
|
||||||
|
|
||||||
|
|
||||||
class TweaksRequest(BaseModel):
|
class TweaksRequest(BaseModel):
|
||||||
tweaks: Optional[Dict[str, Dict[str, Any]]] = Field(default_factory=dict)
|
tweaks: dict[str, dict[str, Any]] | None = Field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
class UpdateTemplateRequest(BaseModel):
|
class UpdateTemplateRequest(BaseModel):
|
||||||
|
|
@ -38,25 +38,25 @@ class UpdateTemplateRequest(BaseModel):
|
||||||
class TaskResponse(BaseModel):
|
class TaskResponse(BaseModel):
|
||||||
"""Task response schema."""
|
"""Task response schema."""
|
||||||
|
|
||||||
id: Optional[str] = Field(None)
|
id: str | None = Field(None)
|
||||||
href: Optional[str] = Field(None)
|
href: str | None = Field(None)
|
||||||
|
|
||||||
|
|
||||||
class ProcessResponse(BaseModel):
|
class ProcessResponse(BaseModel):
|
||||||
"""Process response schema."""
|
"""Process response schema."""
|
||||||
|
|
||||||
result: Any
|
result: Any
|
||||||
status: Optional[str] = None
|
status: str | None = None
|
||||||
task: Optional[TaskResponse] = None
|
task: TaskResponse | None = None
|
||||||
session_id: Optional[str] = None
|
session_id: str | None = None
|
||||||
backend: Optional[str] = None
|
backend: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class RunResponse(BaseModel):
|
class RunResponse(BaseModel):
|
||||||
"""Run response schema."""
|
"""Run response schema."""
|
||||||
|
|
||||||
outputs: Optional[List[RunOutputs]] = []
|
outputs: list[RunOutputs] | None = []
|
||||||
session_id: Optional[str] = None
|
session_id: str | None = None
|
||||||
|
|
||||||
@model_serializer(mode="plain")
|
@model_serializer(mode="plain")
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
|
|
@ -76,23 +76,23 @@ class RunResponse(BaseModel):
|
||||||
class PreloadResponse(BaseModel):
|
class PreloadResponse(BaseModel):
|
||||||
"""Preload response schema."""
|
"""Preload response schema."""
|
||||||
|
|
||||||
session_id: Optional[str] = None
|
session_id: str | None = None
|
||||||
is_clear: Optional[bool] = None
|
is_clear: bool | None = None
|
||||||
|
|
||||||
|
|
||||||
class TaskStatusResponse(BaseModel):
|
class TaskStatusResponse(BaseModel):
|
||||||
"""Task status response schema."""
|
"""Task status response schema."""
|
||||||
|
|
||||||
status: str
|
status: str
|
||||||
result: Optional[Any] = None
|
result: Any | None = None
|
||||||
|
|
||||||
|
|
||||||
class ChatMessage(BaseModel):
|
class ChatMessage(BaseModel):
|
||||||
"""Chat message schema."""
|
"""Chat message schema."""
|
||||||
|
|
||||||
is_bot: bool = False
|
is_bot: bool = False
|
||||||
message: Union[str, None, dict] = None
|
message: str | None | dict = None
|
||||||
chatKey: Optional[str] = None
|
chatKey: str | None = None
|
||||||
type: str = "human"
|
type: str = "human"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -138,19 +138,19 @@ class FileResponse(ChatMessage):
|
||||||
|
|
||||||
|
|
||||||
class FlowListCreate(BaseModel):
|
class FlowListCreate(BaseModel):
|
||||||
flows: List[FlowCreate]
|
flows: list[FlowCreate]
|
||||||
|
|
||||||
|
|
||||||
class FlowListIds(BaseModel):
|
class FlowListIds(BaseModel):
|
||||||
flow_ids: List[str]
|
flow_ids: list[str]
|
||||||
|
|
||||||
|
|
||||||
class FlowListRead(BaseModel):
|
class FlowListRead(BaseModel):
|
||||||
flows: List[FlowRead]
|
flows: list[FlowRead]
|
||||||
|
|
||||||
|
|
||||||
class FlowListReadWithFolderName(BaseModel):
|
class FlowListReadWithFolderName(BaseModel):
|
||||||
flows: List[FlowRead]
|
flows: list[FlowRead]
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ class StreamData(BaseModel):
|
||||||
class CustomComponentRequest(BaseModel):
|
class CustomComponentRequest(BaseModel):
|
||||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||||
code: str
|
code: str
|
||||||
frontend_node: Optional[dict] = None
|
frontend_node: dict | None = None
|
||||||
|
|
||||||
|
|
||||||
class CustomComponentResponse(BaseModel):
|
class CustomComponentResponse(BaseModel):
|
||||||
|
|
@ -191,7 +191,7 @@ class CustomComponentResponse(BaseModel):
|
||||||
|
|
||||||
class UpdateCustomComponentRequest(CustomComponentRequest):
|
class UpdateCustomComponentRequest(CustomComponentRequest):
|
||||||
field: str
|
field: str
|
||||||
field_value: Optional[Union[str, int, float, bool, dict, list]] = None
|
field_value: str | int | float | bool | dict | list | None = None
|
||||||
template: dict
|
template: dict
|
||||||
|
|
||||||
def get_template(self):
|
def get_template(self):
|
||||||
|
|
@ -204,16 +204,16 @@ class CustomComponentResponseError(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class ComponentListCreate(BaseModel):
|
class ComponentListCreate(BaseModel):
|
||||||
flows: List[FlowCreate]
|
flows: list[FlowCreate]
|
||||||
|
|
||||||
|
|
||||||
class ComponentListRead(BaseModel):
|
class ComponentListRead(BaseModel):
|
||||||
flows: List[FlowRead]
|
flows: list[FlowRead]
|
||||||
|
|
||||||
|
|
||||||
class UsersResponse(BaseModel):
|
class UsersResponse(BaseModel):
|
||||||
total_count: int
|
total_count: int
|
||||||
users: List[UserRead]
|
users: list[UserRead]
|
||||||
|
|
||||||
|
|
||||||
class ApiKeyResponse(BaseModel):
|
class ApiKeyResponse(BaseModel):
|
||||||
|
|
@ -227,7 +227,7 @@ class ApiKeyResponse(BaseModel):
|
||||||
class ApiKeysResponse(BaseModel):
|
class ApiKeysResponse(BaseModel):
|
||||||
total_count: int
|
total_count: int
|
||||||
user_id: UUID
|
user_id: UUID
|
||||||
api_keys: List[ApiKeyRead]
|
api_keys: list[ApiKeyRead]
|
||||||
|
|
||||||
|
|
||||||
class CreateApiKeyRequest(BaseModel):
|
class CreateApiKeyRequest(BaseModel):
|
||||||
|
|
@ -245,20 +245,20 @@ class ApiKeyCreateRequest(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class VerticesOrderResponse(BaseModel):
|
class VerticesOrderResponse(BaseModel):
|
||||||
ids: List[str]
|
ids: list[str]
|
||||||
run_id: UUID
|
run_id: UUID
|
||||||
vertices_to_run: List[str]
|
vertices_to_run: list[str]
|
||||||
|
|
||||||
|
|
||||||
class ResultDataResponse(BaseModel):
|
class ResultDataResponse(BaseModel):
|
||||||
results: Optional[Any] = Field(default_factory=dict)
|
results: Any | None = Field(default_factory=dict)
|
||||||
outputs: dict[str, OutputValue] = Field(default_factory=dict)
|
outputs: dict[str, OutputValue] = Field(default_factory=dict)
|
||||||
logs: dict[str, list[Log]] = Field(default_factory=dict)
|
logs: dict[str, list[Log]] = Field(default_factory=dict)
|
||||||
message: Optional[Any] = Field(default_factory=dict)
|
message: Any | None = Field(default_factory=dict)
|
||||||
artifacts: Optional[Any] = Field(default_factory=dict)
|
artifacts: Any | None = Field(default_factory=dict)
|
||||||
timedelta: Optional[float] = None
|
timedelta: float | None = None
|
||||||
duration: Optional[str] = None
|
duration: str | None = None
|
||||||
used_frozen_result: Optional[bool] = False
|
used_frozen_result: bool | None = False
|
||||||
|
|
||||||
@field_serializer("results")
|
@field_serializer("results")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -269,27 +269,27 @@ class ResultDataResponse(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class VertexBuildResponse(BaseModel):
|
class VertexBuildResponse(BaseModel):
|
||||||
id: Optional[str] = None
|
id: str | None = None
|
||||||
inactivated_vertices: Optional[List[str]] = None
|
inactivated_vertices: list[str] | None = None
|
||||||
next_vertices_ids: Optional[List[str]] = None
|
next_vertices_ids: list[str] | None = None
|
||||||
top_level_vertices: Optional[List[str]] = None
|
top_level_vertices: list[str] | None = None
|
||||||
valid: bool
|
valid: bool
|
||||||
params: Optional[Any] = Field(default_factory=dict)
|
params: Any | None = Field(default_factory=dict)
|
||||||
"""JSON string of the params."""
|
"""JSON string of the params."""
|
||||||
data: ResultDataResponse
|
data: ResultDataResponse
|
||||||
"""Mapping of vertex ids to result dict containing the param name and result value."""
|
"""Mapping of vertex ids to result dict containing the param name and result value."""
|
||||||
timestamp: Optional[datetime] = Field(default_factory=lambda: datetime.now(timezone.utc))
|
timestamp: datetime | None = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||||
"""Timestamp of the build."""
|
"""Timestamp of the build."""
|
||||||
|
|
||||||
|
|
||||||
class VerticesBuiltResponse(BaseModel):
|
class VerticesBuiltResponse(BaseModel):
|
||||||
vertices: List[VertexBuildResponse]
|
vertices: list[VertexBuildResponse]
|
||||||
|
|
||||||
|
|
||||||
class InputValueRequest(BaseModel):
|
class InputValueRequest(BaseModel):
|
||||||
components: Optional[List[str]] = []
|
components: list[str] | None = []
|
||||||
input_value: Optional[str] = None
|
input_value: str | None = None
|
||||||
type: Optional[InputType] = Field(
|
type: InputType | None = Field(
|
||||||
"any",
|
"any",
|
||||||
description="Defines on which components the input value should be applied. 'any' applies to all input components.",
|
description="Defines on which components the input value should be applied. 'any' applies to all input components.",
|
||||||
)
|
)
|
||||||
|
|
@ -313,15 +313,15 @@ class InputValueRequest(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class SimplifiedAPIRequest(BaseModel):
|
class SimplifiedAPIRequest(BaseModel):
|
||||||
input_value: Optional[str] = Field(default=None, description="The input value")
|
input_value: str | None = Field(default=None, description="The input value")
|
||||||
input_type: Optional[InputType] = Field(default="chat", description="The input type")
|
input_type: InputType | None = Field(default="chat", description="The input type")
|
||||||
output_type: Optional[OutputType] = Field(default="chat", description="The output type")
|
output_type: OutputType | None = Field(default="chat", description="The output type")
|
||||||
output_component: Optional[str] = Field(
|
output_component: str | None = Field(
|
||||||
default="",
|
default="",
|
||||||
description="If there are multiple output components, you can specify the component to get the output from.",
|
description="If there are multiple output components, you can specify the component to get the output from.",
|
||||||
)
|
)
|
||||||
tweaks: Optional[Tweaks] = Field(default=None, description="The tweaks")
|
tweaks: Tweaks | None = Field(default=None, description="The tweaks")
|
||||||
session_id: Optional[str] = Field(default=None, description="The session id")
|
session_id: str | None = Field(default=None, description="The session id")
|
||||||
|
|
||||||
|
|
||||||
# (alias) type ReactFlowJsonObject<NodeData = any, EdgeData = any> = {
|
# (alias) type ReactFlowJsonObject<NodeData = any, EdgeData = any> = {
|
||||||
|
|
@ -331,9 +331,9 @@ class SimplifiedAPIRequest(BaseModel):
|
||||||
# }
|
# }
|
||||||
# import ReactFlowJsonObject
|
# import ReactFlowJsonObject
|
||||||
class FlowDataRequest(BaseModel):
|
class FlowDataRequest(BaseModel):
|
||||||
nodes: List[dict]
|
nodes: list[dict]
|
||||||
edges: List[dict]
|
edges: list[dict]
|
||||||
viewport: Optional[dict] = None
|
viewport: dict | None = None
|
||||||
|
|
||||||
|
|
||||||
class ConfigResponse(BaseModel):
|
class ConfigResponse(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
|
@ -10,7 +8,7 @@ from langflow.services.database.models.user.model import User
|
||||||
router = APIRouter(prefix="/starter-projects", tags=["Flows"])
|
router = APIRouter(prefix="/starter-projects", tags=["Flows"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=List[GraphDump], status_code=200)
|
@router.get("/", response_model=list[GraphDump], status_code=200)
|
||||||
def get_starter_projects(
|
def get_starter_projects(
|
||||||
*,
|
*,
|
||||||
current_user: User = Depends(get_current_active_user),
|
current_user: User = Depends(get_current_active_user),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Annotated, List, Optional, Union
|
from typing import Annotated
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
|
|
@ -60,7 +60,7 @@ def check_if_store_is_enabled(
|
||||||
|
|
||||||
@router.get("/check/api_key")
|
@router.get("/check/api_key")
|
||||||
async def check_if_store_has_api_key(
|
async def check_if_store_has_api_key(
|
||||||
api_key: Optional[str] = Depends(get_optional_user_store_api_key),
|
api_key: str | None = Depends(get_optional_user_store_api_key),
|
||||||
store_service: StoreService = Depends(get_store_service),
|
store_service: StoreService = Depends(get_store_service),
|
||||||
):
|
):
|
||||||
if api_key is None:
|
if api_key is None:
|
||||||
|
|
@ -105,19 +105,19 @@ async def update_shared_component(
|
||||||
|
|
||||||
@router.get("/components/", response_model=ListComponentResponseModel)
|
@router.get("/components/", response_model=ListComponentResponseModel)
|
||||||
async def get_components(
|
async def get_components(
|
||||||
component_id: Annotated[Optional[str], Query()] = None,
|
component_id: Annotated[str | None, Query()] = None,
|
||||||
search: Annotated[Optional[str], Query()] = None,
|
search: Annotated[str | None, Query()] = None,
|
||||||
private: Annotated[Optional[bool], Query()] = None,
|
private: Annotated[bool | None, Query()] = None,
|
||||||
is_component: Annotated[Optional[bool], Query()] = None,
|
is_component: Annotated[bool | None, Query()] = None,
|
||||||
tags: Annotated[Optional[list[str]], Query()] = None,
|
tags: Annotated[list[str] | None, Query()] = None,
|
||||||
sort: Annotated[Union[list[str], None], Query()] = None,
|
sort: Annotated[list[str] | None, Query()] = None,
|
||||||
liked: Annotated[bool, Query()] = False,
|
liked: Annotated[bool, Query()] = False,
|
||||||
filter_by_user: Annotated[bool, Query()] = False,
|
filter_by_user: Annotated[bool, Query()] = False,
|
||||||
fields: Annotated[Optional[list[str]], Query()] = None,
|
fields: Annotated[list[str] | None, Query()] = None,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
store_service: StoreService = Depends(get_store_service),
|
store_service: StoreService = Depends(get_store_service),
|
||||||
store_api_key: Optional[str] = Depends(get_optional_user_store_api_key),
|
store_api_key: str | None = Depends(get_optional_user_store_api_key),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
return await store_service.get_list_component_response_model(
|
return await store_service.get_list_component_response_model(
|
||||||
|
|
@ -159,7 +159,7 @@ async def download_component(
|
||||||
return component
|
return component
|
||||||
|
|
||||||
|
|
||||||
@router.get("/tags", response_model=List[TagResponse])
|
@router.get("/tags", response_model=list[TagResponse])
|
||||||
async def get_tags(
|
async def get_tags(
|
||||||
store_service: StoreService = Depends(get_store_service),
|
store_service: StoreService = Depends(get_store_service),
|
||||||
):
|
):
|
||||||
|
|
@ -171,7 +171,7 @@ async def get_tags(
|
||||||
raise HTTPException(status_code=500, detail=str(exc))
|
raise HTTPException(status_code=500, detail=str(exc))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/users/likes", response_model=List[UsersLikesResponse])
|
@router.get("/users/likes", response_model=list[UsersLikesResponse])
|
||||||
async def get_list_of_components_liked_by_user(
|
async def get_list_of_components_liked_by_user(
|
||||||
store_service: StoreService = Depends(get_store_service),
|
store_service: StoreService = Depends(get_store_service),
|
||||||
store_api_key: str = Depends(get_user_store_api_key),
|
store_api_key: str = Depends(get_user_store_api_key),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue