diff --git a/docs/package-lock.json b/docs/package-lock.json
index 36d3f0c4d5e..8505f4c706a 100644
--- a/docs/package-lock.json
+++ b/docs/package-lock.json
@@ -20,6 +20,7 @@
"clsx": "^1.2.1",
"docusaurus-node-polyfills": "^1.0.0",
"docusaurus-plugin-image-zoom": "^2.0.0",
+ "lucide-react": "^0.460.0",
"prism-react-renderer": "^1.3.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
@@ -12179,6 +12180,14 @@
"yallist": "^2.1.2"
}
},
+ "node_modules/lucide-react": {
+ "version": "0.460.0",
+ "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.460.0.tgz",
+ "integrity": "sha512-BVtq/DykVeIvRTJvRAgCsOwaGL8Un3Bxh8MbDxMhEWlZay3T4IpEKDEpwt5KZ0KJMHzgm6jrltxlT5eXOWXDHg==",
+ "peerDependencies": {
+ "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc"
+ }
+ },
"node_modules/lunr": {
"version": "2.3.9",
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz",
diff --git a/docs/yarn.lock b/docs/yarn.lock
index 8bc1868177e..8417a0e51e8 100644
--- a/docs/yarn.lock
+++ b/docs/yarn.lock
@@ -7279,6 +7279,11 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"
+lucide-react@^0.460.0:
+ version "0.460.0"
+ resolved "https://registry.npmjs.org/lucide-react/-/lucide-react-0.460.0.tgz"
+ integrity sha512-BVtq/DykVeIvRTJvRAgCsOwaGL8Un3Bxh8MbDxMhEWlZay3T4IpEKDEpwt5KZ0KJMHzgm6jrltxlT5eXOWXDHg==
+
lunr-languages@^1.4.0:
version "1.14.0"
resolved "https://registry.npmjs.org/lunr-languages/-/lunr-languages-1.14.0.tgz"
@@ -9474,7 +9479,7 @@ react-router@^5.3.4, react-router@>=5, react-router@5.3.4:
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"
-react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.14.0 || ^17 || ^18", "react@^16.6.0 || ^17.0.0 || ^18.0.0", "react@^16.8.3 || ^17 || ^18", "react@^17.x || ^18.x", react@^18.0.0, react@^18.2.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=0.14.9, react@>=15, react@>=16, react@>=16.0.0, react@>=16.6.0, "react@0.14 || 15 || 16 || 17 || 18":
+react@*, "react@^16.13.1 || ^17.0.0 || ^18.0.0", "react@^16.14.0 || ^17 || ^18", "react@^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc", "react@^16.6.0 || ^17.0.0 || ^18.0.0", "react@^16.8.3 || ^17 || ^18", "react@^17.x || ^18.x", react@^18.0.0, react@^18.2.0, react@^18.3.1, "react@>= 16.8.0 < 19.0.0", react@>=0.14.9, react@>=15, react@>=16, react@>=16.0.0, react@>=16.6.0, "react@0.14 || 15 || 16 || 17 || 18":
version "18.3.1"
resolved "https://registry.npmjs.org/react/-/react-18.3.1.tgz"
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting.json b/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting.json
index fc69881b2c4..e8e56348f18 100644
--- a/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting.json
+++ b/src/backend/base/langflow/initial_setup/starter_projects/Basic Prompting.json
@@ -1082,7 +1082,7 @@
"zoom": 0.7749929474098888
}
},
- "description": "Get started with a simple prompt engineering flow. Customize AI responses by adjusting the system prompt template to create varied personalities.",
+ "description": "Perform basic prompting with an OpenAI model.",
"endpoint_name": null,
"icon": "Braces",
"id": "1511c230-d446-43a7-bfc3-539e69ce05b8",
diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent .json b/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent .json
deleted file mode 100644
index 9bf3e43f34e..00000000000
--- a/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent .json
+++ /dev/null
@@ -1,1501 +0,0 @@
-{
- "data": {
- "edges": [
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "YahooFinanceTool",
- "id": "YahooFinanceTool-PzHUy",
- "name": "api_build_tool",
- "output_types": [
- "Tool"
- ]
- },
- "targetHandle": {
- "fieldName": "tools",
- "id": "Agent-KhAae",
- "inputTypes": [
- "Tool",
- "BaseTool",
- "StructuredTool"
- ],
- "type": "other"
- }
- },
- "id": "reactflow__edge-YahooFinanceTool-PzHUy{œdataTypeœ:œYahooFinanceToolœ,œidœ:œYahooFinanceTool-PzHUyœ,œnameœ:œapi_build_toolœ,œoutput_typesœ:[œToolœ]}-Agent-KhAae{œfieldNameœ:œtoolsœ,œidœ:œAgent-KhAaeœ,œinputTypesœ:[œToolœ,œBaseToolœ,œStructuredToolœ],œtypeœ:œotherœ}",
- "source": "YahooFinanceTool-PzHUy",
- "sourceHandle": "{œdataTypeœ: œYahooFinanceToolœ, œidœ: œYahooFinanceTool-PzHUyœ, œnameœ: œapi_build_toolœ, œoutput_typesœ: [œToolœ]}",
- "target": "Agent-KhAae",
- "targetHandle": "{œfieldNameœ: œtoolsœ, œidœ: œAgent-KhAaeœ, œinputTypesœ: [œToolœ, œBaseToolœ, œStructuredToolœ], œtypeœ: œotherœ}"
- },
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "ChatInput",
- "id": "ChatInput-dBek4",
- "name": "message",
- "output_types": [
- "Message"
- ]
- },
- "targetHandle": {
- "fieldName": "input_value",
- "id": "Agent-KhAae",
- "inputTypes": [
- "Message"
- ],
- "type": "str"
- }
- },
- "id": "reactflow__edge-ChatInput-dBek4{œdataTypeœ:œChatInputœ,œidœ:œChatInput-dBek4œ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-Agent-KhAae{œfieldNameœ:œinput_valueœ,œidœ:œAgent-KhAaeœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
- "source": "ChatInput-dBek4",
- "sourceHandle": "{œdataTypeœ: œChatInputœ, œidœ: œChatInput-dBek4œ, œnameœ: œmessageœ, œoutput_typesœ: [œMessageœ]}",
- "target": "Agent-KhAae",
- "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œAgent-KhAaeœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
- },
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "Agent",
- "id": "Agent-KhAae",
- "name": "response",
- "output_types": [
- "Message"
- ]
- },
- "targetHandle": {
- "fieldName": "input_value",
- "id": "ChatOutput-ULcvr",
- "inputTypes": [
- "Message"
- ],
- "type": "str"
- }
- },
- "id": "reactflow__edge-Agent-KhAae{œdataTypeœ:œAgentœ,œidœ:œAgent-KhAaeœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-ULcvr{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-ULcvrœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
- "source": "Agent-KhAae",
- "sourceHandle": "{œdataTypeœ: œAgentœ, œidœ: œAgent-KhAaeœ, œnameœ: œresponseœ, œoutput_typesœ: [œMessageœ]}",
- "target": "ChatOutput-ULcvr",
- "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-ULcvrœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
- }
- ],
- "nodes": [
- {
- "data": {
- "description": "Define the agent's instructions, then enter a task to complete using tools.",
- "display_name": "Agent",
- "id": "Agent-KhAae",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Define the agent's instructions, then enter a task to complete using tools.",
- "display_name": "Agent",
- "documentation": "",
- "edited": false,
- "field_order": [
- "agent_llm",
- "max_tokens",
- "model_kwargs",
- "json_mode",
- "output_schema",
- "model_name",
- "openai_api_base",
- "api_key",
- "temperature",
- "seed",
- "output_parser",
- "system_prompt",
- "tools",
- "input_value",
- "handle_parsing_errors",
- "verbose",
- "max_iterations",
- "agent_description",
- "memory",
- "sender",
- "sender_name",
- "n_messages",
- "session_id",
- "order",
- "template",
- "add_current_date_tool"
- ],
- "frozen": false,
- "icon": "bot",
- "legacy": false,
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Response",
- "method": "message_response",
- "name": "response",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "add_current_date_tool": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Add tool Current Date",
- "dynamic": false,
- "info": "If true, will add a tool to the agent that returns the current date.",
- "list": false,
- "name": "add_current_date_tool",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "agent_description": {
- "_input_type": "MultilineInput",
- "advanced": true,
- "display_name": "Agent Description",
- "dynamic": false,
- "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "agent_description",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "A helpful assistant with access to the following tools:"
- },
- "agent_llm": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Model Provider",
- "dynamic": false,
- "info": "The provider of the language model that the agent will use to generate responses.",
- "input_types": [],
- "name": "agent_llm",
- "options": [
- "Amazon Bedrock",
- "Anthropic",
- "Azure OpenAI",
- "Groq",
- "NVIDIA",
- "OpenAI",
- "Custom"
- ],
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "OpenAI"
- },
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": false,
- "display_name": "OpenAI API Key",
- "dynamic": false,
- "info": "The OpenAI API Key to use for the OpenAI model.",
- "input_types": [
- "Message"
- ],
- "load_from_db": false,
- "name": "api_key",
- "password": true,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "type": "str",
- "value": "OPENAI_API_KEY"
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langchain_core.tools import StructuredTool\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.base.models.model_input_constants import ALL_PROVIDER_FIELDS, MODEL_PROVIDERS_DICT\nfrom langflow.base.models.model_utils import get_model_name\nfrom langflow.components.helpers import CurrentDateComponent\nfrom langflow.components.helpers.memory import MemoryComponent\nfrom langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent\nfrom langflow.io import BoolInput, DropdownInput, MultilineInput, Output\nfrom langflow.schema.dotdict import dotdict\nfrom langflow.schema.message import Message\n\n\ndef set_advanced_true(component_input):\n component_input.advanced = True\n return component_input\n\n\nclass AgentComponent(ToolCallingAgentComponent):\n display_name: str = \"Agent\"\n description: str = \"Define the agent's instructions, then enter a task to complete using tools.\"\n icon = \"bot\"\n beta = False\n name = \"Agent\"\n\n memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]\n\n inputs = [\n DropdownInput(\n name=\"agent_llm\",\n display_name=\"Model Provider\",\n info=\"The provider of the language model that the agent will use to generate responses.\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"OpenAI\",\n real_time_refresh=True,\n input_types=[],\n ),\n *MODEL_PROVIDERS_DICT[\"OpenAI\"][\"inputs\"],\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"Agent Instructions\",\n info=\"System Prompt: Initial instructions and context provided to guide the agent's behavior.\",\n value=\"You are a helpful assistant that can use tools to answer questions and perform tasks.\",\n advanced=False,\n ),\n *LCToolsAgentComponent._base_inputs,\n *memory_inputs,\n BoolInput(\n name=\"add_current_date_tool\",\n display_name=\"Add tool Current Date\",\n advanced=True,\n info=\"If true, will add a tool to the agent that returns the current date.\",\n value=True,\n ),\n ]\n outputs = [Output(name=\"response\", display_name=\"Response\", method=\"message_response\")]\n\n async def message_response(self) -> Message:\n llm_model, display_name = self.get_llm()\n self.model_name = get_model_name(llm_model, display_name=display_name)\n if llm_model is None:\n msg = \"No language model selected\"\n raise ValueError(msg)\n self.chat_history = self.get_memory_data()\n\n if self.add_current_date_tool:\n if not isinstance(self.tools, list): # type: ignore[has-type]\n self.tools = []\n # Convert CurrentDateComponent to a StructuredTool\n current_date_tool = CurrentDateComponent().to_toolkit()[0]\n if isinstance(current_date_tool, StructuredTool):\n self.tools.append(current_date_tool)\n else:\n msg = \"CurrentDateComponent must be converted to a StructuredTool\"\n raise ValueError(msg)\n\n if not self.tools:\n msg = \"Tools are required to run the agent.\"\n raise ValueError(msg)\n self.set(\n llm=llm_model,\n tools=self.tools,\n chat_history=self.chat_history,\n input_value=self.input_value,\n system_prompt=self.system_prompt,\n )\n agent = self.create_agent_runnable()\n return await self.run_agent(agent)\n\n def get_memory_data(self):\n memory_kwargs = {\n component_input.name: getattr(self, f\"{component_input.name}\") for component_input in self.memory_inputs\n }\n\n return MemoryComponent().set(**memory_kwargs).retrieve_messages()\n\n def get_llm(self):\n if isinstance(self.agent_llm, str):\n try:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n display_name = component_class.display_name\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\", \"\")\n return self._build_llm_model(component_class, inputs, prefix), display_name\n except Exception as e:\n msg = f\"Error building {self.agent_llm} language model\"\n raise ValueError(msg) from e\n return self.agent_llm, None\n\n def _build_llm_model(self, component, inputs, prefix=\"\"):\n model_kwargs = {input_.name: getattr(self, f\"{prefix}{input_.name}\") for input_ in inputs}\n return component.set(**model_kwargs).build_model()\n\n def delete_fields(self, build_config: dotdict, fields: dict | list[str]) -> None:\n \"\"\"Delete specified fields from build_config.\"\"\"\n for field in fields:\n build_config.pop(field, None)\n\n def update_input_types(self, build_config: dotdict) -> dotdict:\n \"\"\"Update input types for all fields in build_config.\"\"\"\n for key, value in build_config.items():\n if isinstance(value, dict):\n if value.get(\"input_types\") is None:\n build_config[key][\"input_types\"] = []\n elif hasattr(value, \"input_types\") and value.input_types is None:\n value.input_types = []\n return build_config\n\n def update_build_config(self, build_config: dotdict, field_value: str, field_name: str | None = None) -> dotdict:\n # Iterate over all providers in the MODEL_PROVIDERS_DICT\n # Existing logic for updating build_config\n if field_name == \"agent_llm\":\n provider_info = MODEL_PROVIDERS_DICT.get(field_value)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call the component class's update_build_config method\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n provider_configs: dict[str, tuple[dict, list[dict]]] = {\n provider: (\n MODEL_PROVIDERS_DICT[provider][\"fields\"],\n [\n MODEL_PROVIDERS_DICT[other_provider][\"fields\"]\n for other_provider in MODEL_PROVIDERS_DICT\n if other_provider != provider\n ],\n )\n for provider in MODEL_PROVIDERS_DICT\n }\n if field_value in provider_configs:\n fields_to_add, fields_to_delete = provider_configs[field_value]\n\n # Delete fields from other providers\n for fields in fields_to_delete:\n self.delete_fields(build_config, fields)\n\n # Add provider-specific fields\n if field_value == \"OpenAI\" and not any(field in build_config for field in fields_to_add):\n build_config.update(fields_to_add)\n else:\n build_config.update(fields_to_add)\n # Reset input types for agent_llm\n build_config[\"agent_llm\"][\"input_types\"] = []\n elif field_value == \"Custom\":\n # Delete all provider fields\n self.delete_fields(build_config, ALL_PROVIDER_FIELDS)\n # Update with custom component\n custom_component = DropdownInput(\n name=\"agent_llm\",\n display_name=\"Language Model\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"Custom\",\n real_time_refresh=True,\n input_types=[\"LanguageModel\"],\n )\n build_config.update({\"agent_llm\": custom_component.to_dict()})\n # Update input types for all fields\n build_config = self.update_input_types(build_config)\n\n # Validate required keys\n default_keys = [\n \"code\",\n \"_type\",\n \"agent_llm\",\n \"tools\",\n \"input_value\",\n \"add_current_date_tool\",\n \"system_prompt\",\n \"agent_description\",\n \"max_iterations\",\n \"handle_parsing_errors\",\n \"verbose\",\n ]\n missing_keys = [key for key in default_keys if key not in build_config]\n if missing_keys:\n msg = f\"Missing required keys in build_config: {missing_keys}\"\n raise ValueError(msg)\n if isinstance(self.agent_llm, str) and self.agent_llm in MODEL_PROVIDERS_DICT:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n prefix = provider_info.get(\"prefix\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call each component class's update_build_config method\n # remove the prefix from the field_name\n if isinstance(field_name, str) and isinstance(prefix, str):\n field_name = field_name.replace(prefix, \"\")\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n return build_config\n"
- },
- "handle_parsing_errors": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Handle Parse Errors",
- "dynamic": false,
- "info": "Should the Agent fix errors when reading user input for better processing?",
- "list": false,
- "name": "handle_parsing_errors",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "input_value": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "display_name": "Input",
- "dynamic": false,
- "info": "The input provided by the user for the agent to process.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": true,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "json_mode": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "JSON Mode",
- "dynamic": false,
- "info": "If True, it will output JSON regardless of passing a schema.",
- "list": false,
- "name": "json_mode",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": false
- },
- "max_iterations": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Max Iterations",
- "dynamic": false,
- "info": "The maximum number of attempts the agent can make to complete its task before it stops.",
- "list": false,
- "name": "max_iterations",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 15
- },
- "max_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Max Tokens",
- "dynamic": false,
- "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
- "list": false,
- "name": "max_tokens",
- "placeholder": "",
- "range_spec": {
- "max": 128000,
- "min": 0,
- "step": 0.1,
- "step_type": "float"
- },
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": ""
- },
- "memory": {
- "_input_type": "HandleInput",
- "advanced": true,
- "display_name": "External Memory",
- "dynamic": false,
- "info": "Retrieve messages from an external memory. If empty, it will use the Langflow tables.",
- "input_types": [
- "BaseChatMessageHistory"
- ],
- "list": false,
- "name": "memory",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "model_kwargs": {
- "_input_type": "DictInput",
- "advanced": true,
- "display_name": "Model Kwargs",
- "dynamic": false,
- "info": "Additional keyword arguments to pass to the model.",
- "list": false,
- "name": "model_kwargs",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "type": "dict",
- "value": {}
- },
- "model_name": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Model Name",
- "dynamic": false,
- "info": "",
- "name": "model_name",
- "options": [
- "gpt-4o-mini",
- "gpt-4o",
- "gpt-4-turbo",
- "gpt-4-turbo-preview",
- "gpt-4",
- "gpt-3.5-turbo",
- "gpt-3.5-turbo-0125"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "gpt-4o-mini"
- },
- "n_messages": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Number of Messages",
- "dynamic": false,
- "info": "Number of messages to retrieve.",
- "list": false,
- "name": "n_messages",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 100
- },
- "openai_api_base": {
- "_input_type": "StrInput",
- "advanced": true,
- "display_name": "OpenAI API Base",
- "dynamic": false,
- "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.",
- "list": false,
- "load_from_db": false,
- "name": "openai_api_base",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "order": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Order",
- "dynamic": false,
- "info": "Order of the messages.",
- "name": "order",
- "options": [
- "Ascending",
- "Descending"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Ascending"
- },
- "output_parser": {
- "_input_type": "HandleInput",
- "advanced": true,
- "display_name": "Output Parser",
- "dynamic": false,
- "info": "The parser to use to parse the output of the model",
- "input_types": [
- "OutputParser"
- ],
- "list": false,
- "name": "output_parser",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "output_schema": {
- "_input_type": "DictInput",
- "advanced": true,
- "display_name": "Schema",
- "dynamic": false,
- "info": "The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled. [DEPRECATED]",
- "list": true,
- "name": "output_schema",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "type": "dict",
- "value": {}
- },
- "seed": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Seed",
- "dynamic": false,
- "info": "The seed controls the reproducibility of the job.",
- "list": false,
- "name": "seed",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 1
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Filter by sender type.",
- "name": "sender",
- "options": [
- "Machine",
- "User",
- "Machine and User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Machine and User"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Filter by sender name.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "system_prompt": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Agent Instructions",
- "dynamic": false,
- "info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "system_prompt",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "You are a helpful assistant that can use tools to answer questions and perform tasks.\nUse markdown to format your answer, properly embedding images and urls."
- },
- "temperature": {
- "_input_type": "FloatInput",
- "advanced": true,
- "display_name": "Temperature",
- "dynamic": false,
- "info": "",
- "list": false,
- "name": "temperature",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "float",
- "value": 0.1
- },
- "template": {
- "_input_type": "MultilineInput",
- "advanced": true,
- "display_name": "Template",
- "dynamic": false,
- "info": "The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "template",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "{sender_name}: {text}"
- },
- "tools": {
- "_input_type": "HandleInput",
- "advanced": false,
- "display_name": "Tools",
- "dynamic": false,
- "info": "These are the tools that the agent can use to help with tasks.",
- "input_types": [
- "Tool",
- "BaseTool",
- "StructuredTool"
- ],
- "list": true,
- "name": "tools",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "verbose": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Verbose",
- "dynamic": false,
- "info": "",
- "list": false,
- "name": "verbose",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- }
- },
- "tool_mode": false
- },
- "type": "Agent"
- },
- "dragging": false,
- "height": 650,
- "id": "Agent-KhAae",
- "position": {
- "x": 2306.5155821255557,
- "y": 335.1151630488809
- },
- "positionAbsolute": {
- "x": 2306.5155821255557,
- "y": 335.1151630488809
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "description": "Access financial data and market information using Yahoo Finance.",
- "display_name": "Yahoo Finance Tool",
- "id": "YahooFinanceTool-PzHUy",
- "node": {
- "base_classes": [
- "Data",
- "Tool"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Access financial data and market information using Yahoo Finance.",
- "display_name": "Yahoo Finance Tool",
- "documentation": "",
- "edited": false,
- "field_order": [
- "symbol",
- "method",
- "num_news"
- ],
- "frozen": false,
- "icon": "trending-up",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Data",
- "method": "run_model",
- "name": "api_run_model",
- "required_inputs": [],
- "selected": "Data",
- "types": [
- "Data"
- ],
- "value": "__UNDEFINED__"
- },
- {
- "cache": true,
- "display_name": "Tool",
- "method": "build_tool",
- "name": "api_build_tool",
- "required_inputs": [],
- "selected": "Tool",
- "types": [
- "Tool"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "import ast\nimport pprint\nfrom enum import Enum\n\nimport yfinance as yf\nfrom langchain.tools import StructuredTool\nfrom langchain_core.tools import ToolException\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import DropdownInput, IntInput, MessageTextInput\nfrom langflow.schema import Data\n\n\nclass YahooFinanceMethod(Enum):\n GET_INFO = \"get_info\"\n GET_NEWS = \"get_news\"\n GET_ACTIONS = \"get_actions\"\n GET_ANALYSIS = \"get_analysis\"\n GET_BALANCE_SHEET = \"get_balance_sheet\"\n GET_CALENDAR = \"get_calendar\"\n GET_CASHFLOW = \"get_cashflow\"\n GET_INSTITUTIONAL_HOLDERS = \"get_institutional_holders\"\n GET_RECOMMENDATIONS = \"get_recommendations\"\n GET_SUSTAINABILITY = \"get_sustainability\"\n GET_MAJOR_HOLDERS = \"get_major_holders\"\n GET_MUTUALFUND_HOLDERS = \"get_mutualfund_holders\"\n GET_INSIDER_PURCHASES = \"get_insider_purchases\"\n GET_INSIDER_TRANSACTIONS = \"get_insider_transactions\"\n GET_INSIDER_ROSTER_HOLDERS = \"get_insider_roster_holders\"\n GET_DIVIDENDS = \"get_dividends\"\n GET_CAPITAL_GAINS = \"get_capital_gains\"\n GET_SPLITS = \"get_splits\"\n GET_SHARES = \"get_shares\"\n GET_FAST_INFO = \"get_fast_info\"\n GET_SEC_FILINGS = \"get_sec_filings\"\n GET_RECOMMENDATIONS_SUMMARY = \"get_recommendations_summary\"\n GET_UPGRADES_DOWNGRADES = \"get_upgrades_downgrades\"\n GET_EARNINGS = \"get_earnings\"\n GET_INCOME_STMT = \"get_income_stmt\"\n\n\nclass YahooFinanceSchema(BaseModel):\n symbol: str = Field(..., description=\"The stock symbol to retrieve data for.\")\n method: YahooFinanceMethod = Field(YahooFinanceMethod.GET_INFO, description=\"The type of data to retrieve.\")\n num_news: int | None = Field(5, description=\"The number of news articles to retrieve.\")\n\n\nclass YfinanceToolComponent(LCToolComponent):\n display_name = \"Yahoo Finance\"\n description = \"\"\"Uses [yfinance](https://pypi.org/project/yfinance/) (unofficial package) \\\nto access financial data and market information from Yahoo Finance.\"\"\"\n icon = \"trending-up\"\n name = \"YahooFinanceTool\"\n\n inputs = [\n MessageTextInput(\n name=\"symbol\",\n display_name=\"Stock Symbol\",\n info=\"The stock symbol to retrieve data for (e.g., AAPL, GOOG).\",\n ),\n DropdownInput(\n name=\"method\",\n display_name=\"Data Method\",\n info=\"The type of data to retrieve.\",\n options=list(YahooFinanceMethod),\n value=\"get_news\",\n ),\n IntInput(\n name=\"num_news\",\n display_name=\"Number of News\",\n info=\"The number of news articles to retrieve (only applicable for get_news).\",\n value=5,\n ),\n ]\n\n def run_model(self) -> list[Data]:\n return self._yahoo_finance_tool(\n self.symbol,\n self.method,\n self.num_news,\n )\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"yahoo_finance\",\n description=\"Access financial data and market information from Yahoo Finance.\",\n func=self._yahoo_finance_tool,\n args_schema=YahooFinanceSchema,\n )\n\n def _yahoo_finance_tool(\n self,\n symbol: str,\n method: YahooFinanceMethod,\n num_news: int | None = 5,\n ) -> list[Data]:\n ticker = yf.Ticker(symbol)\n\n try:\n if method == YahooFinanceMethod.GET_INFO:\n result = ticker.info\n elif method == YahooFinanceMethod.GET_NEWS:\n result = ticker.news[:num_news]\n else:\n result = getattr(ticker, method.value)()\n\n result = pprint.pformat(result)\n\n if method == YahooFinanceMethod.GET_NEWS:\n data_list = [Data(data=article) for article in ast.literal_eval(result)]\n else:\n data_list = [Data(data={\"result\": result})]\n\n except Exception as e:\n error_message = f\"Error retrieving data: {e}\"\n logger.debug(error_message)\n self.status = error_message\n raise ToolException(error_message) from e\n\n return data_list\n"
- },
- "method": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Data Method",
- "dynamic": false,
- "info": "The type of data to retrieve.",
- "name": "method",
- "options": [
- "get_info",
- "get_news",
- "get_actions",
- "get_analysis",
- "get_balance_sheet",
- "get_calendar",
- "get_cashflow",
- "get_institutional_holders",
- "get_recommendations",
- "get_sustainability",
- "get_major_holders",
- "get_mutualfund_holders",
- "get_insider_purchases",
- "get_insider_transactions",
- "get_insider_roster_holders",
- "get_dividends",
- "get_capital_gains",
- "get_splits",
- "get_shares",
- "get_fast_info",
- "get_sec_filings",
- "get_recommendations_summary",
- "get_upgrades_downgrades",
- "get_earnings",
- "get_income_stmt"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "get_news"
- },
- "num_news": {
- "_input_type": "IntInput",
- "advanced": false,
- "display_name": "Number of News",
- "dynamic": false,
- "info": "The number of news articles to retrieve (only applicable for get_news).",
- "list": false,
- "name": "num_news",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 5
- },
- "symbol": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "display_name": "Stock Symbol",
- "dynamic": false,
- "info": "The stock symbol to retrieve data for (e.g., AAPL, GOOG).",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "symbol",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "NVDA"
- }
- },
- "tool_mode": false
- },
- "type": "YahooFinanceTool"
- },
- "dragging": false,
- "height": 475,
- "id": "YahooFinanceTool-PzHUy",
- "position": {
- "x": 1905.5096784216487,
- "y": 313.6052678310467
- },
- "positionAbsolute": {
- "x": 1905.5096784216487,
- "y": 313.6052678310467
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "id": "ChatInput-dBek4",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Get chat inputs from the Playground.",
- "display_name": "Chat Input",
- "documentation": "",
- "edited": false,
- "field_order": [
- "input_value",
- "should_store_message",
- "sender",
- "sender_name",
- "session_id",
- "files",
- "background_color",
- "chat_icon",
- "text_color"
- ],
- "frozen": false,
- "icon": "MessagesSquare",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Message",
- "method": "message_response",
- "name": "message",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "background_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Background Color",
- "dynamic": false,
- "info": "The background color of the icon.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "background_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "chat_icon": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Icon",
- "dynamic": false,
- "info": "The icon of the message.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "chat_icon",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, FileInput, MessageTextInput, MultilineInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_USER, MESSAGE_SENDER_USER\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_USER,\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_USER,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n _background_color = self.background_color\n _text_color = self.text_color\n _icon = self.chat_icon\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n properties={\"background_color\": _background_color, \"text_color\": _text_color, \"icon\": _icon},\n )\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
- },
- "files": {
- "_input_type": "FileInput",
- "advanced": true,
- "display_name": "Files",
- "dynamic": false,
- "fileTypes": [
- "txt",
- "md",
- "mdx",
- "csv",
- "json",
- "yaml",
- "yml",
- "xml",
- "html",
- "htm",
- "pdf",
- "docx",
- "py",
- "sh",
- "sql",
- "js",
- "ts",
- "tsx",
- "jpg",
- "jpeg",
- "png",
- "bmp",
- "image"
- ],
- "file_path": "",
- "info": "Files to be sent with the message.",
- "list": true,
- "name": "files",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "file",
- "value": ""
- },
- "input_value": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Message to be passed as input.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "search news about AAPL"
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Type of sender.",
- "name": "sender",
- "options": [
- "Machine",
- "User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "User"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Name of the sender.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "User"
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "should_store_message": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Store Messages",
- "dynamic": false,
- "info": "Store the message in the history.",
- "list": false,
- "name": "should_store_message",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "text_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Text Color",
- "dynamic": false,
- "info": "The text color of the name",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "text_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- }
- },
- "tool_mode": false
- },
- "type": "ChatInput"
- },
- "dragging": false,
- "height": 234,
- "id": "ChatInput-dBek4",
- "position": {
- "x": 1907.4497817799925,
- "y": 817.955066634514
- },
- "positionAbsolute": {
- "x": 1907.4497817799925,
- "y": 817.955066634514
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "description": "Display a chat message in the Playground.",
- "display_name": "Chat Output",
- "id": "ChatOutput-ULcvr",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Display a chat message in the Playground.",
- "display_name": "Chat Output",
- "documentation": "",
- "edited": false,
- "field_order": [
- "input_value",
- "should_store_message",
- "sender",
- "sender_name",
- "session_id",
- "data_template",
- "background_color",
- "chat_icon",
- "text_color"
- ],
- "frozen": false,
- "icon": "MessagesSquare",
- "legacy": false,
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Message",
- "method": "message_response",
- "name": "message",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "background_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Background Color",
- "dynamic": false,
- "info": "The background color of the icon.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "background_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "chat_icon": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Icon",
- "dynamic": false,
- "info": "The icon of the message.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "chat_icon",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, MessageInput, MessageTextInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.schema.properties import Source\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_AI, MESSAGE_SENDER_USER\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatOutput\"\n\n inputs = [\n MessageInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Message to be passed as output.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_AI,\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_AI,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Message\",\n name=\"message\",\n method=\"message_response\",\n ),\n ]\n\n def _build_source(self, _id: str | None, display_name: str | None, source: str | None) -> Source:\n source_dict = {}\n if _id:\n source_dict[\"id\"] = _id\n if display_name:\n source_dict[\"display_name\"] = display_name\n if source:\n source_dict[\"source\"] = source\n return Source(**source_dict)\n\n def message_response(self) -> Message:\n _source, _icon, _display_name, _source_id = self.get_properties_from_source_component()\n _background_color = self.background_color\n _text_color = self.text_color\n if self.chat_icon:\n _icon = self.chat_icon\n message = self.input_value if isinstance(self.input_value, Message) else Message(text=self.input_value)\n message.sender = self.sender\n message.sender_name = self.sender_name\n message.session_id = self.session_id\n message.flow_id = self.graph.flow_id if hasattr(self, \"graph\") else None\n message.properties.source = self._build_source(_source_id, _display_name, _source)\n message.properties.icon = _icon\n message.properties.background_color = _background_color\n message.properties.text_color = _text_color\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
- },
- "data_template": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Data Template",
- "dynamic": false,
- "info": "Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "data_template",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "{text}"
- },
- "input_value": {
- "_input_type": "MessageInput",
- "advanced": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Message to be passed as output.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Type of sender.",
- "name": "sender",
- "options": [
- "Machine",
- "User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Machine"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Name of the sender.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "AI"
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "should_store_message": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Store Messages",
- "dynamic": false,
- "info": "Store the message in the history.",
- "list": false,
- "name": "should_store_message",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "text_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Text Color",
- "dynamic": false,
- "info": "The text color of the name",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "text_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- }
- },
- "tool_mode": false
- },
- "type": "ChatOutput"
- },
- "dragging": false,
- "height": 234,
- "id": "ChatOutput-ULcvr",
- "position": {
- "x": 2683.9938458383212,
- "y": 556.5828467235146
- },
- "positionAbsolute": {
- "x": 2683.9938458383212,
- "y": 556.5828467235146
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "id": "note-FSVUJ",
- "node": {
- "description": "# Simple Agent\nA straightforward implementation of a chatbot focusing on processing inputs and generating responses employing conversation memory capabilities.\n## Core Components\n1. **Chat Input**\n - Collects user messages for processing.\n2. **Agent**\n - Analyzes user input.\n - Generates contextually relevant responses.\n - Utilizes tools to refine and enhance replies as needed.\n3. **Chat Output**\n - Presents formatted responses to the user.\n - Ensures consistent conversational flow.\n## Features\n- Processes each message independently.\n- Focuses on generating relevant, immediate responses.\n- Handles each chat interaction as a standalone session.\n## Quick Start\n1. Initiate a chat by sending a message in Chat Input.\n2. The Agent processes the message, considering any immediate context.\n3. Receive a response in Chat Output.\n\nThis simple agent chatbot provides a streamlined conversational flow without the complexity of managing conversation memory.",
- "display_name": "",
- "documentation": "",
- "template": {}
- },
- "type": "note"
- },
- "dragging": false,
- "height": 736,
- "id": "note-FSVUJ",
- "position": {
- "x": 1512.8976594415833,
- "y": 312.9558305744385
- },
- "positionAbsolute": {
- "x": 1512.8976594415833,
- "y": 312.9558305744385
- },
- "resizing": false,
- "selected": false,
- "style": {
- "height": 736,
- "width": 382
- },
- "type": "noteNode",
- "width": 382
- }
- ],
- "viewport": {
- "x": -1275.792144730309,
- "y": -144.09980323772618,
- "zoom": 0.8828160439097184
- }
- },
- "description": "Get started with an agent that calls the Yahoo Finance tool for quick access to stock prices, market trends, and financial data.",
- "endpoint_name": null,
- "gradient": "5",
- "icon": "Bot",
- "id": "a774332d-6fb5-43b6-96a4-d3eb8e62ddc0",
- "is_component": false,
- "last_tested_version": "1.0.19.post2",
- "name": "Simple Agent",
- "tags": [
- "assistants",
- "agents"
- ]
-}
\ No newline at end of file
diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json b/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json
new file mode 100644
index 00000000000..d94c4bfc984
--- /dev/null
+++ b/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json
@@ -0,0 +1,1578 @@
+{
+ "data": {
+ "edges": [
+ {
+ "animated": false,
+ "className": "",
+ "data": {
+ "sourceHandle": {
+ "dataType": "ChatInput",
+ "id": "ChatInput-Lqvzc",
+ "name": "message",
+ "output_types": [
+ "Message"
+ ]
+ },
+ "targetHandle": {
+ "fieldName": "input_value",
+ "id": "Agent-WoCzf",
+ "inputTypes": [
+ "Message"
+ ],
+ "type": "str"
+ }
+ },
+ "id": "reactflow__edge-ChatInput-Lqvzc{œdataTypeœ:œChatInputœ,œidœ:œChatInput-Lqvzcœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-Agent-WoCzf{œfieldNameœ:œinput_valueœ,œidœ:œAgent-WoCzfœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "selected": false,
+ "source": "ChatInput-Lqvzc",
+ "sourceHandle": "{œdataTypeœ: œChatInputœ, œidœ: œChatInput-Lqvzcœ, œnameœ: œmessageœ, œoutput_typesœ: [œMessageœ]}",
+ "target": "Agent-WoCzf",
+ "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œAgent-WoCzfœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
+ },
+ {
+ "animated": false,
+ "className": "",
+ "data": {
+ "sourceHandle": {
+ "dataType": "Agent",
+ "id": "Agent-WoCzf",
+ "name": "response",
+ "output_types": [
+ "Message"
+ ]
+ },
+ "targetHandle": {
+ "fieldName": "input_value",
+ "id": "ChatOutput-MXQER",
+ "inputTypes": [
+ "Message"
+ ],
+ "type": "str"
+ }
+ },
+ "id": "reactflow__edge-Agent-WoCzf{œdataTypeœ:œAgentœ,œidœ:œAgent-WoCzfœ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-MXQER{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-MXQERœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
+ "selected": false,
+ "source": "Agent-WoCzf",
+ "sourceHandle": "{œdataTypeœ: œAgentœ, œidœ: œAgent-WoCzfœ, œnameœ: œresponseœ, œoutput_typesœ: [œMessageœ]}",
+ "target": "ChatOutput-MXQER",
+ "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-MXQERœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
+ }
+ ],
+ "nodes": [
+ {
+ "data": {
+ "description": "Define the agent's instructions, then enter a task to complete using tools.",
+ "display_name": "Agent",
+ "id": "Agent-WoCzf",
+ "node": {
+ "base_classes": [
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Define the agent's instructions, then enter a task to complete using tools.",
+ "display_name": "Agent",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "agent_llm",
+ "max_tokens",
+ "model_kwargs",
+ "json_mode",
+ "output_schema",
+ "model_name",
+ "openai_api_base",
+ "api_key",
+ "temperature",
+ "seed",
+ "output_parser",
+ "system_prompt",
+ "tools",
+ "input_value",
+ "handle_parsing_errors",
+ "verbose",
+ "max_iterations",
+ "agent_description",
+ "memory",
+ "sender",
+ "sender_name",
+ "n_messages",
+ "session_id",
+ "order",
+ "template",
+ "add_current_date_tool"
+ ],
+ "frozen": false,
+ "icon": "bot",
+ "legacy": false,
+ "lf_version": "1.1.0.dev4",
+ "metadata": {},
+ "output_types": [],
+ "outputs": [
+ {
+ "cache": true,
+ "display_name": "Response",
+ "method": "message_response",
+ "name": "response",
+ "selected": "Message",
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "add_current_date_tool": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Add tool Current Date",
+ "dynamic": false,
+ "info": "If true, will add a tool to the agent that returns the current date.",
+ "list": false,
+ "name": "add_current_date_tool",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": true
+ },
+ "agent_description": {
+ "_input_type": "MultilineInput",
+ "advanced": true,
+ "display_name": "Agent Description",
+ "dynamic": false,
+ "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "agent_description",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "A helpful assistant with access to the following tools:"
+ },
+ "agent_llm": {
+ "_input_type": "DropdownInput",
+ "advanced": false,
+ "combobox": false,
+ "display_name": "Model Provider",
+ "dynamic": false,
+ "info": "The provider of the language model that the agent will use to generate responses.",
+ "input_types": [],
+ "name": "agent_llm",
+ "options": [
+ "Amazon Bedrock",
+ "Anthropic",
+ "Azure OpenAI",
+ "Groq",
+ "NVIDIA",
+ "OpenAI",
+ "Custom"
+ ],
+ "placeholder": "",
+ "real_time_refresh": true,
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "OpenAI"
+ },
+ "api_key": {
+ "_input_type": "SecretStrInput",
+ "advanced": false,
+ "display_name": "OpenAI API Key",
+ "dynamic": false,
+ "info": "The OpenAI API Key to use for the OpenAI model.",
+ "input_types": [
+ "Message"
+ ],
+ "load_from_db": false,
+ "name": "api_key",
+ "password": true,
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "type": "str",
+ "value": ""
+ },
+ "code": {
+ "advanced": true,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "from langchain_core.tools import StructuredTool\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.base.models.model_input_constants import ALL_PROVIDER_FIELDS, MODEL_PROVIDERS_DICT\nfrom langflow.base.models.model_utils import get_model_name\nfrom langflow.components.helpers import CurrentDateComponent\nfrom langflow.components.helpers.memory import MemoryComponent\nfrom langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent\nfrom langflow.io import BoolInput, DropdownInput, MultilineInput, Output\nfrom langflow.schema.dotdict import dotdict\nfrom langflow.schema.message import Message\n\n\ndef set_advanced_true(component_input):\n component_input.advanced = True\n return component_input\n\n\nclass AgentComponent(ToolCallingAgentComponent):\n display_name: str = \"Agent\"\n description: str = \"Define the agent's instructions, then enter a task to complete using tools.\"\n icon = \"bot\"\n beta = False\n name = \"Agent\"\n\n memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]\n\n inputs = [\n DropdownInput(\n name=\"agent_llm\",\n display_name=\"Model Provider\",\n info=\"The provider of the language model that the agent will use to generate responses.\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"OpenAI\",\n real_time_refresh=True,\n input_types=[],\n ),\n *MODEL_PROVIDERS_DICT[\"OpenAI\"][\"inputs\"],\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"Agent Instructions\",\n info=\"System Prompt: Initial instructions and context provided to guide the agent's behavior.\",\n value=\"You are a helpful assistant that can use tools to answer questions and perform tasks.\",\n advanced=False,\n ),\n *LCToolsAgentComponent._base_inputs,\n *memory_inputs,\n BoolInput(\n name=\"add_current_date_tool\",\n display_name=\"Add tool Current Date\",\n advanced=True,\n info=\"If true, will add a tool to the agent that returns the current date.\",\n value=True,\n ),\n ]\n outputs = [Output(name=\"response\", display_name=\"Response\", method=\"message_response\")]\n\n async def message_response(self) -> Message:\n llm_model, display_name = self.get_llm()\n self.model_name = get_model_name(llm_model, display_name=display_name)\n if llm_model is None:\n msg = \"No language model selected\"\n raise ValueError(msg)\n self.chat_history = self.get_memory_data()\n\n if self.add_current_date_tool:\n if not isinstance(self.tools, list): # type: ignore[has-type]\n self.tools = []\n # Convert CurrentDateComponent to a StructuredTool\n current_date_tool = CurrentDateComponent().to_toolkit()[0]\n if isinstance(current_date_tool, StructuredTool):\n self.tools.append(current_date_tool)\n else:\n msg = \"CurrentDateComponent must be converted to a StructuredTool\"\n raise ValueError(msg)\n\n if not self.tools:\n msg = \"Tools are required to run the agent.\"\n raise ValueError(msg)\n self.set(\n llm=llm_model,\n tools=self.tools,\n chat_history=self.chat_history,\n input_value=self.input_value,\n system_prompt=self.system_prompt,\n )\n agent = self.create_agent_runnable()\n return await self.run_agent(agent)\n\n def get_memory_data(self):\n memory_kwargs = {\n component_input.name: getattr(self, f\"{component_input.name}\") for component_input in self.memory_inputs\n }\n\n return MemoryComponent().set(**memory_kwargs).retrieve_messages()\n\n def get_llm(self):\n if isinstance(self.agent_llm, str):\n try:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n display_name = component_class.display_name\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\", \"\")\n return self._build_llm_model(component_class, inputs, prefix), display_name\n except Exception as e:\n msg = f\"Error building {self.agent_llm} language model\"\n raise ValueError(msg) from e\n return self.agent_llm, None\n\n def _build_llm_model(self, component, inputs, prefix=\"\"):\n model_kwargs = {input_.name: getattr(self, f\"{prefix}{input_.name}\") for input_ in inputs}\n return component.set(**model_kwargs).build_model()\n\n def delete_fields(self, build_config: dotdict, fields: dict | list[str]) -> None:\n \"\"\"Delete specified fields from build_config.\"\"\"\n for field in fields:\n build_config.pop(field, None)\n\n def update_input_types(self, build_config: dotdict) -> dotdict:\n \"\"\"Update input types for all fields in build_config.\"\"\"\n for key, value in build_config.items():\n if isinstance(value, dict):\n if value.get(\"input_types\") is None:\n build_config[key][\"input_types\"] = []\n elif hasattr(value, \"input_types\") and value.input_types is None:\n value.input_types = []\n return build_config\n\n def update_build_config(self, build_config: dotdict, field_value: str, field_name: str | None = None) -> dotdict:\n # Iterate over all providers in the MODEL_PROVIDERS_DICT\n # Existing logic for updating build_config\n if field_name == \"agent_llm\":\n provider_info = MODEL_PROVIDERS_DICT.get(field_value)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call the component class's update_build_config method\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n provider_configs: dict[str, tuple[dict, list[dict]]] = {\n provider: (\n MODEL_PROVIDERS_DICT[provider][\"fields\"],\n [\n MODEL_PROVIDERS_DICT[other_provider][\"fields\"]\n for other_provider in MODEL_PROVIDERS_DICT\n if other_provider != provider\n ],\n )\n for provider in MODEL_PROVIDERS_DICT\n }\n if field_value in provider_configs:\n fields_to_add, fields_to_delete = provider_configs[field_value]\n\n # Delete fields from other providers\n for fields in fields_to_delete:\n self.delete_fields(build_config, fields)\n\n # Add provider-specific fields\n if field_value == \"OpenAI\" and not any(field in build_config for field in fields_to_add):\n build_config.update(fields_to_add)\n else:\n build_config.update(fields_to_add)\n # Reset input types for agent_llm\n build_config[\"agent_llm\"][\"input_types\"] = []\n elif field_value == \"Custom\":\n # Delete all provider fields\n self.delete_fields(build_config, ALL_PROVIDER_FIELDS)\n # Update with custom component\n custom_component = DropdownInput(\n name=\"agent_llm\",\n display_name=\"Language Model\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"Custom\",\n real_time_refresh=True,\n input_types=[\"LanguageModel\"],\n )\n build_config.update({\"agent_llm\": custom_component.to_dict()})\n # Update input types for all fields\n build_config = self.update_input_types(build_config)\n\n # Validate required keys\n default_keys = [\n \"code\",\n \"_type\",\n \"agent_llm\",\n \"tools\",\n \"input_value\",\n \"add_current_date_tool\",\n \"system_prompt\",\n \"agent_description\",\n \"max_iterations\",\n \"handle_parsing_errors\",\n \"verbose\",\n ]\n missing_keys = [key for key in default_keys if key not in build_config]\n if missing_keys:\n msg = f\"Missing required keys in build_config: {missing_keys}\"\n raise ValueError(msg)\n if isinstance(self.agent_llm, str) and self.agent_llm in MODEL_PROVIDERS_DICT:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n prefix = provider_info.get(\"prefix\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call each component class's update_build_config method\n # remove the prefix from the field_name\n if isinstance(field_name, str) and isinstance(prefix, str):\n field_name = field_name.replace(prefix, \"\")\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n return build_config\n"
+ },
+ "handle_parsing_errors": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Handle Parse Errors",
+ "dynamic": false,
+ "info": "Should the Agent fix errors when reading user input for better processing?",
+ "list": false,
+ "name": "handle_parsing_errors",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": true
+ },
+ "input_value": {
+ "_input_type": "MessageTextInput",
+ "advanced": false,
+ "display_name": "Input",
+ "dynamic": false,
+ "info": "The input provided by the user for the agent to process.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "input_value",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": true,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "json_mode": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "JSON Mode",
+ "dynamic": false,
+ "info": "If True, it will output JSON regardless of passing a schema.",
+ "list": false,
+ "name": "json_mode",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": false
+ },
+ "max_iterations": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "display_name": "Max Iterations",
+ "dynamic": false,
+ "info": "The maximum number of attempts the agent can make to complete its task before it stops.",
+ "list": false,
+ "name": "max_iterations",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "int",
+ "value": 15
+ },
+ "max_tokens": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "display_name": "Max Tokens",
+ "dynamic": false,
+ "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
+ "list": false,
+ "name": "max_tokens",
+ "placeholder": "",
+ "range_spec": {
+ "max": 128000,
+ "min": 0,
+ "step": 0.1,
+ "step_type": "float"
+ },
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "int",
+ "value": ""
+ },
+ "memory": {
+ "_input_type": "HandleInput",
+ "advanced": true,
+ "display_name": "External Memory",
+ "dynamic": false,
+ "info": "Retrieve messages from an external memory. If empty, it will use the Langflow tables.",
+ "input_types": [
+ "BaseChatMessageHistory"
+ ],
+ "list": false,
+ "name": "memory",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "other",
+ "value": ""
+ },
+ "model_kwargs": {
+ "_input_type": "DictInput",
+ "advanced": true,
+ "display_name": "Model Kwargs",
+ "dynamic": false,
+ "info": "Additional keyword arguments to pass to the model.",
+ "list": false,
+ "name": "model_kwargs",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_input": true,
+ "type": "dict",
+ "value": {}
+ },
+ "model_name": {
+ "_input_type": "DropdownInput",
+ "advanced": false,
+ "combobox": false,
+ "display_name": "Model Name",
+ "dynamic": false,
+ "info": "",
+ "name": "model_name",
+ "options": [
+ "gpt-4o-mini",
+ "gpt-4o",
+ "gpt-4-turbo",
+ "gpt-4-turbo-preview",
+ "gpt-4",
+ "gpt-3.5-turbo",
+ "gpt-3.5-turbo-0125"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "gpt-4o-mini"
+ },
+ "n_messages": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "display_name": "Number of Messages",
+ "dynamic": false,
+ "info": "Number of messages to retrieve.",
+ "list": false,
+ "name": "n_messages",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "int",
+ "value": 100
+ },
+ "openai_api_base": {
+ "_input_type": "StrInput",
+ "advanced": true,
+ "display_name": "OpenAI API Base",
+ "dynamic": false,
+ "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.",
+ "list": false,
+ "load_from_db": false,
+ "name": "openai_api_base",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "order": {
+ "_input_type": "DropdownInput",
+ "advanced": true,
+ "combobox": false,
+ "display_name": "Order",
+ "dynamic": false,
+ "info": "Order of the messages.",
+ "name": "order",
+ "options": [
+ "Ascending",
+ "Descending"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "Ascending"
+ },
+ "output_parser": {
+ "_input_type": "HandleInput",
+ "advanced": true,
+ "display_name": "Output Parser",
+ "dynamic": false,
+ "info": "The parser to use to parse the output of the model",
+ "input_types": [
+ "OutputParser"
+ ],
+ "list": false,
+ "name": "output_parser",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "other",
+ "value": ""
+ },
+ "output_schema": {
+ "_input_type": "DictInput",
+ "advanced": true,
+ "display_name": "Schema",
+ "dynamic": false,
+ "info": "The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled. [DEPRECATED]",
+ "list": true,
+ "name": "output_schema",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_input": true,
+ "type": "dict",
+ "value": {}
+ },
+ "seed": {
+ "_input_type": "IntInput",
+ "advanced": true,
+ "display_name": "Seed",
+ "dynamic": false,
+ "info": "The seed controls the reproducibility of the job.",
+ "list": false,
+ "name": "seed",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "int",
+ "value": 1
+ },
+ "sender": {
+ "_input_type": "DropdownInput",
+ "advanced": true,
+ "combobox": false,
+ "display_name": "Sender Type",
+ "dynamic": false,
+ "info": "Filter by sender type.",
+ "name": "sender",
+ "options": [
+ "Machine",
+ "User",
+ "Machine and User"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "Machine and User"
+ },
+ "sender_name": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Sender Name",
+ "dynamic": false,
+ "info": "Filter by sender name.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "sender_name",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "session_id": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Session ID",
+ "dynamic": false,
+ "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "session_id",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "system_prompt": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "display_name": "Agent Instructions",
+ "dynamic": false,
+ "info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "system_prompt",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "You are a helpful assistant that can use tools to answer questions and perform tasks.\nUse markdown to format your answer, properly embedding images and urls."
+ },
+ "temperature": {
+ "_input_type": "FloatInput",
+ "advanced": true,
+ "display_name": "Temperature",
+ "dynamic": false,
+ "info": "",
+ "list": false,
+ "name": "temperature",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "float",
+ "value": 0.1
+ },
+ "template": {
+ "_input_type": "MultilineInput",
+ "advanced": true,
+ "display_name": "Template",
+ "dynamic": false,
+ "info": "The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "template",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "{sender_name}: {text}"
+ },
+ "tools": {
+ "_input_type": "HandleInput",
+ "advanced": false,
+ "display_name": "Tools",
+ "dynamic": false,
+ "info": "These are the tools that the agent can use to help with tasks.",
+ "input_types": [
+ "Tool",
+ "BaseTool",
+ "StructuredTool"
+ ],
+ "list": true,
+ "name": "tools",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "other",
+ "value": ""
+ },
+ "verbose": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Verbose",
+ "dynamic": false,
+ "info": "",
+ "list": false,
+ "name": "verbose",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": true
+ }
+ },
+ "tool_mode": false
+ },
+ "type": "Agent"
+ },
+ "dragging": false,
+ "height": 645,
+ "id": "Agent-WoCzf",
+ "position": {
+ "x": 2306.5155821255557,
+ "y": 332.5289520982579
+ },
+ "positionAbsolute": {
+ "x": 2306.5155821255557,
+ "y": 332.5289520982579
+ },
+ "selected": true,
+ "type": "genericNode",
+ "width": 320
+ },
+ {
+ "data": {
+ "id": "ChatInput-Lqvzc",
+ "node": {
+ "base_classes": [
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Get chat inputs from the Playground.",
+ "display_name": "Chat Input",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "input_value",
+ "should_store_message",
+ "sender",
+ "sender_name",
+ "session_id",
+ "files",
+ "background_color",
+ "chat_icon",
+ "text_color"
+ ],
+ "frozen": false,
+ "icon": "MessagesSquare",
+ "legacy": false,
+ "lf_version": "1.1.0.dev4",
+ "metadata": {},
+ "output_types": [],
+ "outputs": [
+ {
+ "cache": true,
+ "display_name": "Message",
+ "method": "message_response",
+ "name": "message",
+ "selected": "Message",
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "background_color": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Background Color",
+ "dynamic": false,
+ "info": "The background color of the icon.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "background_color",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "chat_icon": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Icon",
+ "dynamic": false,
+ "info": "The icon of the message.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "chat_icon",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "code": {
+ "advanced": true,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, FileInput, MessageTextInput, MultilineInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_USER, MESSAGE_SENDER_USER\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_USER,\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_USER,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n _background_color = self.background_color\n _text_color = self.text_color\n _icon = self.chat_icon\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n properties={\"background_color\": _background_color, \"text_color\": _text_color, \"icon\": _icon},\n )\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
+ },
+ "files": {
+ "_input_type": "FileInput",
+ "advanced": true,
+ "display_name": "Files",
+ "dynamic": false,
+ "fileTypes": [
+ "txt",
+ "md",
+ "mdx",
+ "csv",
+ "json",
+ "yaml",
+ "yml",
+ "xml",
+ "html",
+ "htm",
+ "pdf",
+ "docx",
+ "py",
+ "sh",
+ "sql",
+ "js",
+ "ts",
+ "tsx",
+ "jpg",
+ "jpeg",
+ "png",
+ "bmp",
+ "image"
+ ],
+ "file_path": "",
+ "info": "Files to be sent with the message.",
+ "list": true,
+ "name": "files",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "file",
+ "value": ""
+ },
+ "input_value": {
+ "_input_type": "MultilineInput",
+ "advanced": false,
+ "display_name": "Text",
+ "dynamic": false,
+ "info": "Message to be passed as input.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "input_value",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "sender": {
+ "_input_type": "DropdownInput",
+ "advanced": true,
+ "combobox": false,
+ "display_name": "Sender Type",
+ "dynamic": false,
+ "info": "Type of sender.",
+ "name": "sender",
+ "options": [
+ "Machine",
+ "User"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "User"
+ },
+ "sender_name": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Sender Name",
+ "dynamic": false,
+ "info": "Name of the sender.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "sender_name",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "User"
+ },
+ "session_id": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Session ID",
+ "dynamic": false,
+ "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "session_id",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "should_store_message": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Store Messages",
+ "dynamic": false,
+ "info": "Store the message in the history.",
+ "list": false,
+ "name": "should_store_message",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": true
+ },
+ "text_color": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Text Color",
+ "dynamic": false,
+ "info": "The text color of the name",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "text_color",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ }
+ },
+ "tool_mode": false
+ },
+ "type": "ChatInput"
+ },
+ "dragging": false,
+ "height": 233,
+ "id": "ChatInput-Lqvzc",
+ "position": {
+ "x": 1933.1267332374987,
+ "y": 887.6496491620314
+ },
+ "positionAbsolute": {
+ "x": 1933.1267332374987,
+ "y": 887.6496491620314
+ },
+ "selected": false,
+ "type": "genericNode",
+ "width": 320
+ },
+ {
+ "data": {
+ "description": "Display a chat message in the Playground.",
+ "display_name": "Chat Output",
+ "id": "ChatOutput-MXQER",
+ "node": {
+ "base_classes": [
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Display a chat message in the Playground.",
+ "display_name": "Chat Output",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "input_value",
+ "should_store_message",
+ "sender",
+ "sender_name",
+ "session_id",
+ "data_template",
+ "background_color",
+ "chat_icon",
+ "text_color"
+ ],
+ "frozen": false,
+ "icon": "MessagesSquare",
+ "legacy": false,
+ "lf_version": "1.1.0.dev4",
+ "metadata": {},
+ "output_types": [],
+ "outputs": [
+ {
+ "cache": true,
+ "display_name": "Message",
+ "method": "message_response",
+ "name": "message",
+ "selected": "Message",
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "background_color": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Background Color",
+ "dynamic": false,
+ "info": "The background color of the icon.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "background_color",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "chat_icon": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Icon",
+ "dynamic": false,
+ "info": "The icon of the message.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "chat_icon",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "code": {
+ "advanced": true,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "from langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, MessageInput, MessageTextInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.schema.properties import Source\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_AI, MESSAGE_SENDER_USER\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatOutput\"\n\n inputs = [\n MessageInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Message to be passed as output.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_AI,\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_AI,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Message\",\n name=\"message\",\n method=\"message_response\",\n ),\n ]\n\n def _build_source(self, _id: str | None, display_name: str | None, source: str | None) -> Source:\n source_dict = {}\n if _id:\n source_dict[\"id\"] = _id\n if display_name:\n source_dict[\"display_name\"] = display_name\n if source:\n source_dict[\"source\"] = source\n return Source(**source_dict)\n\n def message_response(self) -> Message:\n _source, _icon, _display_name, _source_id = self.get_properties_from_source_component()\n _background_color = self.background_color\n _text_color = self.text_color\n if self.chat_icon:\n _icon = self.chat_icon\n message = self.input_value if isinstance(self.input_value, Message) else Message(text=self.input_value)\n message.sender = self.sender\n message.sender_name = self.sender_name\n message.session_id = self.session_id\n message.flow_id = self.graph.flow_id if hasattr(self, \"graph\") else None\n message.properties.source = self._build_source(_source_id, _display_name, _source)\n message.properties.icon = _icon\n message.properties.background_color = _background_color\n message.properties.text_color = _text_color\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
+ },
+ "data_template": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Data Template",
+ "dynamic": false,
+ "info": "Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "data_template",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "{text}"
+ },
+ "input_value": {
+ "_input_type": "MessageInput",
+ "advanced": false,
+ "display_name": "Text",
+ "dynamic": false,
+ "info": "Message to be passed as output.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "input_value",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "sender": {
+ "_input_type": "DropdownInput",
+ "advanced": true,
+ "combobox": false,
+ "display_name": "Sender Type",
+ "dynamic": false,
+ "info": "Type of sender.",
+ "name": "sender",
+ "options": [
+ "Machine",
+ "User"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "Machine"
+ },
+ "sender_name": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Sender Name",
+ "dynamic": false,
+ "info": "Name of the sender.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "sender_name",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "AI"
+ },
+ "session_id": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Session ID",
+ "dynamic": false,
+ "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "session_id",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ },
+ "should_store_message": {
+ "_input_type": "BoolInput",
+ "advanced": true,
+ "display_name": "Store Messages",
+ "dynamic": false,
+ "info": "Store the message in the history.",
+ "list": false,
+ "name": "should_store_message",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "trace_as_metadata": true,
+ "type": "bool",
+ "value": true
+ },
+ "text_color": {
+ "_input_type": "MessageTextInput",
+ "advanced": true,
+ "display_name": "Text Color",
+ "dynamic": false,
+ "info": "The text color of the name",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "text_color",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ }
+ },
+ "tool_mode": false
+ },
+ "type": "ChatOutput"
+ },
+ "dragging": false,
+ "height": 233,
+ "id": "ChatOutput-MXQER",
+ "position": {
+ "x": 2683.9938458383212,
+ "y": 556.5828467235146
+ },
+ "positionAbsolute": {
+ "x": 2683.9938458383212,
+ "y": 556.5828467235146
+ },
+ "selected": false,
+ "type": "genericNode",
+ "width": 320
+ },
+ {
+ "data": {
+ "id": "URL-kae98",
+ "node": {
+ "base_classes": [
+ "Data",
+ "Message"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Fetch content from one or more URLs.",
+ "display_name": "URL",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "urls",
+ "format"
+ ],
+ "frozen": false,
+ "icon": "layout-template",
+ "legacy": false,
+ "lf_version": "1.1.0.dev4",
+ "metadata": {},
+ "output_types": [],
+ "outputs": [
+ {
+ "cache": true,
+ "display_name": "Data",
+ "method": "fetch_content",
+ "name": "data",
+ "selected": "Data",
+ "types": [
+ "Data"
+ ],
+ "value": "__UNDEFINED__"
+ },
+ {
+ "cache": true,
+ "display_name": "Text",
+ "method": "fetch_content_text",
+ "name": "text",
+ "selected": "Message",
+ "types": [
+ "Message"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "code": {
+ "advanced": true,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "import re\n\nfrom langchain_community.document_loaders import AsyncHtmlLoader, WebBaseLoader\n\nfrom langflow.custom import Component\nfrom langflow.helpers.data import data_to_text\nfrom langflow.io import DropdownInput, MessageTextInput, Output\nfrom langflow.schema import Data\nfrom langflow.schema.message import Message\n\n\nclass URLComponent(Component):\n display_name = \"URL\"\n description = \"Fetch content from one or more URLs.\"\n icon = \"layout-template\"\n name = \"URL\"\n\n inputs = [\n MessageTextInput(\n name=\"urls\",\n display_name=\"URLs\",\n info=\"Enter one or more URLs, by clicking the '+' button.\",\n is_list=True,\n tool_mode=True,\n ),\n DropdownInput(\n name=\"format\",\n display_name=\"Output Format\",\n info=\"Output Format. Use 'Text' to extract the text from the HTML or 'Raw HTML' for the raw HTML content.\",\n options=[\"Text\", \"Raw HTML\"],\n value=\"Text\",\n ),\n ]\n\n outputs = [\n Output(display_name=\"Data\", name=\"data\", method=\"fetch_content\"),\n Output(display_name=\"Text\", name=\"text\", method=\"fetch_content_text\"),\n ]\n\n def ensure_url(self, string: str) -> str:\n \"\"\"Ensures the given string is a URL by adding 'http://' if it doesn't start with 'http://' or 'https://'.\n\n Raises an error if the string is not a valid URL.\n\n Parameters:\n string (str): The string to be checked and possibly modified.\n\n Returns:\n str: The modified string that is ensured to be a URL.\n\n Raises:\n ValueError: If the string is not a valid URL.\n \"\"\"\n if not string.startswith((\"http://\", \"https://\")):\n string = \"http://\" + string\n\n # Basic URL validation regex\n url_regex = re.compile(\n r\"^(https?:\\/\\/)?\" # optional protocol\n r\"(www\\.)?\" # optional www\n r\"([a-zA-Z0-9.-]+)\" # domain\n r\"(\\.[a-zA-Z]{2,})?\" # top-level domain\n r\"(:\\d+)?\" # optional port\n r\"(\\/[^\\s]*)?$\", # optional path\n re.IGNORECASE,\n )\n\n if not url_regex.match(string):\n msg = f\"Invalid URL: {string}\"\n raise ValueError(msg)\n\n return string\n\n def fetch_content(self) -> list[Data]:\n urls = [self.ensure_url(url.strip()) for url in self.urls if url.strip()]\n if self.format == \"Raw HTML\":\n loader = AsyncHtmlLoader(web_path=urls, encoding=\"utf-8\")\n else:\n loader = WebBaseLoader(web_paths=urls, encoding=\"utf-8\")\n docs = loader.load()\n data = [Data(text=doc.page_content, **doc.metadata) for doc in docs]\n self.status = data\n return data\n\n def fetch_content_text(self) -> Message:\n data = self.fetch_content()\n\n result_string = data_to_text(\"{text}\", data)\n self.status = result_string\n return Message(text=result_string)\n"
+ },
+ "format": {
+ "_input_type": "DropdownInput",
+ "advanced": false,
+ "combobox": false,
+ "display_name": "Output Format",
+ "dynamic": false,
+ "info": "Output Format. Use 'Text' to extract the text from the HTML or 'Raw HTML' for the raw HTML content.",
+ "name": "format",
+ "options": [
+ "Text",
+ "Raw HTML"
+ ],
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": false,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": "Text"
+ },
+ "urls": {
+ "_input_type": "MessageTextInput",
+ "advanced": false,
+ "display_name": "URLs",
+ "dynamic": false,
+ "info": "Enter one or more URLs, by clicking the '+' button.",
+ "input_types": [
+ "Message"
+ ],
+ "list": true,
+ "load_from_db": false,
+ "name": "urls",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": true,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ }
+ },
+ "tool_mode": false
+ },
+ "type": "URL"
+ },
+ "dragging": false,
+ "height": 319,
+ "id": "URL-kae98",
+ "position": {
+ "x": 1942.2313716725494,
+ "y": 301.6632034906458
+ },
+ "positionAbsolute": {
+ "x": 1942.2313716725494,
+ "y": 301.6632034906458
+ },
+ "selected": false,
+ "type": "genericNode",
+ "width": 320
+ },
+ {
+ "data": {
+ "id": "CalculatorTool-JxFks",
+ "node": {
+ "base_classes": [
+ "Data",
+ "Tool"
+ ],
+ "beta": false,
+ "conditional_paths": [],
+ "custom_fields": {},
+ "description": "Perform basic arithmetic operations on a given expression.",
+ "display_name": "Calculator",
+ "documentation": "",
+ "edited": false,
+ "field_order": [
+ "expression"
+ ],
+ "frozen": false,
+ "icon": "calculator",
+ "legacy": false,
+ "lf_version": "1.1.0.dev4",
+ "metadata": {},
+ "output_types": [],
+ "outputs": [
+ {
+ "cache": true,
+ "display_name": "Data",
+ "method": "run_model",
+ "name": "api_run_model",
+ "required_inputs": [],
+ "selected": "Data",
+ "types": [
+ "Data"
+ ],
+ "value": "__UNDEFINED__"
+ },
+ {
+ "cache": true,
+ "display_name": "Tool",
+ "method": "build_tool",
+ "name": "api_build_tool",
+ "required_inputs": [],
+ "selected": "Tool",
+ "types": [
+ "Tool"
+ ],
+ "value": "__UNDEFINED__"
+ }
+ ],
+ "pinned": false,
+ "template": {
+ "_type": "Component",
+ "code": {
+ "advanced": true,
+ "dynamic": true,
+ "fileTypes": [],
+ "file_path": "",
+ "info": "",
+ "list": false,
+ "load_from_db": false,
+ "multiline": true,
+ "name": "code",
+ "password": false,
+ "placeholder": "",
+ "required": true,
+ "show": true,
+ "title_case": false,
+ "type": "code",
+ "value": "import ast\nimport operator\n\nfrom langchain.tools import StructuredTool\nfrom langchain_core.tools import ToolException\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import MessageTextInput\nfrom langflow.schema import Data\n\n\nclass CalculatorToolComponent(LCToolComponent):\n display_name = \"Calculator\"\n description = \"Perform basic arithmetic operations on a given expression.\"\n icon = \"calculator\"\n name = \"CalculatorTool\"\n\n inputs = [\n MessageTextInput(\n name=\"expression\",\n display_name=\"Expression\",\n info=\"The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').\",\n ),\n ]\n\n class CalculatorToolSchema(BaseModel):\n expression: str = Field(..., description=\"The arithmetic expression to evaluate.\")\n\n def run_model(self) -> list[Data]:\n return self._evaluate_expression(self.expression)\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"calculator\",\n description=\"Evaluate basic arithmetic expressions. Input should be a string containing the expression.\",\n func=self._eval_expr_with_error,\n args_schema=self.CalculatorToolSchema,\n )\n\n def _eval_expr(self, node):\n # Define the allowed operators\n operators = {\n ast.Add: operator.add,\n ast.Sub: operator.sub,\n ast.Mult: operator.mul,\n ast.Div: operator.truediv,\n ast.Pow: operator.pow,\n }\n if isinstance(node, ast.Num):\n return node.n\n if isinstance(node, ast.BinOp):\n return operators[type(node.op)](self._eval_expr(node.left), self._eval_expr(node.right))\n if isinstance(node, ast.UnaryOp):\n return operators[type(node.op)](self._eval_expr(node.operand))\n if isinstance(node, ast.Call):\n msg = (\n \"Function calls like sqrt(), sin(), cos() etc. are not supported. \"\n \"Only basic arithmetic operations (+, -, *, /, **) are allowed.\"\n )\n raise TypeError(msg)\n msg = f\"Unsupported operation or expression type: {type(node).__name__}\"\n raise TypeError(msg)\n\n def _eval_expr_with_error(self, expression: str) -> list[Data]:\n try:\n return self._evaluate_expression(expression)\n except Exception as e:\n raise ToolException(str(e)) from e\n\n def _evaluate_expression(self, expression: str) -> list[Data]:\n try:\n # Parse the expression and evaluate it\n tree = ast.parse(expression, mode=\"eval\")\n result = self._eval_expr(tree.body)\n\n # Format the result to a reasonable number of decimal places\n formatted_result = f\"{result:.6f}\".rstrip(\"0\").rstrip(\".\")\n\n self.status = formatted_result\n return [Data(data={\"result\": formatted_result})]\n\n except (SyntaxError, TypeError, KeyError) as e:\n error_message = f\"Invalid expression: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n except ZeroDivisionError:\n error_message = \"Error: Division by zero\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n except Exception as e: # noqa: BLE001\n logger.opt(exception=True).debug(\"Error evaluating expression\")\n error_message = f\"Error: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message, \"input\": expression})]\n"
+ },
+ "expression": {
+ "_input_type": "MessageTextInput",
+ "advanced": false,
+ "display_name": "Expression",
+ "dynamic": false,
+ "info": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').",
+ "input_types": [
+ "Message"
+ ],
+ "list": false,
+ "load_from_db": false,
+ "name": "expression",
+ "placeholder": "",
+ "required": false,
+ "show": true,
+ "title_case": false,
+ "tool_mode": true,
+ "trace_as_input": true,
+ "trace_as_metadata": true,
+ "type": "str",
+ "value": ""
+ }
+ },
+ "tool_mode": false
+ },
+ "type": "CalculatorTool"
+ },
+ "dragging": false,
+ "height": 253,
+ "id": "CalculatorTool-JxFks",
+ "position": {
+ "x": 1938.2271796804105,
+ "y": 626.1679381318158
+ },
+ "positionAbsolute": {
+ "x": 1938.2271796804105,
+ "y": 626.1679381318158
+ },
+ "selected": false,
+ "type": "genericNode",
+ "width": 320
+ },
+ {
+ "data": {
+ "id": "note-2Ag8D",
+ "node": {
+ "description": "# 📖 README\nRun an Agent with URL and Calculator tools available for its use. \nThe Agent decides which tool to use to solve a problem.\n## Quick start\n\n1. Add your OpenAI API key to the Agent.\n2. Open the Playground and chat with the Agent. Request some information about a recipe, and then ask to add two numbers together. In the responses, the Agent will use different tools to solve different problems.\n\n## Next steps\nConnect more tools to the Agent to create your perfect assistant.\n\nFor more, see the [Langflow docs](https://docs.langflow.org/agents-tool-calling-agent-component).",
+ "display_name": "",
+ "documentation": "",
+ "template": {
+ "backgroundColor": "neutral"
+ }
+ },
+ "type": "note"
+ },
+ "dragging": false,
+ "height": 571,
+ "id": "note-2Ag8D",
+ "position": {
+ "x": 1314.267618793912,
+ "y": 323.12512509078374
+ },
+ "positionAbsolute": {
+ "x": 1314.267618793912,
+ "y": 323.12512509078374
+ },
+ "resizing": false,
+ "selected": false,
+ "style": {
+ "height": 571,
+ "width": 600
+ },
+ "type": "noteNode",
+ "width": 600
+ },
+ {
+ "data": {
+ "id": "note-C3J4h",
+ "node": {
+ "description": "### 💡 Add your OpenAI API key here👇",
+ "display_name": "",
+ "documentation": "",
+ "template": {
+ "backgroundColor": "transparent"
+ }
+ },
+ "type": "note"
+ },
+ "dragging": false,
+ "height": 324,
+ "id": "note-C3J4h",
+ "position": {
+ "x": 2302.9552933034743,
+ "y": 288.4851054994825
+ },
+ "positionAbsolute": {
+ "x": 2302.9552933034743,
+ "y": 288.4851054994825
+ },
+ "resizing": false,
+ "selected": false,
+ "style": {
+ "height": 324,
+ "width": 330
+ },
+ "type": "noteNode",
+ "width": 330
+ }
+ ],
+ "viewport": {
+ "x": -1004.3169636975567,
+ "y": -120.95585414190066,
+ "zoom": 0.8212388148365221
+ }
+ },
+ "description": "A simple but powerful starter agent.",
+ "endpoint_name": null,
+ "id": "84152f18-d493-4cfe-a51c-38a7f717be19",
+ "is_component": false,
+ "last_tested_version": "1.1.0.dev4",
+ "name": "Simple Agent",
+ "tags": [
+ "assistants",
+ "agents"
+ ]
+}
\ No newline at end of file
diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json b/src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json
index ef99db20f4a..e599b9b2656 100644
--- a/src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json
+++ b/src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json
@@ -996,7 +996,7 @@
"data": {
"id": "note-UrQ0p",
"node": {
- "description": "## 📚 1. Load Data Flow\n\nRun this first! Load data from a local file and embed it into the vector database.\n\nSelect a Database and a Collection, or create new ones. \n\nClick ▶️ **Run component** on the **Astra DB** component to load your data.\n\n*If you're using OSS Langflow, add your Astra DB Application Token to the Astra DB component.\n\n#### Next steps:\n Experiment by changing the prompt and the contextual data to see how the retrieval flow's responses change.",
+ "description": "## 📚 1. Load Data Flow\n\nRun this first! Load data from a local file and embed it into the vector database.\n\nSelect a Database and a Collection, or create new ones. \n\nClick ▶️ **Run component** on the **Astra DB** component to load your data.\n\n* If you're using OSS Langflow, add your Astra DB Application Token to the Astra DB component.\n\n#### Next steps:\n Experiment by changing the prompt and the contextual data to see how the retrieval flow's responses change.",
"display_name": "",
"documentation": "",
"template": {
@@ -1029,7 +1029,7 @@
"data": {
"id": "note-39jdn",
"node": {
- "description": "## 📖 README\n\nLoad your data into a vector database with the 📚 **Load Data** flow, and then use your data as chat context with the 🐕 **Retriever** flow.\n\n**🚨 Add your OpenAI API key as a global variable to easily add it to all of the OpenAI components in this flow.** \n\n**Quick start**:\n1. Run the 📚 **Load Data** flow.\n2. Run the 🐕 **Retriever** flow.\n\n**Next steps** \n\n- Experiment by changing the prompt and the loaded data to see how the bot's responses change. \n\nFor more info, see the [Langflow docs](https://docs.langflow.org/starter-projects-vector-store-rag).",
+ "description": "## 📖 README\n\nLoad your data into a vector database with the 📚 **Load Data** flow, and then use your data as chat context with the 🐕 **Retriever** flow.\n\n**🚨 Add your OpenAI API key as a global variable to easily add it to all of the OpenAI components in this flow.** \n\n**Quick start**\n1. Run the 📚 **Load Data** flow.\n2. Run the 🐕 **Retriever** flow.\n\n**Next steps** \n\n- Experiment by changing the prompt and the loaded data to see how the bot's responses change. \n\nFor more info, see the [Langflow docs](https://docs.langflow.org/starter-projects-vector-store-rag).",
"display_name": "Read Me",
"documentation": "",
"template": {
@@ -1873,7 +1873,7 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "import os\n\nimport orjson\nfrom astrapy.admin import parse_api_endpoint\nfrom langchain_astradb import AstraDBVectorStore\n\nfrom langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom langflow.helpers import docs_to_data\nfrom langflow.inputs import DictInput, FloatInput, MessageTextInput, NestedDictInput\nfrom langflow.io import (\n BoolInput,\n DataInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n SecretStrInput,\n StrInput,\n)\nfrom langflow.schema import Data\n\n\nclass AstraVectorStoreComponent(LCVectorStoreComponent):\n display_name: str = \"Astra DB\"\n description: str = \"Implementation of Vector Store using Astra DB with search capabilities\"\n documentation: str = \"https://docs.langflow.org/starter-projects-vector-store-rag\"\n name = \"AstraDB\"\n icon: str = \"AstraDB\"\n\n _cached_vector_store: AstraDBVectorStore | None = None\n\n VECTORIZE_PROVIDERS_MAPPING = {\n \"Azure OpenAI\": [\"azureOpenAI\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Hugging Face - Dedicated\": [\"huggingfaceDedicated\", [\"endpoint-defined-model\"]],\n \"Hugging Face - Serverless\": [\n \"huggingface\",\n [\n \"sentence-transformers/all-MiniLM-L6-v2\",\n \"intfloat/multilingual-e5-large\",\n \"intfloat/multilingual-e5-large-instruct\",\n \"BAAI/bge-small-en-v1.5\",\n \"BAAI/bge-base-en-v1.5\",\n \"BAAI/bge-large-en-v1.5\",\n ],\n ],\n \"Jina AI\": [\n \"jinaAI\",\n [\n \"jina-embeddings-v2-base-en\",\n \"jina-embeddings-v2-base-de\",\n \"jina-embeddings-v2-base-es\",\n \"jina-embeddings-v2-base-code\",\n \"jina-embeddings-v2-base-zh\",\n ],\n ],\n \"Mistral AI\": [\"mistral\", [\"mistral-embed\"]],\n \"NVIDIA\": [\"nvidia\", [\"NV-Embed-QA\"]],\n \"OpenAI\": [\"openai\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Upstage\": [\"upstageAI\", [\"solar-embedding-1-large\"]],\n \"Voyage AI\": [\n \"voyageAI\",\n [\"voyage-large-2-instruct\", \"voyage-law-2\", \"voyage-code-2\", \"voyage-large-2\", \"voyage-2\"],\n ],\n }\n\n inputs = [\n SecretStrInput(\n name=\"token\",\n display_name=\"Astra DB Application Token\",\n info=\"Authentication token for accessing Astra DB.\",\n value=\"ASTRA_DB_APPLICATION_TOKEN\",\n required=True,\n advanced=os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\",\n ),\n SecretStrInput(\n name=\"api_endpoint\",\n display_name=\"Database\" if os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\" else \"API Endpoint\",\n info=\"API endpoint URL for the Astra DB service.\",\n value=\"ASTRA_DB_API_ENDPOINT\",\n required=True,\n ),\n StrInput(\n name=\"collection_name\",\n display_name=\"Collection Name\",\n info=\"The name of the collection within Astra DB where the vectors will be stored.\",\n required=True,\n ),\n MultilineInput(\n name=\"search_input\",\n display_name=\"Search Input\",\n ),\n DataInput(\n name=\"ingest_data\",\n display_name=\"Ingest Data\",\n is_list=True,\n ),\n StrInput(\n name=\"keyspace\",\n display_name=\"Keyspace\",\n info=\"Optional keyspace within Astra DB to use for the collection.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"embedding_choice\",\n display_name=\"Embedding Model or Astra Vectorize\",\n info=\"Determines whether to use Astra Vectorize for the collection.\",\n options=[\"Embedding Model\", \"Astra Vectorize\"],\n real_time_refresh=True,\n value=\"Embedding Model\",\n ),\n HandleInput(\n name=\"embedding\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ),\n DropdownInput(\n name=\"metric\",\n display_name=\"Metric\",\n info=\"Optional distance metric for vector comparisons in the vector store.\",\n options=[\"cosine\", \"dot_product\", \"euclidean\"],\n value=\"cosine\",\n advanced=True,\n ),\n IntInput(\n name=\"batch_size\",\n display_name=\"Batch Size\",\n info=\"Optional number of data to process in a single batch.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_batch_concurrency\",\n display_name=\"Bulk Insert Batch Concurrency\",\n info=\"Optional concurrency level for bulk insert operations.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_overwrite_concurrency\",\n display_name=\"Bulk Insert Overwrite Concurrency\",\n info=\"Optional concurrency level for bulk insert operations that overwrite existing data.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_delete_concurrency\",\n display_name=\"Bulk Delete Concurrency\",\n info=\"Optional concurrency level for bulk delete operations.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"setup_mode\",\n display_name=\"Setup Mode\",\n info=\"Configuration mode for setting up the vector store, with options like 'Sync' or 'Off'.\",\n options=[\"Sync\", \"Off\"],\n advanced=True,\n value=\"Sync\",\n ),\n BoolInput(\n name=\"pre_delete_collection\",\n display_name=\"Pre Delete Collection\",\n info=\"Boolean flag to determine whether to delete the collection before creating a new one.\",\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_include\",\n display_name=\"Metadata Indexing Include\",\n info=\"Optional list of metadata fields to include in the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_exclude\",\n display_name=\"Metadata Indexing Exclude\",\n info=\"Optional list of metadata fields to exclude from the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"collection_indexing_policy\",\n display_name=\"Collection Indexing Policy\",\n info='Optional JSON string for the \"indexing\" field of the collection. '\n \"See https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option\",\n advanced=True,\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Number of Results\",\n info=\"Number of results to return.\",\n advanced=True,\n value=4,\n ),\n DropdownInput(\n name=\"search_type\",\n display_name=\"Search Type\",\n info=\"Search type to use\",\n options=[\"Similarity\", \"Similarity with score threshold\", \"MMR (Max Marginal Relevance)\"],\n value=\"Similarity\",\n advanced=True,\n ),\n FloatInput(\n name=\"search_score_threshold\",\n display_name=\"Search Score Threshold\",\n info=\"Minimum similarity score threshold for search results. \"\n \"(when using 'Similarity with score threshold')\",\n value=0,\n advanced=True,\n ),\n NestedDictInput(\n name=\"advanced_search_filter\",\n display_name=\"Search Metadata Filter\",\n info=\"Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n ),\n DictInput(\n name=\"search_filter\",\n display_name=\"[DEPRECATED] Search Metadata Filter\",\n info=\"Deprecated: use advanced_search_filter. Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n is_list=True,\n ),\n ]\n\n def del_fields(self, build_config, field_list):\n for field in field_list:\n if field in build_config:\n del build_config[field]\n\n return build_config\n\n def insert_in_dict(self, build_config, field_name, new_parameters):\n # Insert the new key-value pair after the found key\n for new_field_name, new_parameter in new_parameters.items():\n # Get all the items as a list of tuples (key, value)\n items = list(build_config.items())\n\n # Find the index of the key to insert after\n idx = len(items)\n for i, (key, _) in enumerate(items):\n if key == field_name:\n idx = i + 1\n break\n\n items.insert(idx, (new_field_name, new_parameter))\n\n # Clear the original dictionary and update with the modified items\n build_config.clear()\n build_config.update(items)\n\n return build_config\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n if field_name == \"embedding_choice\":\n if field_value == \"Astra Vectorize\":\n self.del_fields(build_config, [\"embedding\"])\n\n new_parameter = DropdownInput(\n name=\"embedding_provider\",\n display_name=\"Embedding Provider\",\n options=self.VECTORIZE_PROVIDERS_MAPPING.keys(),\n value=\"\",\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_provider\": new_parameter})\n else:\n self.del_fields(\n build_config,\n [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ],\n )\n\n new_parameter = HandleInput(\n name=\"embedding\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding\": new_parameter})\n\n elif field_name == \"embedding_provider\":\n self.del_fields(\n build_config,\n [\"model\", \"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n model_options = self.VECTORIZE_PROVIDERS_MAPPING[field_value][1]\n\n new_parameter = DropdownInput(\n name=\"model\",\n display_name=\"Model\",\n info=\"The embedding model to use for the selected provider. Each provider has a different set of \"\n \"models available (full list at \"\n \"https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html):\\n\\n\"\n f\"{', '.join(model_options)}\",\n options=model_options,\n value=None,\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_provider\", {\"model\": new_parameter})\n\n elif field_name == \"model\":\n self.del_fields(\n build_config,\n [\"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n new_parameter_1 = DictInput(\n name=\"z_01_model_parameters\",\n display_name=\"Model Parameters\",\n is_list=True,\n ).to_dict()\n\n new_parameter_2 = MessageTextInput(\n name=\"z_02_api_key_name\",\n display_name=\"API Key Name\",\n info=\"The name of the embeddings provider API key stored on Astra. \"\n \"If set, it will override the 'ProviderKey' in the authentication parameters.\",\n ).to_dict()\n\n new_parameter_3 = SecretStrInput(\n load_from_db=False,\n name=\"z_03_provider_api_key\",\n display_name=\"Provider API Key\",\n info=\"An alternative to the Astra Authentication that passes an API key for the provider \"\n \"with each request to Astra DB. \"\n \"This may be used when Vectorize is configured for the collection, \"\n \"but no corresponding provider secret is stored within Astra's key management system.\",\n ).to_dict()\n\n new_parameter_4 = DictInput(\n name=\"z_04_authentication\",\n display_name=\"Authentication Parameters\",\n is_list=True,\n ).to_dict()\n\n self.insert_in_dict(\n build_config,\n \"model\",\n {\n \"z_01_model_parameters\": new_parameter_1,\n \"z_02_api_key_name\": new_parameter_2,\n \"z_03_provider_api_key\": new_parameter_3,\n \"z_04_authentication\": new_parameter_4,\n },\n )\n\n return build_config\n\n def build_vectorize_options(self, **kwargs):\n for attribute in [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ]:\n if not hasattr(self, attribute):\n setattr(self, attribute, None)\n\n # Fetch values from kwargs if any self.* attributes are None\n provider_value = self.VECTORIZE_PROVIDERS_MAPPING.get(self.embedding_provider, [None])[0] or kwargs.get(\n \"embedding_provider\"\n )\n model_name = self.model or kwargs.get(\"model\")\n authentication = {**(self.z_04_authentication or kwargs.get(\"z_04_authentication\", {}))}\n parameters = self.z_01_model_parameters or kwargs.get(\"z_01_model_parameters\", {})\n\n # Set the API key name if provided\n api_key_name = self.z_02_api_key_name or kwargs.get(\"z_02_api_key_name\")\n provider_key = self.z_03_provider_api_key or kwargs.get(\"z_03_provider_api_key\")\n if api_key_name:\n authentication[\"providerKey\"] = api_key_name\n\n # Set authentication and parameters to None if no values are provided\n if not authentication:\n authentication = None\n if not parameters:\n parameters = None\n\n return {\n # must match astrapy.info.CollectionVectorServiceOptions\n \"collection_vector_service_options\": {\n \"provider\": provider_value,\n \"modelName\": model_name,\n \"authentication\": authentication,\n \"parameters\": parameters,\n },\n \"collection_embedding_api_key\": provider_key,\n }\n\n @check_cached_vector_store\n def build_vector_store(self, vectorize_options=None):\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError as e:\n msg = (\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n raise ImportError(msg) from e\n\n try:\n if not self.setup_mode:\n self.setup_mode = self._inputs[\"setup_mode\"].options[0]\n\n setup_mode_value = SetupMode[self.setup_mode.upper()]\n except KeyError as e:\n msg = f\"Invalid setup mode: {self.setup_mode}\"\n raise ValueError(msg) from e\n\n if self.embedding_choice == \"Embedding Model\":\n embedding_dict = {\"embedding\": self.embedding}\n else:\n from astrapy.info import CollectionVectorServiceOptions\n\n # Fetch values from kwargs if any self.* attributes are None\n dict_options = vectorize_options or self.build_vectorize_options()\n\n # Set the embedding dictionary\n embedding_dict = {\n \"collection_vector_service_options\": CollectionVectorServiceOptions.from_dict(\n dict_options.get(\"collection_vector_service_options\")\n ),\n \"collection_embedding_api_key\": dict_options.get(\"collection_embedding_api_key\"),\n }\n\n try:\n vector_store = AstraDBVectorStore(\n collection_name=self.collection_name,\n token=self.token,\n api_endpoint=self.api_endpoint,\n namespace=self.keyspace or None,\n environment=parse_api_endpoint(self.api_endpoint).environment if self.api_endpoint else None,\n metric=self.metric or None,\n batch_size=self.batch_size or None,\n bulk_insert_batch_concurrency=self.bulk_insert_batch_concurrency or None,\n bulk_insert_overwrite_concurrency=self.bulk_insert_overwrite_concurrency or None,\n bulk_delete_concurrency=self.bulk_delete_concurrency or None,\n setup_mode=setup_mode_value,\n pre_delete_collection=self.pre_delete_collection,\n metadata_indexing_include=[s for s in self.metadata_indexing_include if s] or None,\n metadata_indexing_exclude=[s for s in self.metadata_indexing_exclude if s] or None,\n collection_indexing_policy=orjson.dumps(self.collection_indexing_policy)\n if self.collection_indexing_policy\n else None,\n **embedding_dict,\n )\n except Exception as e:\n msg = f\"Error initializing AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self._add_documents_to_vector_store(vector_store)\n\n return vector_store\n\n def _add_documents_to_vector_store(self, vector_store) -> None:\n documents = []\n for _input in self.ingest_data or []:\n if isinstance(_input, Data):\n documents.append(_input.to_lc_document())\n else:\n msg = \"Vector Store Inputs must be Data objects.\"\n raise TypeError(msg)\n\n if documents:\n self.log(f\"Adding {len(documents)} documents to the Vector Store.\")\n try:\n vector_store.add_documents(documents)\n except Exception as e:\n msg = f\"Error adding documents to AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n else:\n self.log(\"No documents to add to the Vector Store.\")\n\n def _map_search_type(self) -> str:\n if self.search_type == \"Similarity with score threshold\":\n return \"similarity_score_threshold\"\n if self.search_type == \"MMR (Max Marginal Relevance)\":\n return \"mmr\"\n return \"similarity\"\n\n def _build_search_args(self):\n query = self.search_input if isinstance(self.search_input, str) and self.search_input.strip() else None\n search_filter = (\n {k: v for k, v in self.search_filter.items() if k and v and k.strip()} if self.search_filter else None\n )\n\n if query:\n args = {\n \"query\": query,\n \"search_type\": self._map_search_type(),\n \"k\": self.number_of_results,\n \"score_threshold\": self.search_score_threshold,\n }\n elif self.advanced_search_filter or search_filter:\n args = {\n \"n\": self.number_of_results,\n }\n else:\n return {}\n\n filter_arg = self.advanced_search_filter or {}\n\n if search_filter:\n self.log(self.log(f\"`search_filter` is deprecated. Use `advanced_search_filter`. Cleaned: {search_filter}\"))\n filter_arg.update(search_filter)\n\n if filter_arg:\n args[\"filter\"] = filter_arg\n\n return args\n\n def search_documents(self, vector_store=None) -> list[Data]:\n vector_store = vector_store or self.build_vector_store()\n\n self.log(f\"Search input: {self.search_input}\")\n self.log(f\"Search type: {self.search_type}\")\n self.log(f\"Number of results: {self.number_of_results}\")\n\n try:\n search_args = self._build_search_args()\n except Exception as e:\n msg = f\"Error in AstraDBVectorStore._build_search_args: {e}\"\n raise ValueError(msg) from e\n\n if not search_args:\n self.log(\"No search input or filters provided. Skipping search.\")\n return []\n\n docs = []\n search_method = \"search\" if \"query\" in search_args else \"metadata_search\"\n\n try:\n self.log(f\"Calling vector_store.{search_method} with args: {search_args}\")\n docs = getattr(vector_store, search_method)(**search_args)\n except Exception as e:\n msg = f\"Error performing {search_method} in AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self.log(f\"Retrieved documents: {len(docs)}\")\n\n data = docs_to_data(docs)\n self.log(f\"Converted documents to data: {len(data)}\")\n self.status = data\n return data\n\n def get_retriever_kwargs(self):\n search_args = self._build_search_args()\n return {\n \"search_type\": self._map_search_type(),\n \"search_kwargs\": search_args,\n }\n"
+ "value": "import os\nfrom collections import defaultdict\n\nimport orjson\nfrom astrapy import DataAPIClient\nfrom astrapy.admin import parse_api_endpoint\nfrom langchain_astradb import AstraDBVectorStore\n\nfrom langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom langflow.helpers import docs_to_data\nfrom langflow.inputs import DictInput, FloatInput, MessageTextInput, NestedDictInput\nfrom langflow.io import (\n BoolInput,\n DataInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n SecretStrInput,\n StrInput,\n)\nfrom langflow.schema import Data\n\n\nclass AstraVectorStoreComponent(LCVectorStoreComponent):\n display_name: str = \"Astra DB\"\n description: str = \"Implementation of Vector Store using Astra DB with search capabilities\"\n documentation: str = \"https://docs.langflow.org/starter-projects-vector-store-rag\"\n name = \"AstraDB\"\n icon: str = \"AstraDB\"\n\n _cached_vector_store: AstraDBVectorStore | None = None\n\n VECTORIZE_PROVIDERS_MAPPING = defaultdict(\n list,\n {\n \"Azure OpenAI\": [\n \"azureOpenAI\",\n [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"],\n ],\n \"Hugging Face - Dedicated\": [\"huggingfaceDedicated\", [\"endpoint-defined-model\"]],\n \"Hugging Face - Serverless\": [\n \"huggingface\",\n [\n \"sentence-transformers/all-MiniLM-L6-v2\",\n \"intfloat/multilingual-e5-large\",\n \"intfloat/multilingual-e5-large-instruct\",\n \"BAAI/bge-small-en-v1.5\",\n \"BAAI/bge-base-en-v1.5\",\n \"BAAI/bge-large-en-v1.5\",\n ],\n ],\n \"Jina AI\": [\n \"jinaAI\",\n [\n \"jina-embeddings-v2-base-en\",\n \"jina-embeddings-v2-base-de\",\n \"jina-embeddings-v2-base-es\",\n \"jina-embeddings-v2-base-code\",\n \"jina-embeddings-v2-base-zh\",\n ],\n ],\n \"Mistral AI\": [\"mistral\", [\"mistral-embed\"]],\n \"NVIDIA\": [\"nvidia\", [\"NV-Embed-QA\"]],\n \"OpenAI\": [\"openai\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Upstage\": [\"upstageAI\", [\"solar-embedding-1-large\"]],\n \"Voyage AI\": [\n \"voyageAI\",\n [\"voyage-large-2-instruct\", \"voyage-law-2\", \"voyage-code-2\", \"voyage-large-2\", \"voyage-2\"],\n ],\n },\n )\n\n inputs = [\n SecretStrInput(\n name=\"token\",\n display_name=\"Astra DB Application Token\",\n info=\"Authentication token for accessing Astra DB.\",\n value=\"ASTRA_DB_APPLICATION_TOKEN\",\n required=True,\n advanced=os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\",\n ),\n SecretStrInput(\n name=\"api_endpoint\",\n display_name=\"Database\" if os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\" else \"API Endpoint\",\n info=\"API endpoint URL for the Astra DB service.\",\n value=\"ASTRA_DB_API_ENDPOINT\",\n required=True,\n ),\n StrInput(\n name=\"collection_name\",\n display_name=\"Collection Name\",\n info=\"The name of the collection within Astra DB where the vectors will be stored.\",\n required=True,\n ),\n MultilineInput(\n name=\"search_input\",\n display_name=\"Search Input\",\n ),\n DataInput(\n name=\"ingest_data\",\n display_name=\"Ingest Data\",\n is_list=True,\n ),\n StrInput(\n name=\"keyspace\",\n display_name=\"Keyspace\",\n info=\"Optional keyspace within Astra DB to use for the collection.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"embedding_choice\",\n display_name=\"Embedding Model or Astra Vectorize\",\n info=\"Determines whether to use Astra Vectorize for the collection.\",\n options=[\"Embedding Model\", \"Astra Vectorize\"],\n real_time_refresh=True,\n value=\"Embedding Model\",\n ),\n HandleInput(\n name=\"embedding_model\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ),\n DropdownInput(\n name=\"metric\",\n display_name=\"Metric\",\n info=\"Optional distance metric for vector comparisons in the vector store.\",\n options=[\"cosine\", \"dot_product\", \"euclidean\"],\n value=\"cosine\",\n advanced=True,\n ),\n IntInput(\n name=\"batch_size\",\n display_name=\"Batch Size\",\n info=\"Optional number of data to process in a single batch.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_batch_concurrency\",\n display_name=\"Bulk Insert Batch Concurrency\",\n info=\"Optional concurrency level for bulk insert operations.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_overwrite_concurrency\",\n display_name=\"Bulk Insert Overwrite Concurrency\",\n info=\"Optional concurrency level for bulk insert operations that overwrite existing data.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_delete_concurrency\",\n display_name=\"Bulk Delete Concurrency\",\n info=\"Optional concurrency level for bulk delete operations.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"setup_mode\",\n display_name=\"Setup Mode\",\n info=\"Configuration mode for setting up the vector store, with options like 'Sync' or 'Off'.\",\n options=[\"Sync\", \"Off\"],\n advanced=True,\n value=\"Sync\",\n ),\n BoolInput(\n name=\"pre_delete_collection\",\n display_name=\"Pre Delete Collection\",\n info=\"Boolean flag to determine whether to delete the collection before creating a new one.\",\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_include\",\n display_name=\"Metadata Indexing Include\",\n info=\"Optional list of metadata fields to include in the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_exclude\",\n display_name=\"Metadata Indexing Exclude\",\n info=\"Optional list of metadata fields to exclude from the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"collection_indexing_policy\",\n display_name=\"Collection Indexing Policy\",\n info='Optional JSON string for the \"indexing\" field of the collection. '\n \"See https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option\",\n advanced=True,\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Number of Results\",\n info=\"Number of results to return.\",\n advanced=True,\n value=4,\n ),\n DropdownInput(\n name=\"search_type\",\n display_name=\"Search Type\",\n info=\"Search type to use\",\n options=[\"Similarity\", \"Similarity with score threshold\", \"MMR (Max Marginal Relevance)\"],\n value=\"Similarity\",\n advanced=True,\n ),\n FloatInput(\n name=\"search_score_threshold\",\n display_name=\"Search Score Threshold\",\n info=\"Minimum similarity score threshold for search results. \"\n \"(when using 'Similarity with score threshold')\",\n value=0,\n advanced=True,\n ),\n NestedDictInput(\n name=\"advanced_search_filter\",\n display_name=\"Search Metadata Filter\",\n info=\"Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n ),\n DictInput(\n name=\"search_filter\",\n display_name=\"[DEPRECATED] Search Metadata Filter\",\n info=\"Deprecated: use advanced_search_filter. Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n is_list=True,\n ),\n ]\n\n def del_fields(self, build_config, field_list):\n for field in field_list:\n if field in build_config:\n del build_config[field]\n\n return build_config\n\n def insert_in_dict(self, build_config, field_name, new_parameters):\n # Insert the new key-value pair after the found key\n for new_field_name, new_parameter in new_parameters.items():\n # Get all the items as a list of tuples (key, value)\n items = list(build_config.items())\n\n # Find the index of the key to insert after\n idx = len(items)\n for i, (key, _) in enumerate(items):\n if key == field_name:\n idx = i + 1\n break\n\n items.insert(idx, (new_field_name, new_parameter))\n\n # Clear the original dictionary and update with the modified items\n build_config.clear()\n build_config.update(items)\n\n return build_config\n\n def update_providers_mapping(self):\n # If we don't have token or api_endpoint, we can't fetch the list of providers\n if not self.token or not self.api_endpoint:\n self.log(\"Astra DB token and API endpoint are required to fetch the list of Vectorize providers.\")\n\n return self.VECTORIZE_PROVIDERS_MAPPING\n\n try:\n self.log(\"Dynamically updating list of Vectorize providers.\")\n\n # Get the admin object\n client = DataAPIClient(token=self.token)\n admin = client.get_admin()\n\n # Get the embedding providers\n db_admin = admin.get_database_admin(self.api_endpoint)\n embedding_providers = db_admin.find_embedding_providers().as_dict()\n\n vectorize_providers_mapping = {}\n\n # Map the provider display name to the provider key and models\n for provider_key, provider_data in embedding_providers[\"embeddingProviders\"].items():\n display_name = provider_data[\"displayName\"]\n models = [model[\"name\"] for model in provider_data[\"models\"]]\n\n vectorize_providers_mapping[display_name] = [provider_key, models]\n\n # Sort the resulting dictionary\n return defaultdict(list, dict(sorted(vectorize_providers_mapping.items())))\n except Exception as e: # noqa: BLE001\n self.log(f\"Error fetching Vectorize providers: {e}\")\n\n return self.VECTORIZE_PROVIDERS_MAPPING\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n if field_name == \"embedding_choice\":\n if field_value == \"Astra Vectorize\":\n self.del_fields(build_config, [\"embedding_model\"])\n\n # Update the providers mapping\n vectorize_providers = self.update_providers_mapping()\n\n new_parameter = DropdownInput(\n name=\"embedding_provider\",\n display_name=\"Embedding Provider\",\n options=vectorize_providers.keys(),\n value=\"\",\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_provider\": new_parameter})\n else:\n self.del_fields(\n build_config,\n [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ],\n )\n\n new_parameter = HandleInput(\n name=\"embedding_model\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_model\": new_parameter})\n\n elif field_name == \"embedding_provider\":\n self.del_fields(\n build_config,\n [\"model\", \"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n # Update the providers mapping\n vectorize_providers = self.update_providers_mapping()\n model_options = vectorize_providers[field_value][1]\n\n new_parameter = DropdownInput(\n name=\"model\",\n display_name=\"Model\",\n info=\"The embedding model to use for the selected provider. Each provider has a different set of \"\n \"models available (full list at \"\n \"https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html):\\n\\n\"\n f\"{', '.join(model_options)}\",\n options=model_options,\n value=None,\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_provider\", {\"model\": new_parameter})\n\n elif field_name == \"model\":\n self.del_fields(\n build_config,\n [\"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n new_parameter_1 = DictInput(\n name=\"z_01_model_parameters\",\n display_name=\"Model Parameters\",\n is_list=True,\n ).to_dict()\n\n new_parameter_2 = MessageTextInput(\n name=\"z_02_api_key_name\",\n display_name=\"API Key Name\",\n info=\"The name of the embeddings provider API key stored on Astra. \"\n \"If set, it will override the 'ProviderKey' in the authentication parameters.\",\n ).to_dict()\n\n new_parameter_3 = SecretStrInput(\n load_from_db=False,\n name=\"z_03_provider_api_key\",\n display_name=\"Provider API Key\",\n info=\"An alternative to the Astra Authentication that passes an API key for the provider \"\n \"with each request to Astra DB. \"\n \"This may be used when Vectorize is configured for the collection, \"\n \"but no corresponding provider secret is stored within Astra's key management system.\",\n ).to_dict()\n\n new_parameter_4 = DictInput(\n name=\"z_04_authentication\",\n display_name=\"Authentication Parameters\",\n is_list=True,\n ).to_dict()\n\n self.insert_in_dict(\n build_config,\n \"model\",\n {\n \"z_01_model_parameters\": new_parameter_1,\n \"z_02_api_key_name\": new_parameter_2,\n \"z_03_provider_api_key\": new_parameter_3,\n \"z_04_authentication\": new_parameter_4,\n },\n )\n\n return build_config\n\n def build_vectorize_options(self, **kwargs):\n for attribute in [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ]:\n if not hasattr(self, attribute):\n setattr(self, attribute, None)\n\n # Fetch values from kwargs if any self.* attributes are None\n provider_value = self.VECTORIZE_PROVIDERS_MAPPING.get(self.embedding_provider, [None])[0] or kwargs.get(\n \"embedding_provider\"\n )\n model_name = self.model or kwargs.get(\"model\")\n authentication = {**(self.z_04_authentication or kwargs.get(\"z_04_authentication\", {}))}\n parameters = self.z_01_model_parameters or kwargs.get(\"z_01_model_parameters\", {})\n\n # Set the API key name if provided\n api_key_name = self.z_02_api_key_name or kwargs.get(\"z_02_api_key_name\")\n provider_key = self.z_03_provider_api_key or kwargs.get(\"z_03_provider_api_key\")\n if api_key_name:\n authentication[\"providerKey\"] = api_key_name\n\n # Set authentication and parameters to None if no values are provided\n if not authentication:\n authentication = None\n if not parameters:\n parameters = None\n\n return {\n # must match astrapy.info.CollectionVectorServiceOptions\n \"collection_vector_service_options\": {\n \"provider\": provider_value,\n \"modelName\": model_name,\n \"authentication\": authentication,\n \"parameters\": parameters,\n },\n \"collection_embedding_api_key\": provider_key,\n }\n\n @check_cached_vector_store\n def build_vector_store(self, vectorize_options=None):\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError as e:\n msg = (\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n raise ImportError(msg) from e\n\n try:\n if not self.setup_mode:\n self.setup_mode = self._inputs[\"setup_mode\"].options[0]\n\n setup_mode_value = SetupMode[self.setup_mode.upper()]\n except KeyError as e:\n msg = f\"Invalid setup mode: {self.setup_mode}\"\n raise ValueError(msg) from e\n\n if self.embedding_choice == \"Embedding Model\":\n embedding_dict = {\"embedding\": self.embedding_model}\n else:\n from astrapy.info import CollectionVectorServiceOptions\n\n # Fetch values from kwargs if any self.* attributes are None\n dict_options = vectorize_options or self.build_vectorize_options()\n\n # Set the embedding dictionary\n embedding_dict = {\n \"collection_vector_service_options\": CollectionVectorServiceOptions.from_dict(\n dict_options.get(\"collection_vector_service_options\")\n ),\n \"collection_embedding_api_key\": dict_options.get(\"collection_embedding_api_key\"),\n }\n\n try:\n vector_store = AstraDBVectorStore(\n collection_name=self.collection_name,\n token=self.token,\n api_endpoint=self.api_endpoint,\n namespace=self.keyspace or None,\n environment=parse_api_endpoint(self.api_endpoint).environment if self.api_endpoint else None,\n metric=self.metric or None,\n batch_size=self.batch_size or None,\n bulk_insert_batch_concurrency=self.bulk_insert_batch_concurrency or None,\n bulk_insert_overwrite_concurrency=self.bulk_insert_overwrite_concurrency or None,\n bulk_delete_concurrency=self.bulk_delete_concurrency or None,\n setup_mode=setup_mode_value,\n pre_delete_collection=self.pre_delete_collection,\n metadata_indexing_include=[s for s in self.metadata_indexing_include if s] or None,\n metadata_indexing_exclude=[s for s in self.metadata_indexing_exclude if s] or None,\n collection_indexing_policy=orjson.dumps(self.collection_indexing_policy)\n if self.collection_indexing_policy\n else None,\n **embedding_dict,\n )\n except Exception as e:\n msg = f\"Error initializing AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self._add_documents_to_vector_store(vector_store)\n\n return vector_store\n\n def _add_documents_to_vector_store(self, vector_store) -> None:\n documents = []\n for _input in self.ingest_data or []:\n if isinstance(_input, Data):\n documents.append(_input.to_lc_document())\n else:\n msg = \"Vector Store Inputs must be Data objects.\"\n raise TypeError(msg)\n\n if documents:\n self.log(f\"Adding {len(documents)} documents to the Vector Store.\")\n try:\n vector_store.add_documents(documents)\n except Exception as e:\n msg = f\"Error adding documents to AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n else:\n self.log(\"No documents to add to the Vector Store.\")\n\n def _map_search_type(self) -> str:\n if self.search_type == \"Similarity with score threshold\":\n return \"similarity_score_threshold\"\n if self.search_type == \"MMR (Max Marginal Relevance)\":\n return \"mmr\"\n return \"similarity\"\n\n def _build_search_args(self):\n query = self.search_input if isinstance(self.search_input, str) and self.search_input.strip() else None\n search_filter = (\n {k: v for k, v in self.search_filter.items() if k and v and k.strip()} if self.search_filter else None\n )\n\n if query:\n args = {\n \"query\": query,\n \"search_type\": self._map_search_type(),\n \"k\": self.number_of_results,\n \"score_threshold\": self.search_score_threshold,\n }\n elif self.advanced_search_filter or search_filter:\n args = {\n \"n\": self.number_of_results,\n }\n else:\n return {}\n\n filter_arg = self.advanced_search_filter or {}\n\n if search_filter:\n self.log(self.log(f\"`search_filter` is deprecated. Use `advanced_search_filter`. Cleaned: {search_filter}\"))\n filter_arg.update(search_filter)\n\n if filter_arg:\n args[\"filter\"] = filter_arg\n\n return args\n\n def search_documents(self, vector_store=None) -> list[Data]:\n vector_store = vector_store or self.build_vector_store()\n\n self.log(f\"Search input: {self.search_input}\")\n self.log(f\"Search type: {self.search_type}\")\n self.log(f\"Number of results: {self.number_of_results}\")\n\n try:\n search_args = self._build_search_args()\n except Exception as e:\n msg = f\"Error in AstraDBVectorStore._build_search_args: {e}\"\n raise ValueError(msg) from e\n\n if not search_args:\n self.log(\"No search input or filters provided. Skipping search.\")\n return []\n\n docs = []\n search_method = \"search\" if \"query\" in search_args else \"metadata_search\"\n\n try:\n self.log(f\"Calling vector_store.{search_method} with args: {search_args}\")\n docs = getattr(vector_store, search_method)(**search_args)\n except Exception as e:\n msg = f\"Error performing {search_method} in AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self.log(f\"Retrieved documents: {len(docs)}\")\n\n data = docs_to_data(docs)\n self.log(f\"Converted documents to data: {len(data)}\")\n self.status = data\n return data\n\n def get_retriever_kwargs(self):\n search_args = self._build_search_args()\n return {\n \"search_type\": self._map_search_type(),\n \"search_kwargs\": search_args,\n }\n"
},
"collection_indexing_policy": {
"_input_type": "StrInput",
@@ -1909,25 +1909,6 @@
"type": "str",
"value": ""
},
- "embedding": {
- "_input_type": "HandleInput",
- "advanced": false,
- "display_name": "Embedding Model",
- "dynamic": false,
- "info": "Allows an embedding model configuration.",
- "input_types": [
- "Embeddings"
- ],
- "list": false,
- "name": "embedding",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
"embedding_choice": {
"_input_type": "DropdownInput",
"advanced": false,
@@ -2917,7 +2898,7 @@
"show": true,
"title_case": false,
"type": "code",
- "value": "import os\n\nimport orjson\nfrom astrapy.admin import parse_api_endpoint\nfrom langchain_astradb import AstraDBVectorStore\n\nfrom langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom langflow.helpers import docs_to_data\nfrom langflow.inputs import DictInput, FloatInput, MessageTextInput, NestedDictInput\nfrom langflow.io import (\n BoolInput,\n DataInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n SecretStrInput,\n StrInput,\n)\nfrom langflow.schema import Data\n\n\nclass AstraVectorStoreComponent(LCVectorStoreComponent):\n display_name: str = \"Astra DB\"\n description: str = \"Implementation of Vector Store using Astra DB with search capabilities\"\n documentation: str = \"https://docs.langflow.org/starter-projects-vector-store-rag\"\n name = \"AstraDB\"\n icon: str = \"AstraDB\"\n\n _cached_vector_store: AstraDBVectorStore | None = None\n\n VECTORIZE_PROVIDERS_MAPPING = {\n \"Azure OpenAI\": [\"azureOpenAI\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Hugging Face - Dedicated\": [\"huggingfaceDedicated\", [\"endpoint-defined-model\"]],\n \"Hugging Face - Serverless\": [\n \"huggingface\",\n [\n \"sentence-transformers/all-MiniLM-L6-v2\",\n \"intfloat/multilingual-e5-large\",\n \"intfloat/multilingual-e5-large-instruct\",\n \"BAAI/bge-small-en-v1.5\",\n \"BAAI/bge-base-en-v1.5\",\n \"BAAI/bge-large-en-v1.5\",\n ],\n ],\n \"Jina AI\": [\n \"jinaAI\",\n [\n \"jina-embeddings-v2-base-en\",\n \"jina-embeddings-v2-base-de\",\n \"jina-embeddings-v2-base-es\",\n \"jina-embeddings-v2-base-code\",\n \"jina-embeddings-v2-base-zh\",\n ],\n ],\n \"Mistral AI\": [\"mistral\", [\"mistral-embed\"]],\n \"NVIDIA\": [\"nvidia\", [\"NV-Embed-QA\"]],\n \"OpenAI\": [\"openai\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Upstage\": [\"upstageAI\", [\"solar-embedding-1-large\"]],\n \"Voyage AI\": [\n \"voyageAI\",\n [\"voyage-large-2-instruct\", \"voyage-law-2\", \"voyage-code-2\", \"voyage-large-2\", \"voyage-2\"],\n ],\n }\n\n inputs = [\n SecretStrInput(\n name=\"token\",\n display_name=\"Astra DB Application Token\",\n info=\"Authentication token for accessing Astra DB.\",\n value=\"ASTRA_DB_APPLICATION_TOKEN\",\n required=True,\n advanced=os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\",\n ),\n SecretStrInput(\n name=\"api_endpoint\",\n display_name=\"Database\" if os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\" else \"API Endpoint\",\n info=\"API endpoint URL for the Astra DB service.\",\n value=\"ASTRA_DB_API_ENDPOINT\",\n required=True,\n ),\n StrInput(\n name=\"collection_name\",\n display_name=\"Collection Name\",\n info=\"The name of the collection within Astra DB where the vectors will be stored.\",\n required=True,\n ),\n MultilineInput(\n name=\"search_input\",\n display_name=\"Search Input\",\n ),\n DataInput(\n name=\"ingest_data\",\n display_name=\"Ingest Data\",\n is_list=True,\n ),\n StrInput(\n name=\"keyspace\",\n display_name=\"Keyspace\",\n info=\"Optional keyspace within Astra DB to use for the collection.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"embedding_choice\",\n display_name=\"Embedding Model or Astra Vectorize\",\n info=\"Determines whether to use Astra Vectorize for the collection.\",\n options=[\"Embedding Model\", \"Astra Vectorize\"],\n real_time_refresh=True,\n value=\"Embedding Model\",\n ),\n HandleInput(\n name=\"embedding\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ),\n DropdownInput(\n name=\"metric\",\n display_name=\"Metric\",\n info=\"Optional distance metric for vector comparisons in the vector store.\",\n options=[\"cosine\", \"dot_product\", \"euclidean\"],\n value=\"cosine\",\n advanced=True,\n ),\n IntInput(\n name=\"batch_size\",\n display_name=\"Batch Size\",\n info=\"Optional number of data to process in a single batch.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_batch_concurrency\",\n display_name=\"Bulk Insert Batch Concurrency\",\n info=\"Optional concurrency level for bulk insert operations.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_overwrite_concurrency\",\n display_name=\"Bulk Insert Overwrite Concurrency\",\n info=\"Optional concurrency level for bulk insert operations that overwrite existing data.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_delete_concurrency\",\n display_name=\"Bulk Delete Concurrency\",\n info=\"Optional concurrency level for bulk delete operations.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"setup_mode\",\n display_name=\"Setup Mode\",\n info=\"Configuration mode for setting up the vector store, with options like 'Sync' or 'Off'.\",\n options=[\"Sync\", \"Off\"],\n advanced=True,\n value=\"Sync\",\n ),\n BoolInput(\n name=\"pre_delete_collection\",\n display_name=\"Pre Delete Collection\",\n info=\"Boolean flag to determine whether to delete the collection before creating a new one.\",\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_include\",\n display_name=\"Metadata Indexing Include\",\n info=\"Optional list of metadata fields to include in the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_exclude\",\n display_name=\"Metadata Indexing Exclude\",\n info=\"Optional list of metadata fields to exclude from the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"collection_indexing_policy\",\n display_name=\"Collection Indexing Policy\",\n info='Optional JSON string for the \"indexing\" field of the collection. '\n \"See https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option\",\n advanced=True,\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Number of Results\",\n info=\"Number of results to return.\",\n advanced=True,\n value=4,\n ),\n DropdownInput(\n name=\"search_type\",\n display_name=\"Search Type\",\n info=\"Search type to use\",\n options=[\"Similarity\", \"Similarity with score threshold\", \"MMR (Max Marginal Relevance)\"],\n value=\"Similarity\",\n advanced=True,\n ),\n FloatInput(\n name=\"search_score_threshold\",\n display_name=\"Search Score Threshold\",\n info=\"Minimum similarity score threshold for search results. \"\n \"(when using 'Similarity with score threshold')\",\n value=0,\n advanced=True,\n ),\n NestedDictInput(\n name=\"advanced_search_filter\",\n display_name=\"Search Metadata Filter\",\n info=\"Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n ),\n DictInput(\n name=\"search_filter\",\n display_name=\"[DEPRECATED] Search Metadata Filter\",\n info=\"Deprecated: use advanced_search_filter. Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n is_list=True,\n ),\n ]\n\n def del_fields(self, build_config, field_list):\n for field in field_list:\n if field in build_config:\n del build_config[field]\n\n return build_config\n\n def insert_in_dict(self, build_config, field_name, new_parameters):\n # Insert the new key-value pair after the found key\n for new_field_name, new_parameter in new_parameters.items():\n # Get all the items as a list of tuples (key, value)\n items = list(build_config.items())\n\n # Find the index of the key to insert after\n idx = len(items)\n for i, (key, _) in enumerate(items):\n if key == field_name:\n idx = i + 1\n break\n\n items.insert(idx, (new_field_name, new_parameter))\n\n # Clear the original dictionary and update with the modified items\n build_config.clear()\n build_config.update(items)\n\n return build_config\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n if field_name == \"embedding_choice\":\n if field_value == \"Astra Vectorize\":\n self.del_fields(build_config, [\"embedding\"])\n\n new_parameter = DropdownInput(\n name=\"embedding_provider\",\n display_name=\"Embedding Provider\",\n options=self.VECTORIZE_PROVIDERS_MAPPING.keys(),\n value=\"\",\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_provider\": new_parameter})\n else:\n self.del_fields(\n build_config,\n [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ],\n )\n\n new_parameter = HandleInput(\n name=\"embedding\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding\": new_parameter})\n\n elif field_name == \"embedding_provider\":\n self.del_fields(\n build_config,\n [\"model\", \"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n model_options = self.VECTORIZE_PROVIDERS_MAPPING[field_value][1]\n\n new_parameter = DropdownInput(\n name=\"model\",\n display_name=\"Model\",\n info=\"The embedding model to use for the selected provider. Each provider has a different set of \"\n \"models available (full list at \"\n \"https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html):\\n\\n\"\n f\"{', '.join(model_options)}\",\n options=model_options,\n value=None,\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_provider\", {\"model\": new_parameter})\n\n elif field_name == \"model\":\n self.del_fields(\n build_config,\n [\"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n new_parameter_1 = DictInput(\n name=\"z_01_model_parameters\",\n display_name=\"Model Parameters\",\n is_list=True,\n ).to_dict()\n\n new_parameter_2 = MessageTextInput(\n name=\"z_02_api_key_name\",\n display_name=\"API Key Name\",\n info=\"The name of the embeddings provider API key stored on Astra. \"\n \"If set, it will override the 'ProviderKey' in the authentication parameters.\",\n ).to_dict()\n\n new_parameter_3 = SecretStrInput(\n load_from_db=False,\n name=\"z_03_provider_api_key\",\n display_name=\"Provider API Key\",\n info=\"An alternative to the Astra Authentication that passes an API key for the provider \"\n \"with each request to Astra DB. \"\n \"This may be used when Vectorize is configured for the collection, \"\n \"but no corresponding provider secret is stored within Astra's key management system.\",\n ).to_dict()\n\n new_parameter_4 = DictInput(\n name=\"z_04_authentication\",\n display_name=\"Authentication Parameters\",\n is_list=True,\n ).to_dict()\n\n self.insert_in_dict(\n build_config,\n \"model\",\n {\n \"z_01_model_parameters\": new_parameter_1,\n \"z_02_api_key_name\": new_parameter_2,\n \"z_03_provider_api_key\": new_parameter_3,\n \"z_04_authentication\": new_parameter_4,\n },\n )\n\n return build_config\n\n def build_vectorize_options(self, **kwargs):\n for attribute in [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ]:\n if not hasattr(self, attribute):\n setattr(self, attribute, None)\n\n # Fetch values from kwargs if any self.* attributes are None\n provider_value = self.VECTORIZE_PROVIDERS_MAPPING.get(self.embedding_provider, [None])[0] or kwargs.get(\n \"embedding_provider\"\n )\n model_name = self.model or kwargs.get(\"model\")\n authentication = {**(self.z_04_authentication or kwargs.get(\"z_04_authentication\", {}))}\n parameters = self.z_01_model_parameters or kwargs.get(\"z_01_model_parameters\", {})\n\n # Set the API key name if provided\n api_key_name = self.z_02_api_key_name or kwargs.get(\"z_02_api_key_name\")\n provider_key = self.z_03_provider_api_key or kwargs.get(\"z_03_provider_api_key\")\n if api_key_name:\n authentication[\"providerKey\"] = api_key_name\n\n # Set authentication and parameters to None if no values are provided\n if not authentication:\n authentication = None\n if not parameters:\n parameters = None\n\n return {\n # must match astrapy.info.CollectionVectorServiceOptions\n \"collection_vector_service_options\": {\n \"provider\": provider_value,\n \"modelName\": model_name,\n \"authentication\": authentication,\n \"parameters\": parameters,\n },\n \"collection_embedding_api_key\": provider_key,\n }\n\n @check_cached_vector_store\n def build_vector_store(self, vectorize_options=None):\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError as e:\n msg = (\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n raise ImportError(msg) from e\n\n try:\n if not self.setup_mode:\n self.setup_mode = self._inputs[\"setup_mode\"].options[0]\n\n setup_mode_value = SetupMode[self.setup_mode.upper()]\n except KeyError as e:\n msg = f\"Invalid setup mode: {self.setup_mode}\"\n raise ValueError(msg) from e\n\n if self.embedding_choice == \"Embedding Model\":\n embedding_dict = {\"embedding\": self.embedding}\n else:\n from astrapy.info import CollectionVectorServiceOptions\n\n # Fetch values from kwargs if any self.* attributes are None\n dict_options = vectorize_options or self.build_vectorize_options()\n\n # Set the embedding dictionary\n embedding_dict = {\n \"collection_vector_service_options\": CollectionVectorServiceOptions.from_dict(\n dict_options.get(\"collection_vector_service_options\")\n ),\n \"collection_embedding_api_key\": dict_options.get(\"collection_embedding_api_key\"),\n }\n\n try:\n vector_store = AstraDBVectorStore(\n collection_name=self.collection_name,\n token=self.token,\n api_endpoint=self.api_endpoint,\n namespace=self.keyspace or None,\n environment=parse_api_endpoint(self.api_endpoint).environment if self.api_endpoint else None,\n metric=self.metric or None,\n batch_size=self.batch_size or None,\n bulk_insert_batch_concurrency=self.bulk_insert_batch_concurrency or None,\n bulk_insert_overwrite_concurrency=self.bulk_insert_overwrite_concurrency or None,\n bulk_delete_concurrency=self.bulk_delete_concurrency or None,\n setup_mode=setup_mode_value,\n pre_delete_collection=self.pre_delete_collection,\n metadata_indexing_include=[s for s in self.metadata_indexing_include if s] or None,\n metadata_indexing_exclude=[s for s in self.metadata_indexing_exclude if s] or None,\n collection_indexing_policy=orjson.dumps(self.collection_indexing_policy)\n if self.collection_indexing_policy\n else None,\n **embedding_dict,\n )\n except Exception as e:\n msg = f\"Error initializing AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self._add_documents_to_vector_store(vector_store)\n\n return vector_store\n\n def _add_documents_to_vector_store(self, vector_store) -> None:\n documents = []\n for _input in self.ingest_data or []:\n if isinstance(_input, Data):\n documents.append(_input.to_lc_document())\n else:\n msg = \"Vector Store Inputs must be Data objects.\"\n raise TypeError(msg)\n\n if documents:\n self.log(f\"Adding {len(documents)} documents to the Vector Store.\")\n try:\n vector_store.add_documents(documents)\n except Exception as e:\n msg = f\"Error adding documents to AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n else:\n self.log(\"No documents to add to the Vector Store.\")\n\n def _map_search_type(self) -> str:\n if self.search_type == \"Similarity with score threshold\":\n return \"similarity_score_threshold\"\n if self.search_type == \"MMR (Max Marginal Relevance)\":\n return \"mmr\"\n return \"similarity\"\n\n def _build_search_args(self):\n query = self.search_input if isinstance(self.search_input, str) and self.search_input.strip() else None\n search_filter = (\n {k: v for k, v in self.search_filter.items() if k and v and k.strip()} if self.search_filter else None\n )\n\n if query:\n args = {\n \"query\": query,\n \"search_type\": self._map_search_type(),\n \"k\": self.number_of_results,\n \"score_threshold\": self.search_score_threshold,\n }\n elif self.advanced_search_filter or search_filter:\n args = {\n \"n\": self.number_of_results,\n }\n else:\n return {}\n\n filter_arg = self.advanced_search_filter or {}\n\n if search_filter:\n self.log(self.log(f\"`search_filter` is deprecated. Use `advanced_search_filter`. Cleaned: {search_filter}\"))\n filter_arg.update(search_filter)\n\n if filter_arg:\n args[\"filter\"] = filter_arg\n\n return args\n\n def search_documents(self, vector_store=None) -> list[Data]:\n vector_store = vector_store or self.build_vector_store()\n\n self.log(f\"Search input: {self.search_input}\")\n self.log(f\"Search type: {self.search_type}\")\n self.log(f\"Number of results: {self.number_of_results}\")\n\n try:\n search_args = self._build_search_args()\n except Exception as e:\n msg = f\"Error in AstraDBVectorStore._build_search_args: {e}\"\n raise ValueError(msg) from e\n\n if not search_args:\n self.log(\"No search input or filters provided. Skipping search.\")\n return []\n\n docs = []\n search_method = \"search\" if \"query\" in search_args else \"metadata_search\"\n\n try:\n self.log(f\"Calling vector_store.{search_method} with args: {search_args}\")\n docs = getattr(vector_store, search_method)(**search_args)\n except Exception as e:\n msg = f\"Error performing {search_method} in AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self.log(f\"Retrieved documents: {len(docs)}\")\n\n data = docs_to_data(docs)\n self.log(f\"Converted documents to data: {len(data)}\")\n self.status = data\n return data\n\n def get_retriever_kwargs(self):\n search_args = self._build_search_args()\n return {\n \"search_type\": self._map_search_type(),\n \"search_kwargs\": search_args,\n }\n"
+ "value": "import os\nfrom collections import defaultdict\n\nimport orjson\nfrom astrapy import DataAPIClient\nfrom astrapy.admin import parse_api_endpoint\nfrom langchain_astradb import AstraDBVectorStore\n\nfrom langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store\nfrom langflow.helpers import docs_to_data\nfrom langflow.inputs import DictInput, FloatInput, MessageTextInput, NestedDictInput\nfrom langflow.io import (\n BoolInput,\n DataInput,\n DropdownInput,\n HandleInput,\n IntInput,\n MultilineInput,\n SecretStrInput,\n StrInput,\n)\nfrom langflow.schema import Data\n\n\nclass AstraVectorStoreComponent(LCVectorStoreComponent):\n display_name: str = \"Astra DB\"\n description: str = \"Implementation of Vector Store using Astra DB with search capabilities\"\n documentation: str = \"https://docs.langflow.org/starter-projects-vector-store-rag\"\n name = \"AstraDB\"\n icon: str = \"AstraDB\"\n\n _cached_vector_store: AstraDBVectorStore | None = None\n\n VECTORIZE_PROVIDERS_MAPPING = defaultdict(\n list,\n {\n \"Azure OpenAI\": [\n \"azureOpenAI\",\n [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"],\n ],\n \"Hugging Face - Dedicated\": [\"huggingfaceDedicated\", [\"endpoint-defined-model\"]],\n \"Hugging Face - Serverless\": [\n \"huggingface\",\n [\n \"sentence-transformers/all-MiniLM-L6-v2\",\n \"intfloat/multilingual-e5-large\",\n \"intfloat/multilingual-e5-large-instruct\",\n \"BAAI/bge-small-en-v1.5\",\n \"BAAI/bge-base-en-v1.5\",\n \"BAAI/bge-large-en-v1.5\",\n ],\n ],\n \"Jina AI\": [\n \"jinaAI\",\n [\n \"jina-embeddings-v2-base-en\",\n \"jina-embeddings-v2-base-de\",\n \"jina-embeddings-v2-base-es\",\n \"jina-embeddings-v2-base-code\",\n \"jina-embeddings-v2-base-zh\",\n ],\n ],\n \"Mistral AI\": [\"mistral\", [\"mistral-embed\"]],\n \"NVIDIA\": [\"nvidia\", [\"NV-Embed-QA\"]],\n \"OpenAI\": [\"openai\", [\"text-embedding-3-small\", \"text-embedding-3-large\", \"text-embedding-ada-002\"]],\n \"Upstage\": [\"upstageAI\", [\"solar-embedding-1-large\"]],\n \"Voyage AI\": [\n \"voyageAI\",\n [\"voyage-large-2-instruct\", \"voyage-law-2\", \"voyage-code-2\", \"voyage-large-2\", \"voyage-2\"],\n ],\n },\n )\n\n inputs = [\n SecretStrInput(\n name=\"token\",\n display_name=\"Astra DB Application Token\",\n info=\"Authentication token for accessing Astra DB.\",\n value=\"ASTRA_DB_APPLICATION_TOKEN\",\n required=True,\n advanced=os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\",\n ),\n SecretStrInput(\n name=\"api_endpoint\",\n display_name=\"Database\" if os.getenv(\"ASTRA_ENHANCED\", \"false\").lower() == \"true\" else \"API Endpoint\",\n info=\"API endpoint URL for the Astra DB service.\",\n value=\"ASTRA_DB_API_ENDPOINT\",\n required=True,\n ),\n StrInput(\n name=\"collection_name\",\n display_name=\"Collection Name\",\n info=\"The name of the collection within Astra DB where the vectors will be stored.\",\n required=True,\n ),\n MultilineInput(\n name=\"search_input\",\n display_name=\"Search Input\",\n ),\n DataInput(\n name=\"ingest_data\",\n display_name=\"Ingest Data\",\n is_list=True,\n ),\n StrInput(\n name=\"keyspace\",\n display_name=\"Keyspace\",\n info=\"Optional keyspace within Astra DB to use for the collection.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"embedding_choice\",\n display_name=\"Embedding Model or Astra Vectorize\",\n info=\"Determines whether to use Astra Vectorize for the collection.\",\n options=[\"Embedding Model\", \"Astra Vectorize\"],\n real_time_refresh=True,\n value=\"Embedding Model\",\n ),\n HandleInput(\n name=\"embedding_model\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ),\n DropdownInput(\n name=\"metric\",\n display_name=\"Metric\",\n info=\"Optional distance metric for vector comparisons in the vector store.\",\n options=[\"cosine\", \"dot_product\", \"euclidean\"],\n value=\"cosine\",\n advanced=True,\n ),\n IntInput(\n name=\"batch_size\",\n display_name=\"Batch Size\",\n info=\"Optional number of data to process in a single batch.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_batch_concurrency\",\n display_name=\"Bulk Insert Batch Concurrency\",\n info=\"Optional concurrency level for bulk insert operations.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_insert_overwrite_concurrency\",\n display_name=\"Bulk Insert Overwrite Concurrency\",\n info=\"Optional concurrency level for bulk insert operations that overwrite existing data.\",\n advanced=True,\n ),\n IntInput(\n name=\"bulk_delete_concurrency\",\n display_name=\"Bulk Delete Concurrency\",\n info=\"Optional concurrency level for bulk delete operations.\",\n advanced=True,\n ),\n DropdownInput(\n name=\"setup_mode\",\n display_name=\"Setup Mode\",\n info=\"Configuration mode for setting up the vector store, with options like 'Sync' or 'Off'.\",\n options=[\"Sync\", \"Off\"],\n advanced=True,\n value=\"Sync\",\n ),\n BoolInput(\n name=\"pre_delete_collection\",\n display_name=\"Pre Delete Collection\",\n info=\"Boolean flag to determine whether to delete the collection before creating a new one.\",\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_include\",\n display_name=\"Metadata Indexing Include\",\n info=\"Optional list of metadata fields to include in the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"metadata_indexing_exclude\",\n display_name=\"Metadata Indexing Exclude\",\n info=\"Optional list of metadata fields to exclude from the indexing.\",\n is_list=True,\n advanced=True,\n ),\n StrInput(\n name=\"collection_indexing_policy\",\n display_name=\"Collection Indexing Policy\",\n info='Optional JSON string for the \"indexing\" field of the collection. '\n \"See https://docs.datastax.com/en/astra-db-serverless/api-reference/collections.html#the-indexing-option\",\n advanced=True,\n ),\n IntInput(\n name=\"number_of_results\",\n display_name=\"Number of Results\",\n info=\"Number of results to return.\",\n advanced=True,\n value=4,\n ),\n DropdownInput(\n name=\"search_type\",\n display_name=\"Search Type\",\n info=\"Search type to use\",\n options=[\"Similarity\", \"Similarity with score threshold\", \"MMR (Max Marginal Relevance)\"],\n value=\"Similarity\",\n advanced=True,\n ),\n FloatInput(\n name=\"search_score_threshold\",\n display_name=\"Search Score Threshold\",\n info=\"Minimum similarity score threshold for search results. \"\n \"(when using 'Similarity with score threshold')\",\n value=0,\n advanced=True,\n ),\n NestedDictInput(\n name=\"advanced_search_filter\",\n display_name=\"Search Metadata Filter\",\n info=\"Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n ),\n DictInput(\n name=\"search_filter\",\n display_name=\"[DEPRECATED] Search Metadata Filter\",\n info=\"Deprecated: use advanced_search_filter. Optional dictionary of filters to apply to the search query.\",\n advanced=True,\n is_list=True,\n ),\n ]\n\n def del_fields(self, build_config, field_list):\n for field in field_list:\n if field in build_config:\n del build_config[field]\n\n return build_config\n\n def insert_in_dict(self, build_config, field_name, new_parameters):\n # Insert the new key-value pair after the found key\n for new_field_name, new_parameter in new_parameters.items():\n # Get all the items as a list of tuples (key, value)\n items = list(build_config.items())\n\n # Find the index of the key to insert after\n idx = len(items)\n for i, (key, _) in enumerate(items):\n if key == field_name:\n idx = i + 1\n break\n\n items.insert(idx, (new_field_name, new_parameter))\n\n # Clear the original dictionary and update with the modified items\n build_config.clear()\n build_config.update(items)\n\n return build_config\n\n def update_providers_mapping(self):\n # If we don't have token or api_endpoint, we can't fetch the list of providers\n if not self.token or not self.api_endpoint:\n self.log(\"Astra DB token and API endpoint are required to fetch the list of Vectorize providers.\")\n\n return self.VECTORIZE_PROVIDERS_MAPPING\n\n try:\n self.log(\"Dynamically updating list of Vectorize providers.\")\n\n # Get the admin object\n client = DataAPIClient(token=self.token)\n admin = client.get_admin()\n\n # Get the embedding providers\n db_admin = admin.get_database_admin(self.api_endpoint)\n embedding_providers = db_admin.find_embedding_providers().as_dict()\n\n vectorize_providers_mapping = {}\n\n # Map the provider display name to the provider key and models\n for provider_key, provider_data in embedding_providers[\"embeddingProviders\"].items():\n display_name = provider_data[\"displayName\"]\n models = [model[\"name\"] for model in provider_data[\"models\"]]\n\n vectorize_providers_mapping[display_name] = [provider_key, models]\n\n # Sort the resulting dictionary\n return defaultdict(list, dict(sorted(vectorize_providers_mapping.items())))\n except Exception as e: # noqa: BLE001\n self.log(f\"Error fetching Vectorize providers: {e}\")\n\n return self.VECTORIZE_PROVIDERS_MAPPING\n\n def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):\n if field_name == \"embedding_choice\":\n if field_value == \"Astra Vectorize\":\n self.del_fields(build_config, [\"embedding_model\"])\n\n # Update the providers mapping\n vectorize_providers = self.update_providers_mapping()\n\n new_parameter = DropdownInput(\n name=\"embedding_provider\",\n display_name=\"Embedding Provider\",\n options=vectorize_providers.keys(),\n value=\"\",\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_provider\": new_parameter})\n else:\n self.del_fields(\n build_config,\n [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ],\n )\n\n new_parameter = HandleInput(\n name=\"embedding_model\",\n display_name=\"Embedding Model\",\n input_types=[\"Embeddings\"],\n info=\"Allows an embedding model configuration.\",\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_choice\", {\"embedding_model\": new_parameter})\n\n elif field_name == \"embedding_provider\":\n self.del_fields(\n build_config,\n [\"model\", \"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n # Update the providers mapping\n vectorize_providers = self.update_providers_mapping()\n model_options = vectorize_providers[field_value][1]\n\n new_parameter = DropdownInput(\n name=\"model\",\n display_name=\"Model\",\n info=\"The embedding model to use for the selected provider. Each provider has a different set of \"\n \"models available (full list at \"\n \"https://docs.datastax.com/en/astra-db-serverless/databases/embedding-generation.html):\\n\\n\"\n f\"{', '.join(model_options)}\",\n options=model_options,\n value=None,\n required=True,\n real_time_refresh=True,\n ).to_dict()\n\n self.insert_in_dict(build_config, \"embedding_provider\", {\"model\": new_parameter})\n\n elif field_name == \"model\":\n self.del_fields(\n build_config,\n [\"z_01_model_parameters\", \"z_02_api_key_name\", \"z_03_provider_api_key\", \"z_04_authentication\"],\n )\n\n new_parameter_1 = DictInput(\n name=\"z_01_model_parameters\",\n display_name=\"Model Parameters\",\n is_list=True,\n ).to_dict()\n\n new_parameter_2 = MessageTextInput(\n name=\"z_02_api_key_name\",\n display_name=\"API Key Name\",\n info=\"The name of the embeddings provider API key stored on Astra. \"\n \"If set, it will override the 'ProviderKey' in the authentication parameters.\",\n ).to_dict()\n\n new_parameter_3 = SecretStrInput(\n load_from_db=False,\n name=\"z_03_provider_api_key\",\n display_name=\"Provider API Key\",\n info=\"An alternative to the Astra Authentication that passes an API key for the provider \"\n \"with each request to Astra DB. \"\n \"This may be used when Vectorize is configured for the collection, \"\n \"but no corresponding provider secret is stored within Astra's key management system.\",\n ).to_dict()\n\n new_parameter_4 = DictInput(\n name=\"z_04_authentication\",\n display_name=\"Authentication Parameters\",\n is_list=True,\n ).to_dict()\n\n self.insert_in_dict(\n build_config,\n \"model\",\n {\n \"z_01_model_parameters\": new_parameter_1,\n \"z_02_api_key_name\": new_parameter_2,\n \"z_03_provider_api_key\": new_parameter_3,\n \"z_04_authentication\": new_parameter_4,\n },\n )\n\n return build_config\n\n def build_vectorize_options(self, **kwargs):\n for attribute in [\n \"embedding_provider\",\n \"model\",\n \"z_01_model_parameters\",\n \"z_02_api_key_name\",\n \"z_03_provider_api_key\",\n \"z_04_authentication\",\n ]:\n if not hasattr(self, attribute):\n setattr(self, attribute, None)\n\n # Fetch values from kwargs if any self.* attributes are None\n provider_value = self.VECTORIZE_PROVIDERS_MAPPING.get(self.embedding_provider, [None])[0] or kwargs.get(\n \"embedding_provider\"\n )\n model_name = self.model or kwargs.get(\"model\")\n authentication = {**(self.z_04_authentication or kwargs.get(\"z_04_authentication\", {}))}\n parameters = self.z_01_model_parameters or kwargs.get(\"z_01_model_parameters\", {})\n\n # Set the API key name if provided\n api_key_name = self.z_02_api_key_name or kwargs.get(\"z_02_api_key_name\")\n provider_key = self.z_03_provider_api_key or kwargs.get(\"z_03_provider_api_key\")\n if api_key_name:\n authentication[\"providerKey\"] = api_key_name\n\n # Set authentication and parameters to None if no values are provided\n if not authentication:\n authentication = None\n if not parameters:\n parameters = None\n\n return {\n # must match astrapy.info.CollectionVectorServiceOptions\n \"collection_vector_service_options\": {\n \"provider\": provider_value,\n \"modelName\": model_name,\n \"authentication\": authentication,\n \"parameters\": parameters,\n },\n \"collection_embedding_api_key\": provider_key,\n }\n\n @check_cached_vector_store\n def build_vector_store(self, vectorize_options=None):\n try:\n from langchain_astradb import AstraDBVectorStore\n from langchain_astradb.utils.astradb import SetupMode\n except ImportError as e:\n msg = (\n \"Could not import langchain Astra DB integration package. \"\n \"Please install it with `pip install langchain-astradb`.\"\n )\n raise ImportError(msg) from e\n\n try:\n if not self.setup_mode:\n self.setup_mode = self._inputs[\"setup_mode\"].options[0]\n\n setup_mode_value = SetupMode[self.setup_mode.upper()]\n except KeyError as e:\n msg = f\"Invalid setup mode: {self.setup_mode}\"\n raise ValueError(msg) from e\n\n if self.embedding_choice == \"Embedding Model\":\n embedding_dict = {\"embedding\": self.embedding_model}\n else:\n from astrapy.info import CollectionVectorServiceOptions\n\n # Fetch values from kwargs if any self.* attributes are None\n dict_options = vectorize_options or self.build_vectorize_options()\n\n # Set the embedding dictionary\n embedding_dict = {\n \"collection_vector_service_options\": CollectionVectorServiceOptions.from_dict(\n dict_options.get(\"collection_vector_service_options\")\n ),\n \"collection_embedding_api_key\": dict_options.get(\"collection_embedding_api_key\"),\n }\n\n try:\n vector_store = AstraDBVectorStore(\n collection_name=self.collection_name,\n token=self.token,\n api_endpoint=self.api_endpoint,\n namespace=self.keyspace or None,\n environment=parse_api_endpoint(self.api_endpoint).environment if self.api_endpoint else None,\n metric=self.metric or None,\n batch_size=self.batch_size or None,\n bulk_insert_batch_concurrency=self.bulk_insert_batch_concurrency or None,\n bulk_insert_overwrite_concurrency=self.bulk_insert_overwrite_concurrency or None,\n bulk_delete_concurrency=self.bulk_delete_concurrency or None,\n setup_mode=setup_mode_value,\n pre_delete_collection=self.pre_delete_collection,\n metadata_indexing_include=[s for s in self.metadata_indexing_include if s] or None,\n metadata_indexing_exclude=[s for s in self.metadata_indexing_exclude if s] or None,\n collection_indexing_policy=orjson.dumps(self.collection_indexing_policy)\n if self.collection_indexing_policy\n else None,\n **embedding_dict,\n )\n except Exception as e:\n msg = f\"Error initializing AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self._add_documents_to_vector_store(vector_store)\n\n return vector_store\n\n def _add_documents_to_vector_store(self, vector_store) -> None:\n documents = []\n for _input in self.ingest_data or []:\n if isinstance(_input, Data):\n documents.append(_input.to_lc_document())\n else:\n msg = \"Vector Store Inputs must be Data objects.\"\n raise TypeError(msg)\n\n if documents:\n self.log(f\"Adding {len(documents)} documents to the Vector Store.\")\n try:\n vector_store.add_documents(documents)\n except Exception as e:\n msg = f\"Error adding documents to AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n else:\n self.log(\"No documents to add to the Vector Store.\")\n\n def _map_search_type(self) -> str:\n if self.search_type == \"Similarity with score threshold\":\n return \"similarity_score_threshold\"\n if self.search_type == \"MMR (Max Marginal Relevance)\":\n return \"mmr\"\n return \"similarity\"\n\n def _build_search_args(self):\n query = self.search_input if isinstance(self.search_input, str) and self.search_input.strip() else None\n search_filter = (\n {k: v for k, v in self.search_filter.items() if k and v and k.strip()} if self.search_filter else None\n )\n\n if query:\n args = {\n \"query\": query,\n \"search_type\": self._map_search_type(),\n \"k\": self.number_of_results,\n \"score_threshold\": self.search_score_threshold,\n }\n elif self.advanced_search_filter or search_filter:\n args = {\n \"n\": self.number_of_results,\n }\n else:\n return {}\n\n filter_arg = self.advanced_search_filter or {}\n\n if search_filter:\n self.log(self.log(f\"`search_filter` is deprecated. Use `advanced_search_filter`. Cleaned: {search_filter}\"))\n filter_arg.update(search_filter)\n\n if filter_arg:\n args[\"filter\"] = filter_arg\n\n return args\n\n def search_documents(self, vector_store=None) -> list[Data]:\n vector_store = vector_store or self.build_vector_store()\n\n self.log(f\"Search input: {self.search_input}\")\n self.log(f\"Search type: {self.search_type}\")\n self.log(f\"Number of results: {self.number_of_results}\")\n\n try:\n search_args = self._build_search_args()\n except Exception as e:\n msg = f\"Error in AstraDBVectorStore._build_search_args: {e}\"\n raise ValueError(msg) from e\n\n if not search_args:\n self.log(\"No search input or filters provided. Skipping search.\")\n return []\n\n docs = []\n search_method = \"search\" if \"query\" in search_args else \"metadata_search\"\n\n try:\n self.log(f\"Calling vector_store.{search_method} with args: {search_args}\")\n docs = getattr(vector_store, search_method)(**search_args)\n except Exception as e:\n msg = f\"Error performing {search_method} in AstraDBVectorStore: {e}\"\n raise ValueError(msg) from e\n\n self.log(f\"Retrieved documents: {len(docs)}\")\n\n data = docs_to_data(docs)\n self.log(f\"Converted documents to data: {len(data)}\")\n self.status = data\n return data\n\n def get_retriever_kwargs(self):\n search_args = self._build_search_args()\n return {\n \"search_type\": self._map_search_type(),\n \"search_kwargs\": search_args,\n }\n"
},
"collection_indexing_policy": {
"_input_type": "StrInput",
@@ -2953,25 +2934,6 @@
"type": "str",
"value": "test"
},
- "embedding": {
- "_input_type": "HandleInput",
- "advanced": false,
- "display_name": "Embedding Model",
- "dynamic": false,
- "info": "Allows an embedding model configuration.",
- "input_types": [
- "Embeddings"
- ],
- "list": false,
- "name": "embedding",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
"embedding_choice": {
"_input_type": "DropdownInput",
"advanced": false,
@@ -3280,7 +3242,7 @@
"data": {
"id": "note-igpjN",
"node": {
- "description": "## 🐕 2. Retriever Flow\n\nThis flow answers your questions with contextual data retrieved from your vector database.\n\nOpen the **Playground** and ask, ```What is this document about?```\n",
+ "description": "## 🐕 2. Retriever Flow\n\nThis flow answers your questions with contextual data retrieved from your vector database.\n\nOpen the **Playground** and ask, \n\n```\nWhat is this document about?\n```\n",
"display_name": "",
"documentation": "",
"template": {
@@ -3300,11 +3262,11 @@
"y": 1552.171191793604
},
"selected": false,
- "type": "noteNode",
"style": {
"height": 50,
"width": 325
- }
+ },
+ "type": "noteNode"
},
{
"data": {
@@ -4053,7 +4015,7 @@
"zoom": 0.5239796558908366
}
},
- "description": "Get started with Retrieval-Augmented Generation (RAG) by ingesting data from documents and retrieving relevant chunks through vector similarity to provide contextual answers.",
+ "description": "Load your data for chat context with Retrieval Augmented Generation.",
"endpoint_name": null,
"gradient": "5",
"icon": "Database",
diff --git a/src/backend/base/langflow/initial_setup/starter_projects/YouTube Transcript Q&A.json b/src/backend/base/langflow/initial_setup/starter_projects/YouTube Transcript Q&A.json
deleted file mode 100644
index 3210a48d745..00000000000
--- a/src/backend/base/langflow/initial_setup/starter_projects/YouTube Transcript Q&A.json
+++ /dev/null
@@ -1,1539 +0,0 @@
-{
- "data": {
- "edges": [
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "ChatInput",
- "id": "ChatInput-B1nYa",
- "name": "message",
- "output_types": [
- "Message"
- ]
- },
- "targetHandle": {
- "fieldName": "input_value",
- "id": "Agent-EGSx3",
- "inputTypes": [
- "Message"
- ],
- "type": "str"
- }
- },
- "id": "reactflow__edge-ChatInput-B1nYa{œdataTypeœ:œChatInputœ,œidœ:œChatInput-B1nYaœ,œnameœ:œmessageœ,œoutput_typesœ:[œMessageœ]}-Agent-EGSx3{œfieldNameœ:œinput_valueœ,œidœ:œAgent-EGSx3œ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
- "selected": false,
- "source": "ChatInput-B1nYa",
- "sourceHandle": "{œdataTypeœ: œChatInputœ, œidœ: œChatInput-B1nYaœ, œnameœ: œmessageœ, œoutput_typesœ: [œMessageœ]}",
- "target": "Agent-EGSx3",
- "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œAgent-EGSx3œ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
- },
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "Agent",
- "id": "Agent-EGSx3",
- "name": "response",
- "output_types": [
- "Message"
- ]
- },
- "targetHandle": {
- "fieldName": "input_value",
- "id": "ChatOutput-zUzVK",
- "inputTypes": [
- "Message"
- ],
- "type": "str"
- }
- },
- "id": "reactflow__edge-Agent-EGSx3{œdataTypeœ:œAgentœ,œidœ:œAgent-EGSx3œ,œnameœ:œresponseœ,œoutput_typesœ:[œMessageœ]}-ChatOutput-zUzVK{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-zUzVKœ,œinputTypesœ:[œMessageœ],œtypeœ:œstrœ}",
- "source": "Agent-EGSx3",
- "sourceHandle": "{œdataTypeœ: œAgentœ, œidœ: œAgent-EGSx3œ, œnameœ: œresponseœ, œoutput_typesœ: [œMessageœ]}",
- "target": "ChatOutput-zUzVK",
- "targetHandle": "{œfieldNameœ: œinput_valueœ, œidœ: œChatOutput-zUzVKœ, œinputTypesœ: [œMessageœ], œtypeœ: œstrœ}"
- },
- {
- "animated": false,
- "className": "",
- "data": {
- "sourceHandle": {
- "dataType": "YouTubeTranscriptsComponent",
- "id": "YouTubeTranscriptsComponent-n8Z9Y",
- "name": "transcripts_tool",
- "output_types": [
- "Tool"
- ]
- },
- "targetHandle": {
- "fieldName": "tools",
- "id": "Agent-EGSx3",
- "inputTypes": [
- "Tool",
- "BaseTool",
- "StructuredTool"
- ],
- "type": "other"
- }
- },
- "id": "reactflow__edge-YouTubeTranscriptsComponent-n8Z9Y{œdataTypeœ:œYouTubeTranscriptsComponentœ,œidœ:œYouTubeTranscriptsComponent-n8Z9Yœ,œnameœ:œtranscripts_toolœ,œoutput_typesœ:[œToolœ]}-Agent-EGSx3{œfieldNameœ:œtoolsœ,œidœ:œAgent-EGSx3œ,œinputTypesœ:[œToolœ,œBaseToolœ,œStructuredToolœ],œtypeœ:œotherœ}",
- "source": "YouTubeTranscriptsComponent-n8Z9Y",
- "sourceHandle": "{œdataTypeœ: œYouTubeTranscriptsComponentœ, œidœ: œYouTubeTranscriptsComponent-n8Z9Yœ, œnameœ: œtranscripts_toolœ, œoutput_typesœ: [œToolœ]}",
- "target": "Agent-EGSx3",
- "targetHandle": "{œfieldNameœ: œtoolsœ, œidœ: œAgent-EGSx3œ, œinputTypesœ: [œToolœ, œBaseToolœ, œStructuredToolœ], œtypeœ: œotherœ}"
- }
- ],
- "nodes": [
- {
- "data": {
- "description": "Define the agent's instructions, then enter a task to complete using tools.",
- "display_name": "Agent",
- "id": "Agent-EGSx3",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Define the agent's instructions, then enter a task to complete using tools.",
- "display_name": "Agent",
- "documentation": "",
- "edited": false,
- "field_order": [
- "agent_llm",
- "max_tokens",
- "model_kwargs",
- "json_mode",
- "output_schema",
- "model_name",
- "openai_api_base",
- "api_key",
- "temperature",
- "seed",
- "output_parser",
- "system_prompt",
- "tools",
- "input_value",
- "handle_parsing_errors",
- "verbose",
- "max_iterations",
- "agent_description",
- "memory",
- "sender",
- "sender_name",
- "n_messages",
- "session_id",
- "order",
- "template",
- "add_current_date_tool"
- ],
- "frozen": false,
- "icon": "bot",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Response",
- "method": "message_response",
- "name": "response",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "add_current_date_tool": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Add tool Current Date",
- "dynamic": false,
- "info": "If true, will add a tool to the agent that returns the current date.",
- "list": false,
- "name": "add_current_date_tool",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "agent_description": {
- "_input_type": "MultilineInput",
- "advanced": true,
- "display_name": "Agent Description",
- "dynamic": false,
- "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "agent_description",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "A helpful assistant with access to the following tools:"
- },
- "agent_llm": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Model Provider",
- "dynamic": false,
- "info": "The provider of the language model that the agent will use to generate responses.",
- "input_types": [],
- "name": "agent_llm",
- "options": [
- "Amazon Bedrock",
- "Anthropic",
- "Azure OpenAI",
- "Groq",
- "NVIDIA",
- "OpenAI",
- "Custom"
- ],
- "placeholder": "",
- "real_time_refresh": true,
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "OpenAI"
- },
- "api_key": {
- "_input_type": "SecretStrInput",
- "advanced": false,
- "display_name": "OpenAI API Key",
- "dynamic": false,
- "info": "The OpenAI API Key to use for the OpenAI model.",
- "input_types": [
- "Message"
- ],
- "load_from_db": false,
- "name": "api_key",
- "password": true,
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "type": "str",
- "value": "OPENAI_API_KEY"
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langchain_core.tools import StructuredTool\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.base.models.model_input_constants import ALL_PROVIDER_FIELDS, MODEL_PROVIDERS_DICT\nfrom langflow.base.models.model_utils import get_model_name\nfrom langflow.components.helpers import CurrentDateComponent\nfrom langflow.components.helpers.memory import MemoryComponent\nfrom langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent\nfrom langflow.io import BoolInput, DropdownInput, MultilineInput, Output\nfrom langflow.schema.dotdict import dotdict\nfrom langflow.schema.message import Message\n\n\ndef set_advanced_true(component_input):\n component_input.advanced = True\n return component_input\n\n\nclass AgentComponent(ToolCallingAgentComponent):\n display_name: str = \"Agent\"\n description: str = \"Define the agent's instructions, then enter a task to complete using tools.\"\n icon = \"bot\"\n beta = False\n name = \"Agent\"\n\n memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]\n\n inputs = [\n DropdownInput(\n name=\"agent_llm\",\n display_name=\"Model Provider\",\n info=\"The provider of the language model that the agent will use to generate responses.\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"OpenAI\",\n real_time_refresh=True,\n input_types=[],\n ),\n *MODEL_PROVIDERS_DICT[\"OpenAI\"][\"inputs\"],\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"Agent Instructions\",\n info=\"System Prompt: Initial instructions and context provided to guide the agent's behavior.\",\n value=\"You are a helpful assistant that can use tools to answer questions and perform tasks.\",\n advanced=False,\n ),\n *LCToolsAgentComponent._base_inputs,\n *memory_inputs,\n BoolInput(\n name=\"add_current_date_tool\",\n display_name=\"Add tool Current Date\",\n advanced=True,\n info=\"If true, will add a tool to the agent that returns the current date.\",\n value=True,\n ),\n ]\n outputs = [Output(name=\"response\", display_name=\"Response\", method=\"message_response\")]\n\n async def message_response(self) -> Message:\n llm_model, display_name = self.get_llm()\n self.model_name = get_model_name(llm_model, display_name=display_name)\n if llm_model is None:\n msg = \"No language model selected\"\n raise ValueError(msg)\n self.chat_history = self.get_memory_data()\n\n if self.add_current_date_tool:\n if not isinstance(self.tools, list): # type: ignore[has-type]\n self.tools = []\n # Convert CurrentDateComponent to a StructuredTool\n current_date_tool = CurrentDateComponent().to_toolkit()[0]\n if isinstance(current_date_tool, StructuredTool):\n self.tools.append(current_date_tool)\n else:\n msg = \"CurrentDateComponent must be converted to a StructuredTool\"\n raise ValueError(msg)\n\n if not self.tools:\n msg = \"Tools are required to run the agent.\"\n raise ValueError(msg)\n self.set(\n llm=llm_model,\n tools=self.tools,\n chat_history=self.chat_history,\n input_value=self.input_value,\n system_prompt=self.system_prompt,\n )\n agent = self.create_agent_runnable()\n return await self.run_agent(agent)\n\n def get_memory_data(self):\n memory_kwargs = {\n component_input.name: getattr(self, f\"{component_input.name}\") for component_input in self.memory_inputs\n }\n\n return MemoryComponent().set(**memory_kwargs).retrieve_messages()\n\n def get_llm(self):\n if isinstance(self.agent_llm, str):\n try:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n display_name = component_class.display_name\n inputs = provider_info.get(\"inputs\")\n prefix = provider_info.get(\"prefix\", \"\")\n return self._build_llm_model(component_class, inputs, prefix), display_name\n except Exception as e:\n msg = f\"Error building {self.agent_llm} language model\"\n raise ValueError(msg) from e\n return self.agent_llm, None\n\n def _build_llm_model(self, component, inputs, prefix=\"\"):\n model_kwargs = {input_.name: getattr(self, f\"{prefix}{input_.name}\") for input_ in inputs}\n return component.set(**model_kwargs).build_model()\n\n def delete_fields(self, build_config: dotdict, fields: dict | list[str]) -> None:\n \"\"\"Delete specified fields from build_config.\"\"\"\n for field in fields:\n build_config.pop(field, None)\n\n def update_input_types(self, build_config: dotdict) -> dotdict:\n \"\"\"Update input types for all fields in build_config.\"\"\"\n for key, value in build_config.items():\n if isinstance(value, dict):\n if value.get(\"input_types\") is None:\n build_config[key][\"input_types\"] = []\n elif hasattr(value, \"input_types\") and value.input_types is None:\n value.input_types = []\n return build_config\n\n def update_build_config(self, build_config: dotdict, field_value: str, field_name: str | None = None) -> dotdict:\n # Iterate over all providers in the MODEL_PROVIDERS_DICT\n # Existing logic for updating build_config\n if field_name == \"agent_llm\":\n provider_info = MODEL_PROVIDERS_DICT.get(field_value)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call the component class's update_build_config method\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n provider_configs: dict[str, tuple[dict, list[dict]]] = {\n provider: (\n MODEL_PROVIDERS_DICT[provider][\"fields\"],\n [\n MODEL_PROVIDERS_DICT[other_provider][\"fields\"]\n for other_provider in MODEL_PROVIDERS_DICT\n if other_provider != provider\n ],\n )\n for provider in MODEL_PROVIDERS_DICT\n }\n if field_value in provider_configs:\n fields_to_add, fields_to_delete = provider_configs[field_value]\n\n # Delete fields from other providers\n for fields in fields_to_delete:\n self.delete_fields(build_config, fields)\n\n # Add provider-specific fields\n if field_value == \"OpenAI\" and not any(field in build_config for field in fields_to_add):\n build_config.update(fields_to_add)\n else:\n build_config.update(fields_to_add)\n # Reset input types for agent_llm\n build_config[\"agent_llm\"][\"input_types\"] = []\n elif field_value == \"Custom\":\n # Delete all provider fields\n self.delete_fields(build_config, ALL_PROVIDER_FIELDS)\n # Update with custom component\n custom_component = DropdownInput(\n name=\"agent_llm\",\n display_name=\"Language Model\",\n options=[*sorted(MODEL_PROVIDERS_DICT.keys()), \"Custom\"],\n value=\"Custom\",\n real_time_refresh=True,\n input_types=[\"LanguageModel\"],\n )\n build_config.update({\"agent_llm\": custom_component.to_dict()})\n # Update input types for all fields\n build_config = self.update_input_types(build_config)\n\n # Validate required keys\n default_keys = [\n \"code\",\n \"_type\",\n \"agent_llm\",\n \"tools\",\n \"input_value\",\n \"add_current_date_tool\",\n \"system_prompt\",\n \"agent_description\",\n \"max_iterations\",\n \"handle_parsing_errors\",\n \"verbose\",\n ]\n missing_keys = [key for key in default_keys if key not in build_config]\n if missing_keys:\n msg = f\"Missing required keys in build_config: {missing_keys}\"\n raise ValueError(msg)\n if isinstance(self.agent_llm, str) and self.agent_llm in MODEL_PROVIDERS_DICT:\n provider_info = MODEL_PROVIDERS_DICT.get(self.agent_llm)\n if provider_info:\n component_class = provider_info.get(\"component_class\")\n prefix = provider_info.get(\"prefix\")\n if component_class and hasattr(component_class, \"update_build_config\"):\n # Call each component class's update_build_config method\n # remove the prefix from the field_name\n if isinstance(field_name, str) and isinstance(prefix, str):\n field_name = field_name.replace(prefix, \"\")\n build_config = component_class.update_build_config(build_config, field_value, field_name)\n\n return build_config\n"
- },
- "handle_parsing_errors": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Handle Parse Errors",
- "dynamic": false,
- "info": "Should the Agent fix errors when reading user input for better processing?",
- "list": false,
- "name": "handle_parsing_errors",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "input_value": {
- "_input_type": "MessageTextInput",
- "advanced": false,
- "display_name": "Input",
- "dynamic": false,
- "info": "The input provided by the user for the agent to process.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": true,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "json_mode": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "JSON Mode",
- "dynamic": false,
- "info": "If True, it will output JSON regardless of passing a schema.",
- "list": false,
- "name": "json_mode",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": false
- },
- "max_iterations": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Max Iterations",
- "dynamic": false,
- "info": "The maximum number of attempts the agent can make to complete its task before it stops.",
- "list": false,
- "name": "max_iterations",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 15
- },
- "max_tokens": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Max Tokens",
- "dynamic": false,
- "info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
- "list": false,
- "name": "max_tokens",
- "placeholder": "",
- "range_spec": {
- "max": 128000,
- "min": 0,
- "step": 0.1,
- "step_type": "float"
- },
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": ""
- },
- "memory": {
- "_input_type": "HandleInput",
- "advanced": true,
- "display_name": "External Memory",
- "dynamic": false,
- "info": "Retrieve messages from an external memory. If empty, it will use the Langflow tables.",
- "input_types": [
- "BaseChatMessageHistory"
- ],
- "list": false,
- "name": "memory",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "model_kwargs": {
- "_input_type": "DictInput",
- "advanced": true,
- "display_name": "Model Kwargs",
- "dynamic": false,
- "info": "Additional keyword arguments to pass to the model.",
- "list": false,
- "name": "model_kwargs",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "type": "dict",
- "value": {}
- },
- "model_name": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Model Name",
- "dynamic": false,
- "info": "",
- "name": "model_name",
- "options": [
- "gpt-4o-mini",
- "gpt-4o",
- "gpt-4-turbo",
- "gpt-4-turbo-preview",
- "gpt-4",
- "gpt-3.5-turbo",
- "gpt-3.5-turbo-0125"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "gpt-4o-mini"
- },
- "n_messages": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Number of Messages",
- "dynamic": false,
- "info": "Number of messages to retrieve.",
- "list": false,
- "name": "n_messages",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 100
- },
- "openai_api_base": {
- "_input_type": "StrInput",
- "advanced": true,
- "display_name": "OpenAI API Base",
- "dynamic": false,
- "info": "The base URL of the OpenAI API. Defaults to https://api.openai.com/v1. You can change this to use other APIs like JinaChat, LocalAI and Prem.",
- "list": false,
- "load_from_db": false,
- "name": "openai_api_base",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "order": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Order",
- "dynamic": false,
- "info": "Order of the messages.",
- "name": "order",
- "options": [
- "Ascending",
- "Descending"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Ascending"
- },
- "output_parser": {
- "_input_type": "HandleInput",
- "advanced": true,
- "display_name": "Output Parser",
- "dynamic": false,
- "info": "The parser to use to parse the output of the model",
- "input_types": [
- "OutputParser"
- ],
- "list": false,
- "name": "output_parser",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "output_schema": {
- "_input_type": "DictInput",
- "advanced": true,
- "display_name": "Schema",
- "dynamic": false,
- "info": "The schema for the Output of the model. You must pass the word JSON in the prompt. If left blank, JSON mode will be disabled. [DEPRECATED]",
- "list": true,
- "name": "output_schema",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "type": "dict",
- "value": {}
- },
- "seed": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Seed",
- "dynamic": false,
- "info": "The seed controls the reproducibility of the job.",
- "list": false,
- "name": "seed",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 1
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Filter by sender type.",
- "name": "sender",
- "options": [
- "Machine",
- "User",
- "Machine and User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Machine and User"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Filter by sender name.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "system_prompt": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Agent Instructions",
- "dynamic": false,
- "info": "System Prompt: Initial instructions and context provided to guide the agent's behavior.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "system_prompt",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "You are an AI assistant capable of fetching and analyzing YouTube video transcripts to answer user questions. You have access to a YouTube Transcripts tool that can extract spoken content from YouTube videos.\n\n\n1. First, attempt to fetch the transcript using the following settings:\n \n YouTube_Transcripts(\n url=\"{{VIDEO_URL}}\",\n transcript_format=\"text\",\n language=\"\",\n translation=\"\"\n )\n \n\n2. If you receive an error indicating that only a specific language is available (e.g., \"only pt is available\"), retry the function call with the correct language setting:\n \n YouTube_Transcripts(\n url=\"{{VIDEO_URL}}\",\n transcript_format=\"text\",\n language=\"[specified_language_code]\",\n translation=\"\"\n )\n \n\n3. Once you have successfully retrieved the transcript, analyze its content to answer the user's question.\n\n4. If you need to refer to specific parts of the video, you can make an additional call to get chunked transcripts:\n \n YouTube_Transcripts(\n url=\"{{VIDEO_URL}}\",\n transcript_format=\"chunks\",\n chunk_size_seconds=60,\n language=\"[language_used_in_successful_call]\",\n translation=\"\"\n )\n \n\nWhen answering the user's question:\n- Provide a clear and concise answer based on the information in the transcript.\n- If the question cannot be answered using the transcript alone, state this clearly and explain why.\n- If you need to quote the transcript, use quotation marks and provide context.\n- If referring to specific timestamps, mention them in your answer (only if you've retrieved chunked transcripts).\n\nRemember, your primary goal is to accurately answer the user's question using the information available in the video transcript. If you encounter any issues or if the question cannot be answered based on the transcript, explain this clearly in your response."
- },
- "temperature": {
- "_input_type": "FloatInput",
- "advanced": true,
- "display_name": "Temperature",
- "dynamic": false,
- "info": "",
- "list": false,
- "name": "temperature",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "float",
- "value": 0.1
- },
- "template": {
- "_input_type": "MultilineInput",
- "advanced": true,
- "display_name": "Template",
- "dynamic": false,
- "info": "The template to use for formatting the data. It can contain the keys {text}, {sender} or any other key in the message data.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "template",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "{sender_name}: {text}"
- },
- "tools": {
- "_input_type": "HandleInput",
- "advanced": false,
- "display_name": "Tools",
- "dynamic": false,
- "info": "These are the tools that the agent can use to help with tasks.",
- "input_types": [
- "Tool",
- "BaseTool",
- "StructuredTool"
- ],
- "list": true,
- "name": "tools",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "other",
- "value": ""
- },
- "verbose": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Verbose",
- "dynamic": false,
- "info": "",
- "list": false,
- "name": "verbose",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- }
- },
- "tool_mode": false
- },
- "type": "Agent"
- },
- "dragging": false,
- "height": 650,
- "id": "Agent-EGSx3",
- "position": {
- "x": -631.1849833420482,
- "y": -1088.2379740335518
- },
- "positionAbsolute": {
- "x": -631.1849833420482,
- "y": -1088.2379740335518
- },
- "selected": true,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "id": "ChatInput-B1nYa",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Get chat inputs from the Playground.",
- "display_name": "Chat Input",
- "documentation": "",
- "edited": false,
- "field_order": [
- "input_value",
- "should_store_message",
- "sender",
- "sender_name",
- "session_id",
- "files",
- "background_color",
- "chat_icon",
- "text_color"
- ],
- "frozen": false,
- "icon": "MessagesSquare",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Message",
- "method": "message_response",
- "name": "message",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "background_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Background Color",
- "dynamic": false,
- "info": "The background color of the icon.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "background_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "chat_icon": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Icon",
- "dynamic": false,
- "info": "The icon of the message.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "chat_icon",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES\nfrom langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, FileInput, MessageTextInput, MultilineInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_USER, MESSAGE_SENDER_USER\n\n\nclass ChatInput(ChatComponent):\n display_name = \"Chat Input\"\n description = \"Get chat inputs from the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n value=\"\",\n info=\"Message to be passed as input.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_USER,\n info=\"Type of sender.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_USER,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n FileInput(\n name=\"files\",\n display_name=\"Files\",\n file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,\n info=\"Files to be sent with the message.\",\n advanced=True,\n is_list=True,\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Message\", name=\"message\", method=\"message_response\"),\n ]\n\n def message_response(self) -> Message:\n _background_color = self.background_color\n _text_color = self.text_color\n _icon = self.chat_icon\n message = Message(\n text=self.input_value,\n sender=self.sender,\n sender_name=self.sender_name,\n session_id=self.session_id,\n files=self.files,\n properties={\"background_color\": _background_color, \"text_color\": _text_color, \"icon\": _icon},\n )\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
- },
- "files": {
- "_input_type": "FileInput",
- "advanced": true,
- "display_name": "Files",
- "dynamic": false,
- "fileTypes": [
- "txt",
- "md",
- "mdx",
- "csv",
- "json",
- "yaml",
- "yml",
- "xml",
- "html",
- "htm",
- "pdf",
- "docx",
- "py",
- "sh",
- "sql",
- "js",
- "ts",
- "tsx",
- "jpg",
- "jpeg",
- "png",
- "bmp",
- "image"
- ],
- "file_path": "",
- "info": "Files to be sent with the message.",
- "list": true,
- "name": "files",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "file",
- "value": ""
- },
- "input_value": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Message to be passed as input.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "can you see the transcript from this video and tell me what this is about? https://www.youtube.com/watch?v=UkV79sJAvz8"
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Type of sender.",
- "name": "sender",
- "options": [
- "Machine",
- "User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "User"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Name of the sender.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "User"
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "should_store_message": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Store Messages",
- "dynamic": false,
- "info": "Store the message in the history.",
- "list": false,
- "name": "should_store_message",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "text_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Text Color",
- "dynamic": false,
- "info": "The text color of the name",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "text_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- }
- },
- "tool_mode": false
- },
- "type": "ChatInput"
- },
- "dragging": false,
- "height": 234,
- "id": "ChatInput-B1nYa",
- "position": {
- "x": -996.5201766752447,
- "y": -667.1593168473087
- },
- "positionAbsolute": {
- "x": -996.5201766752447,
- "y": -667.1593168473087
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "description": "Display a chat message in the Playground.",
- "display_name": "Chat Output",
- "id": "ChatOutput-zUzVK",
- "node": {
- "base_classes": [
- "Message"
- ],
- "beta": false,
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Display a chat message in the Playground.",
- "display_name": "Chat Output",
- "documentation": "",
- "edited": false,
- "field_order": [
- "input_value",
- "should_store_message",
- "sender",
- "sender_name",
- "session_id",
- "data_template",
- "background_color",
- "chat_icon",
- "text_color"
- ],
- "frozen": false,
- "icon": "MessagesSquare",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Message",
- "method": "message_response",
- "name": "message",
- "selected": "Message",
- "types": [
- "Message"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "background_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Background Color",
- "dynamic": false,
- "info": "The background color of the icon.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "background_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "chat_icon": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Icon",
- "dynamic": false,
- "info": "The icon of the message.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "chat_icon",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langflow.base.io.chat import ChatComponent\nfrom langflow.inputs import BoolInput\nfrom langflow.io import DropdownInput, MessageInput, MessageTextInput, Output\nfrom langflow.schema.message import Message\nfrom langflow.schema.properties import Source\nfrom langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_NAME_AI, MESSAGE_SENDER_USER\n\n\nclass ChatOutput(ChatComponent):\n display_name = \"Chat Output\"\n description = \"Display a chat message in the Playground.\"\n icon = \"MessagesSquare\"\n name = \"ChatOutput\"\n\n inputs = [\n MessageInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Message to be passed as output.\",\n ),\n BoolInput(\n name=\"should_store_message\",\n display_name=\"Store Messages\",\n info=\"Store the message in the history.\",\n value=True,\n advanced=True,\n ),\n DropdownInput(\n name=\"sender\",\n display_name=\"Sender Type\",\n options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],\n value=MESSAGE_SENDER_AI,\n advanced=True,\n info=\"Type of sender.\",\n ),\n MessageTextInput(\n name=\"sender_name\",\n display_name=\"Sender Name\",\n info=\"Name of the sender.\",\n value=MESSAGE_SENDER_NAME_AI,\n advanced=True,\n ),\n MessageTextInput(\n name=\"session_id\",\n display_name=\"Session ID\",\n info=\"The session ID of the chat. If empty, the current session ID parameter will be used.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"data_template\",\n display_name=\"Data Template\",\n value=\"{text}\",\n advanced=True,\n info=\"Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.\",\n ),\n MessageTextInput(\n name=\"background_color\",\n display_name=\"Background Color\",\n info=\"The background color of the icon.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"chat_icon\",\n display_name=\"Icon\",\n info=\"The icon of the message.\",\n advanced=True,\n ),\n MessageTextInput(\n name=\"text_color\",\n display_name=\"Text Color\",\n info=\"The text color of the name\",\n advanced=True,\n ),\n ]\n outputs = [\n Output(\n display_name=\"Message\",\n name=\"message\",\n method=\"message_response\",\n ),\n ]\n\n def _build_source(self, _id: str | None, display_name: str | None, source: str | None) -> Source:\n source_dict = {}\n if _id:\n source_dict[\"id\"] = _id\n if display_name:\n source_dict[\"display_name\"] = display_name\n if source:\n source_dict[\"source\"] = source\n return Source(**source_dict)\n\n def message_response(self) -> Message:\n _source, _icon, _display_name, _source_id = self.get_properties_from_source_component()\n _background_color = self.background_color\n _text_color = self.text_color\n if self.chat_icon:\n _icon = self.chat_icon\n message = self.input_value if isinstance(self.input_value, Message) else Message(text=self.input_value)\n message.sender = self.sender\n message.sender_name = self.sender_name\n message.session_id = self.session_id\n message.flow_id = self.graph.flow_id if hasattr(self, \"graph\") else None\n message.properties.source = self._build_source(_source_id, _display_name, _source)\n message.properties.icon = _icon\n message.properties.background_color = _background_color\n message.properties.text_color = _text_color\n if self.session_id and isinstance(message, Message) and self.should_store_message:\n stored_message = self.send_message(\n message,\n )\n self.message.value = stored_message\n message = stored_message\n\n self.status = message\n return message\n"
- },
- "data_template": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Data Template",
- "dynamic": false,
- "info": "Template to convert Data to Text. If left empty, it will be dynamically set to the Data's text key.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "data_template",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "{text}"
- },
- "input_value": {
- "_input_type": "MessageInput",
- "advanced": false,
- "display_name": "Text",
- "dynamic": false,
- "info": "Message to be passed as output.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "input_value",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "sender": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Sender Type",
- "dynamic": false,
- "info": "Type of sender.",
- "name": "sender",
- "options": [
- "Machine",
- "User"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "Machine"
- },
- "sender_name": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Sender Name",
- "dynamic": false,
- "info": "Name of the sender.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "sender_name",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": "AI"
- },
- "session_id": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Session ID",
- "dynamic": false,
- "info": "The session ID of the chat. If empty, the current session ID parameter will be used.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "session_id",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "should_store_message": {
- "_input_type": "BoolInput",
- "advanced": true,
- "display_name": "Store Messages",
- "dynamic": false,
- "info": "Store the message in the history.",
- "list": false,
- "name": "should_store_message",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "bool",
- "value": true
- },
- "text_color": {
- "_input_type": "MessageTextInput",
- "advanced": true,
- "display_name": "Text Color",
- "dynamic": false,
- "info": "The text color of the name",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "name": "text_color",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- }
- },
- "tool_mode": false
- },
- "type": "ChatOutput"
- },
- "dragging": false,
- "height": 234,
- "id": "ChatOutput-zUzVK",
- "position": {
- "x": -261.7796479132812,
- "y": -677.0769470644535
- },
- "positionAbsolute": {
- "x": -261.7796479132812,
- "y": -677.0769470644535
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- },
- {
- "data": {
- "id": "note-f5vkx",
- "node": {
- "description": "# YouTube Transcript Q&A\nA quick way to ask questions about YouTube video content through transcript analysis!\n\n## Instructions\n1. **Input Your Query**\n - Paste YouTube video URL\n - Add your question about the content\n - Format: \"What is this video about? [URL]\"\n\n2. **Get Analysis**\n - System extracts video transcript\n - AI processes your question\n - Provides detailed answer from content\n\n3. **Additional Features**\n - Handles multiple languages\n - Can reference specific timestamps\n - Supports follow-up questions\n\n4. **Best Practices**\n - Ensure video has captions/subtitles\n - Ask specific questions\n - For timing details, mention timestamps\n\n5. **Common Uses**\n - Content summaries\n - Finding specific information\n - Understanding key points\n - Fact checking video claims\n\nRemember: Quality depends on available transcripts! 🎥💬",
- "display_name": "",
- "documentation": "",
- "template": {}
- },
- "type": "note"
- },
- "dragging": false,
- "height": 800,
- "id": "note-f5vkx",
- "position": {
- "x": -1627.783352547462,
- "y": -1212.3239149398214
- },
- "positionAbsolute": {
- "x": -1627.783352547462,
- "y": -1212.3239149398214
- },
- "resizing": false,
- "selected": false,
- "style": {
- "height": 800,
- "width": 600
- },
- "type": "noteNode",
- "width": 600
- },
- {
- "data": {
- "id": "YouTubeTranscriptsComponent-n8Z9Y",
- "node": {
- "base_classes": [
- "Data",
- "Tool"
- ],
- "beta": false,
- "category": "tools",
- "conditional_paths": [],
- "custom_fields": {},
- "description": "Extracts spoken content from YouTube videos as transcripts.",
- "display_name": "YouTube Transcripts",
- "documentation": "",
- "edited": false,
- "field_order": [
- "url",
- "transcript_format",
- "chunk_size_seconds",
- "language",
- "translation"
- ],
- "frozen": false,
- "icon": "YouTube",
- "key": "YouTubeTranscriptsComponent",
- "legacy": false,
- "lf_version": "1.0.19.post2",
- "metadata": {},
- "output_types": [],
- "outputs": [
- {
- "cache": true,
- "display_name": "Data",
- "method": "build_youtube_transcripts",
- "name": "transcripts",
- "selected": "Data",
- "types": [
- "Data"
- ],
- "value": "__UNDEFINED__"
- },
- {
- "cache": true,
- "display_name": "Tool",
- "method": "build_youtube_tool",
- "name": "transcripts_tool",
- "selected": "Tool",
- "types": [
- "Tool"
- ],
- "value": "__UNDEFINED__"
- }
- ],
- "pinned": false,
- "template": {
- "_type": "Component",
- "chunk_size_seconds": {
- "_input_type": "IntInput",
- "advanced": true,
- "display_name": "Chunk Size (seconds)",
- "dynamic": false,
- "info": "The size of each transcript chunk in seconds. Only applicable when 'Transcript Format' is set to 'chunks'.",
- "list": false,
- "name": "chunk_size_seconds",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "trace_as_metadata": true,
- "type": "int",
- "value": 60
- },
- "code": {
- "advanced": true,
- "dynamic": true,
- "fileTypes": [],
- "file_path": "",
- "info": "",
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "code",
- "password": false,
- "placeholder": "",
- "required": true,
- "show": true,
- "title_case": false,
- "type": "code",
- "value": "from langchain.tools import StructuredTool\nfrom langchain_community.document_loaders import YoutubeLoader\nfrom langchain_community.document_loaders.youtube import TranscriptFormat\nfrom langchain_core.tools import ToolException\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import DropdownInput, IntInput, MultilineInput\nfrom langflow.schema import Data\nfrom langflow.template import Output\n\n\nclass YoutubeApiSchema(BaseModel):\n \"\"\"Schema to define the input structure for the tool.\"\"\"\n\n url: str = Field(..., description=\"The YouTube URL to get transcripts from.\")\n transcript_format: TranscriptFormat = Field(\n TranscriptFormat.TEXT,\n description=\"The format of the transcripts. Either 'text' for a single \"\n \"text output or 'chunks' for timestamped chunks.\",\n )\n chunk_size_seconds: int = Field(\n 120,\n description=\"The size of each transcript chunk in seconds. Only \"\n \"applicable when 'Transcript Format' is set to 'chunks'.\",\n )\n language: str = Field(\n \"\",\n description=\"A comma-separated list of language codes in descending \" \"priority. Leave empty for default.\",\n )\n translation: str = Field(\n \"\", description=\"Translate the transcripts to the specified language. \" \"Leave empty for no translation.\"\n )\n\n\nclass YouTubeTranscriptsComponent(LCToolComponent):\n \"\"\"A component that extracts spoken content from YouTube videos as transcripts.\"\"\"\n\n display_name: str = \"YouTube Transcripts\"\n description: str = \"Extracts spoken content from YouTube videos as transcripts.\"\n icon: str = \"YouTube\"\n\n inputs = [\n MultilineInput(\n name=\"url\", display_name=\"Video URL\", info=\"Enter the YouTube video URL to get transcripts from.\"\n ),\n DropdownInput(\n name=\"transcript_format\",\n display_name=\"Transcript Format\",\n options=[\"text\", \"chunks\"],\n value=\"text\",\n info=\"The format of the transcripts. Either 'text' for a single output \"\n \"or 'chunks' for timestamped chunks.\",\n ),\n IntInput(\n name=\"chunk_size_seconds\",\n display_name=\"Chunk Size (seconds)\",\n value=60,\n advanced=True,\n info=\"The size of each transcript chunk in seconds. Only applicable when \"\n \"'Transcript Format' is set to 'chunks'.\",\n ),\n MultilineInput(\n name=\"language\",\n display_name=\"Language\",\n info=\"A comma-separated list of language codes in descending priority. \" \"Leave empty for default.\",\n ),\n DropdownInput(\n name=\"translation\",\n display_name=\"Translation Language\",\n advanced=True,\n options=[\"\", \"en\", \"es\", \"fr\", \"de\", \"it\", \"pt\", \"ru\", \"ja\", \"ko\", \"hi\", \"ar\", \"id\"],\n info=\"Translate the transcripts to the specified language. \" \"Leave empty for no translation.\",\n ),\n ]\n\n outputs = [\n Output(name=\"transcripts\", display_name=\"Data\", method=\"build_youtube_transcripts\"),\n Output(name=\"transcripts_tool\", display_name=\"Tool\", method=\"build_youtube_tool\"),\n ]\n\n def build_youtube_transcripts(self) -> Data | list[Data]:\n \"\"\"Method to build transcripts from the provided YouTube URL.\n\n Returns:\n Data | list[Data]: The transcripts of the video, either as a single\n Data object or a list of Data objects.\n \"\"\"\n try:\n loader = YoutubeLoader.from_youtube_url(\n self.url,\n transcript_format=TranscriptFormat.TEXT\n if self.transcript_format == \"text\"\n else TranscriptFormat.CHUNKS,\n chunk_size_seconds=self.chunk_size_seconds,\n language=self.language.split(\",\") if self.language else [\"en\"],\n translation=self.translation if self.translation else None,\n )\n\n transcripts = loader.load()\n\n if self.transcript_format == \"text\":\n # Extract only the page_content from the Document\n return Data(data={\"transcripts\": transcripts[0].page_content})\n # For chunks, extract page_content and metadata separately\n return [Data(data={\"content\": doc.page_content, \"metadata\": doc.metadata}) for doc in transcripts]\n\n except Exception as exc: # noqa: BLE001\n # Using a specific error type for the return value\n return Data(data={\"error\": f\"Failed to get YouTube transcripts: {exc!s}\"})\n\n def youtube_transcripts(\n self,\n url: str = \"\",\n transcript_format: TranscriptFormat = TranscriptFormat.TEXT,\n chunk_size_seconds: int = 120,\n language: str = \"\",\n translation: str = \"\",\n ) -> Data | list[Data]:\n \"\"\"Helper method to handle transcripts outside of component calls.\n\n Args:\n url: The YouTube URL to get transcripts from.\n transcript_format: Format of transcripts ('text' or 'chunks').\n chunk_size_seconds: Size of each transcript chunk in seconds.\n language: Comma-separated list of language codes.\n translation: Target language for translation.\n\n Returns:\n Data | list[Data]: Video transcripts as single Data or list of Data.\n \"\"\"\n try:\n if isinstance(transcript_format, str):\n transcript_format = TranscriptFormat(transcript_format)\n loader = YoutubeLoader.from_youtube_url(\n url,\n transcript_format=TranscriptFormat.TEXT\n if transcript_format == TranscriptFormat.TEXT\n else TranscriptFormat.CHUNKS,\n chunk_size_seconds=chunk_size_seconds,\n language=language.split(\",\") if language else [\"en\"],\n translation=translation if translation else None,\n )\n\n transcripts = loader.load()\n if transcript_format == TranscriptFormat.TEXT and len(transcripts) > 0:\n return Data(data={\"transcript\": transcripts[0].page_content})\n return [Data(data={\"content\": doc.page_content, \"metadata\": doc.metadata}) for doc in transcripts]\n except Exception as exc:\n msg = f\"Failed to get YouTube transcripts: {exc!s}\"\n raise ToolException(msg) from exc\n\n def build_youtube_tool(self) -> Tool:\n \"\"\"Method to build the transcripts tool.\n\n Returns:\n Tool: A structured tool that uses the transcripts method.\n\n Raises:\n RuntimeError: If tool creation fails.\n \"\"\"\n try:\n return StructuredTool.from_function(\n name=\"youtube_transcripts\",\n description=\"Get transcripts from YouTube videos.\",\n func=self.youtube_transcripts,\n args_schema=YoutubeApiSchema,\n )\n\n except Exception as exc:\n msg = f\"Failed to build the YouTube transcripts tool: {exc!s}\"\n raise RuntimeError(msg) from exc\n"
- },
- "language": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Language",
- "dynamic": false,
- "info": "A comma-separated list of language codes in descending priority. Leave empty for default.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "language",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "transcript_format": {
- "_input_type": "DropdownInput",
- "advanced": false,
- "combobox": false,
- "display_name": "Transcript Format",
- "dynamic": false,
- "info": "The format of the transcripts. Either 'text' for a single output or 'chunks' for timestamped chunks.",
- "name": "transcript_format",
- "options": [
- "text",
- "chunks"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": "chunks"
- },
- "translation": {
- "_input_type": "DropdownInput",
- "advanced": true,
- "combobox": false,
- "display_name": "Translation Language",
- "dynamic": false,
- "info": "Translate the transcripts to the specified language. Leave empty for no translation.",
- "name": "translation",
- "options": [
- "",
- "en",
- "es",
- "fr",
- "de",
- "it",
- "pt",
- "ru",
- "ja",
- "ko",
- "hi",
- "ar",
- "id"
- ],
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- },
- "url": {
- "_input_type": "MultilineInput",
- "advanced": false,
- "display_name": "Video URL",
- "dynamic": false,
- "info": "Enter the YouTube video URL to get transcripts from.",
- "input_types": [
- "Message"
- ],
- "list": false,
- "load_from_db": false,
- "multiline": true,
- "name": "url",
- "placeholder": "",
- "required": false,
- "show": true,
- "title_case": false,
- "tool_mode": false,
- "trace_as_input": true,
- "trace_as_metadata": true,
- "type": "str",
- "value": ""
- }
- },
- "tool_mode": false
- },
- "type": "YouTubeTranscriptsComponent"
- },
- "dragging": false,
- "height": 475,
- "id": "YouTubeTranscriptsComponent-n8Z9Y",
- "position": {
- "x": -996.7508450845454,
- "y": -1169.8625689107164
- },
- "positionAbsolute": {
- "x": -996.7508450845454,
- "y": -1169.8625689107164
- },
- "selected": false,
- "type": "genericNode",
- "width": 320
- }
- ],
- "viewport": {
- "x": 1337.7257173603357,
- "y": 1096.2297230048744,
- "zoom": 0.7807596345995297
- }
- },
- "description": "Quickly get detailed answers to questions about YouTube videos by analyzing their transcripts.",
- "endpoint_name": null,
- "gradient": "3",
- "icon": "Youtube",
- "id": "3b33c431-9b8b-4ba1-9372-04b785e590d3",
- "is_component": false,
- "last_tested_version": "1.0.19.post2",
- "name": "YouTube Transcript Q&A",
- "tags": [
- "agents",
- "content-generation",
- "rag",
- "q-a"
- ]
-}
\ No newline at end of file