Refactor API endpoints and schemas
This commit is contained in:
parent
e1ded9c106
commit
6b66834990
3 changed files with 38 additions and 20 deletions
|
|
@ -7,28 +7,20 @@ from loguru import logger
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
|
||||||
from langflow.api.utils import update_frontend_node_with_template_values
|
from langflow.api.utils import update_frontend_node_with_template_values
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (CustomComponentCode, InputValueRequest,
|
||||||
CustomComponentCode,
|
ProcessResponse, RunResponse,
|
||||||
InputValueRequest,
|
TaskStatusResponse, UploadFileResponse)
|
||||||
ProcessResponse,
|
|
||||||
RunResponse,
|
|
||||||
TaskStatusResponse,
|
|
||||||
UploadFileResponse,
|
|
||||||
)
|
|
||||||
from langflow.interface.custom.custom_component import CustomComponent
|
from langflow.interface.custom.custom_component import CustomComponent
|
||||||
from langflow.interface.custom.directory_reader import DirectoryReader
|
from langflow.interface.custom.directory_reader import DirectoryReader
|
||||||
from langflow.interface.custom.utils import build_custom_component_template
|
from langflow.interface.custom.utils import build_custom_component_template
|
||||||
from langflow.processing.process import process_tweaks, run_graph
|
from langflow.processing.process import process_tweaks, run_graph
|
||||||
from langflow.services.auth.utils import api_key_security, get_current_active_user
|
from langflow.services.auth.utils import (api_key_security,
|
||||||
|
get_current_active_user)
|
||||||
from langflow.services.cache.utils import save_uploaded_file
|
from langflow.services.cache.utils import save_uploaded_file
|
||||||
from langflow.services.database.models.flow import Flow
|
from langflow.services.database.models.flow import Flow
|
||||||
from langflow.services.database.models.user.model import User
|
from langflow.services.database.models.user.model import User
|
||||||
from langflow.services.deps import (
|
from langflow.services.deps import (get_session, get_session_service,
|
||||||
get_session,
|
get_settings_service, get_task_service)
|
||||||
get_session_service,
|
|
||||||
get_settings_service,
|
|
||||||
get_task_service,
|
|
||||||
)
|
|
||||||
from langflow.services.session.service import SessionService
|
from langflow.services.session.service import SessionService
|
||||||
from langflow.services.task.service import TaskService
|
from langflow.services.task.service import TaskService
|
||||||
|
|
||||||
|
|
@ -56,7 +48,7 @@ def get_all(
|
||||||
async def run_flow_with_caching(
|
async def run_flow_with_caching(
|
||||||
session: Annotated[Session, Depends(get_session)],
|
session: Annotated[Session, Depends(get_session)],
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
inputs: Optional[InputValueRequest] = None,
|
inputs: Optional[List[InputValueRequest]] = None,
|
||||||
outputs: Optional[List[str]] = None,
|
outputs: Optional[List[str]] = None,
|
||||||
tweaks: Optional[dict] = None,
|
tweaks: Optional[dict] = None,
|
||||||
stream: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
stream: Annotated[bool, Body(embed=True)] = False, # noqa: F821
|
||||||
|
|
|
||||||
|
|
@ -245,4 +245,19 @@ class VerticesBuiltResponse(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class InputValueRequest(BaseModel):
|
class InputValueRequest(BaseModel):
|
||||||
input_value: str
|
components: Optional[List[str]] = None
|
||||||
|
input_value: Optional[List[str]] = None
|
||||||
|
|
||||||
|
# add an example
|
||||||
|
model_config = {
|
||||||
|
"json_schema_extra": {
|
||||||
|
"examples": [
|
||||||
|
{"components": ["components_id"], "input_value": ["input_value"]},
|
||||||
|
{"components": ["Component Name"], "input_value": ["input_value"]},
|
||||||
|
{"input_value": ["input_value"]},
|
||||||
|
{
|
||||||
|
"input_value": ["input_value1", "input_value2"],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,11 +151,21 @@ class Graph:
|
||||||
getattr(self, f"_{attribute}_vertices").append(vertex.id)
|
getattr(self, f"_{attribute}_vertices").append(vertex.id)
|
||||||
|
|
||||||
async def _run(
|
async def _run(
|
||||||
self, inputs: Dict[str, str], outputs: list[str], stream: bool, session_id: str
|
self,
|
||||||
|
inputs: Dict[str, str],
|
||||||
|
input_components: list[str],
|
||||||
|
outputs: list[str],
|
||||||
|
stream: bool,
|
||||||
|
session_id: str,
|
||||||
) -> List[Optional["ResultData"]]:
|
) -> List[Optional["ResultData"]]:
|
||||||
"""Runs the graph with the given inputs."""
|
"""Runs the graph with the given inputs."""
|
||||||
for vertex_id in self._is_input_vertices:
|
for vertex_id in self._is_input_vertices:
|
||||||
vertex = self.get_vertex(vertex_id)
|
vertex = self.get_vertex(vertex_id)
|
||||||
|
if input_components and (
|
||||||
|
vertex_id not in input_components
|
||||||
|
or vertex.display_name not in input_components
|
||||||
|
):
|
||||||
|
continue
|
||||||
if vertex is None:
|
if vertex is None:
|
||||||
raise ValueError(f"Vertex {vertex_id} not found")
|
raise ValueError(f"Vertex {vertex_id} not found")
|
||||||
vertex.update_raw_params(inputs, overwrite=True)
|
vertex.update_raw_params(inputs, overwrite=True)
|
||||||
|
|
@ -206,8 +216,9 @@ class Graph:
|
||||||
inputs_values = [inputs_values]
|
inputs_values = [inputs_values]
|
||||||
for input_value in inputs_values:
|
for input_value in inputs_values:
|
||||||
run_outputs = await self._run(
|
run_outputs = await self._run(
|
||||||
{INPUT_FIELD_NAME: input_value},
|
inputs={INPUT_FIELD_NAME: input_value},
|
||||||
outputs,
|
input_components=inputs.get("components", []),
|
||||||
|
outputs=outputs,
|
||||||
stream=stream,
|
stream=stream,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue