diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 99769517a..bc6604089 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -74,9 +74,11 @@ async def simplified_run_flow( - `input_value` (Optional[str], default=""): Input value to pass to the flow. - `input_type` (Optional[Literal["chat", "text", "any"]], default="chat"): Type of the input value, determining how the input is interpreted. - `output_type` (Optional[Literal["chat", "text", "any", "debug"]], default="chat"): Desired type of output, affecting which components' outputs are included in the response. If set to "debug", all outputs are returned. + - `output_component` (Optional[str], default=None): Specific component output to retrieve. If provided, only the output of the specified component is returned. This overrides the `output_type` parameter. - `tweaks` (Optional[Tweaks], default=None): Adjustments to the flow's behavior, allowing for custom execution parameters. - `session_id` (Optional[str], default=None): An identifier for reusing session data, aiding in performance for subsequent requests. + ### Tweaks A dictionary of tweaks to customize the flow execution. The tweaks can be used to modify the flow's parameters and components. Tweaks can be overridden by the input values. You can use Component's `id` or Display Name as key to tweak a specific component (e.g., `{"Component Name": {"parameter_name": "value"}}`). @@ -135,15 +137,18 @@ async def simplified_run_flow( # if the output type is debug, we return all outputs # if the output type is any, we return all outputs that are either chat or text # if the output type is chat or text, we return only the outputs that match the type - outputs = [ - vertex.id - for vertex in graph.vertices - if input_request.output_type == "debug" - or ( - vertex.is_output - and (input_request.output_type == "any" or input_request.output_type in vertex.id.lower()) - ) - ] + if input_request.output_component: + outputs = [input_request.output_component] + else: + outputs = [ + vertex.id + for vertex in graph.vertices + if input_request.output_type == "debug" + or ( + vertex.is_output + and (input_request.output_type == "any" or input_request.output_type in vertex.id.lower()) + ) + ] task_result, session_id = await run_graph( graph=graph, flow_id=flow_id, diff --git a/src/backend/base/langflow/api/v1/schemas.py b/src/backend/base/langflow/api/v1/schemas.py index bd6adb3a6..631c37fbb 100644 --- a/src/backend/base/langflow/api/v1/schemas.py +++ b/src/backend/base/langflow/api/v1/schemas.py @@ -1,7 +1,7 @@ from datetime import datetime from enum import Enum from pathlib import Path -from typing import Any, Dict, List, Literal, Optional, Union +from typing import Any, Dict, List, Optional, Union from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_serializer @@ -9,7 +9,6 @@ from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, m from langflow.graph.schema import RunOutputs from langflow.schema import dotdict from langflow.schema.schema import InputType, OutputType -from langflow.schema.schema import InputType, OutputType from langflow.services.database.models.api_key.model import ApiKeyRead from langflow.services.database.models.base import orjson_dumps from langflow.services.database.models.flow import FlowCreate, FlowRead @@ -318,5 +317,9 @@ class SimplifiedAPIRequest(BaseModel): input_value: Optional[str] = Field(default="", description="The input value") input_type: Optional[InputType] = Field(default="chat", description="The input type") output_type: Optional[OutputType] = Field(default="chat", description="The output type") + output_component: Optional[str] = Field( + default="", + 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") session_id: Optional[str] = Field(default=None, description="The session id")