Skip to content

refactor: update Output definitions to remove incorrectly passed parameters #7334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/apify/apify_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class ApifyActorsComponent(Component):
]

outputs = [
Output(display_name="Output", name="output", type_=list[Data], method="run_model"),
Output(display_name="Tool", name="tool", type_=Tool, method="build_tool"),
Output(display_name="Output", name="output", method="run_model"),
Output(display_name="Tool", name="tool", method="build_tool"),
]

def __init__(self, *args, **kwargs) -> None:
Expand Down
1 change: 0 additions & 1 deletion src/backend/base/langflow/components/helpers/batch_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class BatchRunComponent(Component):
display_name="DataFrame",
name="batch_results",
method="run_batch",
info="A DataFrame with all original columns plus the model's response column.",
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class OutputParserComponent(Component):
Output(
display_name="Format Instructions",
name="format_instructions",
info="Pass to a prompt template to include formatting instructions for LLM responses.",
method="format_instructions",
),
Output(display_name="Output Parser", name="output_parser", method="build_parser"),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/components/needle/needle.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class NeedleComponent(Component):
),
]

outputs = [Output(display_name="Result", name="result", type_="Message", method="run")]
outputs = [Output(display_name="Result", name="result", method="run")]

def run(self) -> Message:
# Extract query and top_k
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ class AlterMetadataComponent(Component):
Output(
name="data",
display_name="Data",
info="List of Input objects each with added Metadata",
method="process_output",
),
Output(
display_name="DataFrame",
name="dataframe",
info="Data objects as a DataFrame, with metadata as columns",
method="as_dataframe",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DataToDataFrameComponent(Component):
display_name="DataFrame",
name="dataframe",
method="build_dataframe",
info="A DataFrame built from each Data object's fields plus a 'text' column.",
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class DataFrameOperationsComponent(Component):
display_name="DataFrame",
name="output",
method="perform_operation",
info="The resulting DataFrame after the operation.",
)
]

Expand Down
2 changes: 0 additions & 2 deletions src/backend/base/langflow/components/processing/parse_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ class ParseDataComponent(Component):
Output(
display_name="Message",
name="text",
info="Data as a single Message, with each input Data separated by Separator",
method="parse_data",
),
Output(
display_name="Data List",
name="data_list",
info="Data as a list of new Data, each having `text` formatted by Template",
method="parse_data_as_list",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ParseDataFrameComponent(Component):
Output(
display_name="Text",
name="text",
info="All rows combined into a single text, each row formatted by the template and separated by `sep`.",
method="parse_data",
),
]
Expand Down
1 change: 0 additions & 1 deletion src/backend/base/langflow/components/processing/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ParserComponent(Component):
Output(
display_name="Parsed Text",
name="parsed_text",
info="Formatted text output.",
method="parse_combined_text",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class SaveToFileComponent(Component):
name="confirmation",
display_name="Confirmation",
method="save_to_file",
info="Confirmation message after saving the file.",
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CalculatorComponent(Component):
]

outputs = [
Output(display_name="Data", name="result", type_=Data, method="evaluate_expression"),
Output(display_name="Data", name="result", method="evaluate_expression"),
]

def _eval_expr(self, node: ast.AST) -> float:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class GoogleSearchAPICore(Component):
Output(
display_name="Results",
name="results",
type_=DataFrame,
method="search_google",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class GoogleSerperAPICore(Component):
Output(
display_name="Results",
name="results",
type_=DataFrame,
method="search_serper",
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PythonREPLComponent(Component):
Output(
display_name="Results",
name="results",
type_=Data,
method="run_python_repl",
),
]
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@
"show": true,
"title_case": false,
"type": "code",
"value": "from langchain_community.retrievers.needle import NeedleRetriever\n\nfrom langflow.custom.custom_component.component import Component\nfrom langflow.io import IntInput, MessageTextInput, Output, SecretStrInput\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import MESSAGE_SENDER_AI\n\n\nclass NeedleComponent(Component):\n display_name = \"Needle Retriever\"\n description = \"A retriever that uses the Needle API to search collections.\"\n documentation = \"https://docs.needle-ai.com\"\n icon = \"Needle\"\n name = \"needle\"\n\n inputs = [\n SecretStrInput(\n name=\"needle_api_key\",\n display_name=\"Needle API Key\",\n info=\"Your Needle API key.\",\n required=True,\n ),\n MessageTextInput(\n name=\"collection_id\",\n display_name=\"Collection ID\",\n info=\"The ID of the Needle collection.\",\n required=True,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"User Query\",\n info=\"Enter your question here. In tool mode, you can also specify top_k parameter (min: 20).\",\n required=True,\n tool_mode=True,\n ),\n IntInput(\n name=\"top_k\",\n display_name=\"Top K Results\",\n info=\"Number of search results to return (min: 20).\",\n value=20,\n required=True,\n ),\n ]\n\n outputs = [Output(display_name=\"Result\", name=\"result\", type_=\"Message\", method=\"run\")]\n\n def run(self) -> Message:\n # Extract query and top_k\n query_input = self.query\n actual_query = query_input.get(\"query\", \"\") if isinstance(query_input, dict) else query_input\n\n # Parse top_k from tool input or use default, always enforcing minimum of 20\n try:\n if isinstance(query_input, dict) and \"top_k\" in query_input:\n agent_top_k = query_input.get(\"top_k\")\n # Check if agent_top_k is not None before converting to int\n top_k = max(20, int(agent_top_k)) if agent_top_k is not None else max(20, self.top_k)\n else:\n top_k = max(20, self.top_k)\n except (ValueError, TypeError):\n top_k = max(20, self.top_k)\n\n # Validate required inputs\n if not self.needle_api_key or not self.needle_api_key.strip():\n error_msg = \"The Needle API key cannot be empty.\"\n raise ValueError(error_msg)\n if not self.collection_id or not self.collection_id.strip():\n error_msg = \"The Collection ID cannot be empty.\"\n raise ValueError(error_msg)\n if not actual_query or not actual_query.strip():\n error_msg = \"The query cannot be empty.\"\n raise ValueError(error_msg)\n\n try:\n # Initialize the retriever and get documents\n retriever = NeedleRetriever(\n needle_api_key=self.needle_api_key,\n collection_id=self.collection_id,\n top_k=top_k,\n )\n\n docs = retriever.get_relevant_documents(actual_query)\n\n # Format the response\n if not docs:\n text_content = \"No relevant documents found for the query.\"\n else:\n context = \"\\n\\n\".join([f\"Document {i + 1}:\\n{doc.page_content}\" for i, doc in enumerate(docs)])\n text_content = f\"Question: {actual_query}\\n\\nContext:\\n{context}\"\n\n # Return formatted message\n return Message(\n text=text_content,\n type=\"assistant\",\n sender=MESSAGE_SENDER_AI,\n additional_kwargs={\n \"source_documents\": [{\"page_content\": doc.page_content, \"metadata\": doc.metadata} for doc in docs],\n \"top_k_used\": top_k,\n },\n )\n\n except Exception as e:\n error_msg = f\"Error processing query: {e!s}\"\n raise ValueError(error_msg) from e\n"
"value": "from langchain_community.retrievers.needle import NeedleRetriever\n\nfrom langflow.custom.custom_component.component import Component\nfrom langflow.io import IntInput, MessageTextInput, Output, SecretStrInput\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import MESSAGE_SENDER_AI\n\n\nclass NeedleComponent(Component):\n display_name = \"Needle Retriever\"\n description = \"A retriever that uses the Needle API to search collections.\"\n documentation = \"https://docs.needle-ai.com\"\n icon = \"Needle\"\n name = \"needle\"\n\n inputs = [\n SecretStrInput(\n name=\"needle_api_key\",\n display_name=\"Needle API Key\",\n info=\"Your Needle API key.\",\n required=True,\n ),\n MessageTextInput(\n name=\"collection_id\",\n display_name=\"Collection ID\",\n info=\"The ID of the Needle collection.\",\n required=True,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"User Query\",\n info=\"Enter your question here. In tool mode, you can also specify top_k parameter (min: 20).\",\n required=True,\n tool_mode=True,\n ),\n IntInput(\n name=\"top_k\",\n display_name=\"Top K Results\",\n info=\"Number of search results to return (min: 20).\",\n value=20,\n required=True,\n ),\n ]\n\n outputs = [Output(display_name=\"Result\", name=\"result\", method=\"run\")]\n\n def run(self) -> Message:\n # Extract query and top_k\n query_input = self.query\n actual_query = query_input.get(\"query\", \"\") if isinstance(query_input, dict) else query_input\n\n # Parse top_k from tool input or use default, always enforcing minimum of 20\n try:\n if isinstance(query_input, dict) and \"top_k\" in query_input:\n agent_top_k = query_input.get(\"top_k\")\n # Check if agent_top_k is not None before converting to int\n top_k = max(20, int(agent_top_k)) if agent_top_k is not None else max(20, self.top_k)\n else:\n top_k = max(20, self.top_k)\n except (ValueError, TypeError):\n top_k = max(20, self.top_k)\n\n # Validate required inputs\n if not self.needle_api_key or not self.needle_api_key.strip():\n error_msg = \"The Needle API key cannot be empty.\"\n raise ValueError(error_msg)\n if not self.collection_id or not self.collection_id.strip():\n error_msg = \"The Collection ID cannot be empty.\"\n raise ValueError(error_msg)\n if not actual_query or not actual_query.strip():\n error_msg = \"The query cannot be empty.\"\n raise ValueError(error_msg)\n\n try:\n # Initialize the retriever and get documents\n retriever = NeedleRetriever(\n needle_api_key=self.needle_api_key,\n collection_id=self.collection_id,\n top_k=top_k,\n )\n\n docs = retriever.get_relevant_documents(actual_query)\n\n # Format the response\n if not docs:\n text_content = \"No relevant documents found for the query.\"\n else:\n context = \"\\n\\n\".join([f\"Document {i + 1}:\\n{doc.page_content}\" for i, doc in enumerate(docs)])\n text_content = f\"Question: {actual_query}\\n\\nContext:\\n{context}\"\n\n # Return formatted message\n return Message(\n text=text_content,\n type=\"assistant\",\n sender=MESSAGE_SENDER_AI,\n additional_kwargs={\n \"source_documents\": [{\"page_content\": doc.page_content, \"metadata\": doc.metadata} for doc in docs],\n \"top_k_used\": top_k,\n },\n )\n\n except Exception as e:\n error_msg = f\"Error processing query: {e!s}\"\n raise ValueError(error_msg) from e\n"
},
"collection_id": {
"_input_type": "MessageTextInput",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
"show": true,
"title_case": false,
"type": "code",
"value": "from langflow.custom import Component\nfrom langflow.helpers.data import data_to_text, data_to_text_list\nfrom langflow.io import DataInput, MultilineInput, Output, StrInput\nfrom langflow.schema import Data\nfrom langflow.schema.message import Message\n\n\nclass ParseDataComponent(Component):\n display_name = \"Data to Message\"\n description = \"Convert Data objects into Messages using any {field_name} from input data.\"\n icon = \"message-square\"\n name = \"ParseData\"\n legacy = True\n metadata = {\n \"legacy_name\": \"Parse Data\",\n }\n\n inputs = [\n DataInput(\n name=\"data\",\n display_name=\"Data\",\n info=\"The data to convert to text.\",\n is_list=True,\n required=True,\n ),\n MultilineInput(\n name=\"template\",\n display_name=\"Template\",\n info=\"The template to use for formatting the data. \"\n \"It can contain the keys {text}, {data} or any other key in the Data.\",\n value=\"{text}\",\n required=True,\n ),\n StrInput(name=\"sep\", display_name=\"Separator\", advanced=True, value=\"\\n\"),\n ]\n\n outputs = [\n Output(\n display_name=\"Message\",\n name=\"text\",\n info=\"Data as a single Message, with each input Data separated by Separator\",\n method=\"parse_data\",\n ),\n Output(\n display_name=\"Data List\",\n name=\"data_list\",\n info=\"Data as a list of new Data, each having `text` formatted by Template\",\n method=\"parse_data_as_list\",\n ),\n ]\n\n def _clean_args(self) -> tuple[list[Data], str, str]:\n data = self.data if isinstance(self.data, list) else [self.data]\n template = self.template\n sep = self.sep\n return data, template, sep\n\n def parse_data(self) -> Message:\n data, template, sep = self._clean_args()\n result_string = data_to_text(template, data, sep)\n self.status = result_string\n return Message(text=result_string)\n\n def parse_data_as_list(self) -> list[Data]:\n data, template, _ = self._clean_args()\n text_list, data_list = data_to_text_list(template, data)\n for item, text in zip(data_list, text_list, strict=True):\n item.set_text(text)\n self.status = data_list\n return data_list\n"
"value": "from langflow.custom import Component\nfrom langflow.helpers.data import data_to_text, data_to_text_list\nfrom langflow.io import DataInput, MultilineInput, Output, StrInput\nfrom langflow.schema import Data\nfrom langflow.schema.message import Message\n\n\nclass ParseDataComponent(Component):\n display_name = \"Data to Message\"\n description = \"Convert Data objects into Messages using any {field_name} from input data.\"\n icon = \"message-square\"\n name = \"ParseData\"\n legacy = True\n metadata = {\n \"legacy_name\": \"Parse Data\",\n }\n\n inputs = [\n DataInput(\n name=\"data\",\n display_name=\"Data\",\n info=\"The data to convert to text.\",\n is_list=True,\n required=True,\n ),\n MultilineInput(\n name=\"template\",\n display_name=\"Template\",\n info=\"The template to use for formatting the data. \"\n \"It can contain the keys {text}, {data} or any other key in the Data.\",\n value=\"{text}\",\n required=True,\n ),\n StrInput(name=\"sep\", display_name=\"Separator\", advanced=True, value=\"\\n\"),\n ]\n\n outputs = [\n Output(\n display_name=\"Message\",\n name=\"text\",\n method=\"parse_data\",\n ),\n Output(\n display_name=\"Data List\",\n name=\"data_list\",\n method=\"parse_data_as_list\",\n ),\n ]\n\n def _clean_args(self) -> tuple[list[Data], str, str]:\n data = self.data if isinstance(self.data, list) else [self.data]\n template = self.template\n sep = self.sep\n return data, template, sep\n\n def parse_data(self) -> Message:\n data, template, sep = self._clean_args()\n result_string = data_to_text(template, data, sep)\n self.status = result_string\n return Message(text=result_string)\n\n def parse_data_as_list(self) -> list[Data]:\n data, template, _ = self._clean_args()\n text_list, data_list = data_to_text_list(template, data)\n for item, text in zip(data_list, text_list, strict=True):\n item.set_text(text)\n self.status = data_list\n return data_list\n"
},
"data": {
"_input_type": "DataInput",
Expand Down
Loading
Loading