Add support for input values in build_vertex API
This commit is contained in:
parent
8aaa0ee91a
commit
f09ebeba34
3 changed files with 21 additions and 6 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Annotated, Optional
|
||||||
|
|
||||||
from fastapi import (
|
from fastapi import (
|
||||||
APIRouter,
|
APIRouter,
|
||||||
BackgroundTasks,
|
BackgroundTasks,
|
||||||
|
Body,
|
||||||
Depends,
|
Depends,
|
||||||
HTTPException,
|
HTTPException,
|
||||||
WebSocket,
|
WebSocket,
|
||||||
|
|
@ -21,6 +22,7 @@ from langflow.api.utils import (
|
||||||
format_exception_message,
|
format_exception_message,
|
||||||
)
|
)
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (
|
||||||
|
InputValueRequest,
|
||||||
ResultDataResponse,
|
ResultDataResponse,
|
||||||
StreamData,
|
StreamData,
|
||||||
VertexBuildResponse,
|
VertexBuildResponse,
|
||||||
|
|
@ -139,10 +141,12 @@ async def build_vertex(
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
vertex_id: str,
|
vertex_id: str,
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
|
inputs: Annotated[InputValueRequest, Body(embed=True)] = 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),
|
||||||
):
|
):
|
||||||
"""Build a vertex instead of the entire graph."""
|
"""Build a vertex instead of the entire graph."""
|
||||||
|
{"inputs": {"input_value": "some value"}}
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
try:
|
try:
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|
@ -163,7 +167,7 @@ async def build_vertex(
|
||||||
vertex = graph.get_vertex(vertex_id)
|
vertex = graph.get_vertex(vertex_id)
|
||||||
try:
|
try:
|
||||||
if not vertex.pinned or not vertex._built:
|
if not vertex.pinned or not vertex._built:
|
||||||
await vertex.build(user_id=current_user.id)
|
await vertex.build(user_id=current_user.id, inputs=inputs.model_dump())
|
||||||
|
|
||||||
if vertex.result is not None:
|
if vertex.result is not None:
|
||||||
params = vertex._built_object_repr()
|
params = vertex._built_object_repr()
|
||||||
|
|
|
||||||
|
|
@ -261,3 +261,7 @@ class VertexBuildResponse(BaseModel):
|
||||||
|
|
||||||
class VerticesBuiltResponse(BaseModel):
|
class VerticesBuiltResponse(BaseModel):
|
||||||
vertices: List[VertexBuildResponse]
|
vertices: List[VertexBuildResponse]
|
||||||
|
|
||||||
|
|
||||||
|
class InputValueRequest(BaseModel):
|
||||||
|
input_value: str
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,16 @@ import ast
|
||||||
import inspect
|
import inspect
|
||||||
import types
|
import types
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import (TYPE_CHECKING, Any, Callable, Coroutine, Dict, List,
|
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Dict, List, Optional
|
||||||
Optional)
|
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from langflow.graph.schema import (INPUT_COMPONENTS, OUTPUT_COMPONENTS,
|
from langflow.graph.schema import (
|
||||||
InterfaceComponentTypes, ResultData)
|
INPUT_COMPONENTS,
|
||||||
|
OUTPUT_COMPONENTS,
|
||||||
|
InterfaceComponentTypes,
|
||||||
|
ResultData,
|
||||||
|
)
|
||||||
from langflow.graph.utils import UnbuiltObject, UnbuiltResult
|
from langflow.graph.utils import UnbuiltObject, UnbuiltResult
|
||||||
from langflow.graph.vertex.utils import generate_result
|
from langflow.graph.vertex.utils import generate_result
|
||||||
from langflow.interface.initialize import loading
|
from langflow.interface.initialize import loading
|
||||||
|
|
@ -608,6 +611,7 @@ class Vertex:
|
||||||
async def build(
|
async def build(
|
||||||
self,
|
self,
|
||||||
user_id=None,
|
user_id=None,
|
||||||
|
inputs: Optional[Dict[str, Any]] = None,
|
||||||
requester: Optional["Vertex"] = None,
|
requester: Optional["Vertex"] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
|
|
@ -620,6 +624,9 @@ class Vertex:
|
||||||
return self.get_requester_result(requester)
|
return self.get_requester_result(requester)
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
|
if inputs and self.is_input:
|
||||||
|
self.update_raw_params(inputs)
|
||||||
|
|
||||||
# Run steps
|
# Run steps
|
||||||
for step in self.steps:
|
for step in self.steps:
|
||||||
if step not in self.steps_ran:
|
if step not in self.steps_ran:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue