diff --git a/404.html b/404.html index 9b349f292d..5969f0bdfa 100644 --- a/404.html +++ b/404.html @@ -24,7 +24,7 @@ - +
diff --git a/agent-tutorial.html b/agent-tutorial.html index bb55aee5f9..f07de9568c 100644 --- a/agent-tutorial.html +++ b/agent-tutorial.html @@ -24,7 +24,7 @@ - + diff --git a/agents-tools.html b/agents-tools.html index ebf3b204a2..da04535a52 100644 --- a/agents-tools.html +++ b/agents-tools.html @@ -24,7 +24,7 @@ - + diff --git a/agents.html b/agents.html index ebb8f9eca4..bd1fd6cd9c 100644 --- a/agents.html +++ b/agents.html @@ -24,7 +24,7 @@ - + diff --git a/api-build.html b/api-build.html index f3446af801..a6d163fa49 100644 --- a/api-build.html +++ b/api-build.html @@ -24,7 +24,7 @@ - + diff --git a/api-files.html b/api-files.html index b9a8142899..055ed979b5 100644 --- a/api-files.html +++ b/api-files.html @@ -24,7 +24,7 @@ - + diff --git a/api-flows-run.html b/api-flows-run.html index 74dae45829..0d273f68f9 100644 --- a/api-flows-run.html +++ b/api-flows-run.html @@ -24,7 +24,7 @@ - + diff --git a/api-flows.html b/api-flows.html index 0681da5205..df05c7a62b 100644 --- a/api-flows.html +++ b/api-flows.html @@ -24,7 +24,7 @@ - + diff --git a/api-keys-and-authentication.html b/api-keys-and-authentication.html index cd4019b104..72c8e1aa9d 100644 --- a/api-keys-and-authentication.html +++ b/api-keys-and-authentication.html @@ -24,7 +24,7 @@ - + diff --git a/api-logs.html b/api-logs.html index 42d2e8b254..10df2c42bd 100644 --- a/api-logs.html +++ b/api-logs.html @@ -24,7 +24,7 @@ - + diff --git a/api-monitor.html b/api-monitor.html index 734cea95fc..24777a35df 100644 --- a/api-monitor.html +++ b/api-monitor.html @@ -24,7 +24,7 @@ - + diff --git a/api-openai-responses.html b/api-openai-responses.html index d139139e61..8bfc135698 100644 --- a/api-openai-responses.html +++ b/api-openai-responses.html @@ -24,7 +24,7 @@ - + diff --git a/api-projects.html b/api-projects.html index 8f94791fff..f645828ea6 100644 --- a/api-projects.html +++ b/api-projects.html @@ -24,7 +24,7 @@ - + diff --git a/api-reference-api-examples.html b/api-reference-api-examples.html index 71b1257dc2..a4ff621ea2 100644 --- a/api-reference-api-examples.html +++ b/api-reference-api-examples.html @@ -24,7 +24,7 @@ - + diff --git a/api-request.html b/api-request.html index 4ac8ae69d5..2072cb4cbf 100644 --- a/api-request.html +++ b/api-request.html @@ -24,7 +24,7 @@ - + diff --git a/api-users.html b/api-users.html index 9a9a2d2d9c..6666e0f9d0 100644 --- a/api-users.html +++ b/api-users.html @@ -24,7 +24,7 @@ - + diff --git a/api.html b/api.html index 374604689e..2ab720e943 100644 --- a/api.html +++ b/api.html @@ -24,7 +24,7 @@ - + diff --git a/api/openapi.json.html b/api/openapi.json.html index 7f8cd38869..bf3ade5b3f 100644 --- a/api/openapi.json.html +++ b/api/openapi.json.html @@ -24,7 +24,7 @@ - + diff --git a/api/openapi.yaml.html b/api/openapi.yaml.html index 257bce3c2e..7ed2b1ad2c 100644 --- a/api/openapi.yaml.html +++ b/api/openapi.yaml.html @@ -24,7 +24,7 @@ - + diff --git a/assets/js/1a29c454.98aaee60.js b/assets/js/1a29c454.98aaee60.js new file mode 100644 index 0000000000..26d38fccd8 --- /dev/null +++ b/assets/js/1a29c454.98aaee60.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunklangflow_docs=self.webpackChunklangflow_docs||[]).push([[3140],{11470:(o,t,e)=>{e.d(t,{A:()=>x});var n=e(96540),r=e(18215),s=e(23104),l=e(56347),c=e(205),p=e(57485),a=e(31682),y=e(70679);function i(o){return n.Children.toArray(o).filter(o=>"\n"!==o).map(o=>{if(!o||(0,n.isValidElement)(o)&&function(o){const{props:t}=o;return!!t&&"object"==typeof t&&"value"in t}(o))return o;throw new Error(`Docusaurus error: BadpandasResult:
_12Executed run_python_repl_12_12Input:_12_12{_12 "python_code": "import pandas as pd\nimport math\n\n# Create a simple DataFrame\ndf = pd.DataFrame({\n 'numbers': [1, 2, 3, 4, 5],\n 'squares': [x**2 for x in range(1, 6)]\n})\n\n# Calculate the square root of the mean\nresult = math.sqrt(df['squares'].mean())\nprint(f\"Square root of mean squares: {result}\")"_12}_12Output:_12_12{_12 "result": "Square root of mean squares: 3.3166247903554"_12}
If you don't include the package imports in the chat, the agent can still create the table using pd.DataFrame, because the pandas package is imported globally by the Python Interpreter component in the Global Imports field.
+Pass inputs to the Python Interpreter​
+To pass inputs to the Python Interpreter component, you need to customize the component's code to add input fields.
+After the input field is added to the component code, the port becomes available for connections.
+For example, to connect a Text component and pass a URL value to the Python Interpreter component, do the following:
+
+-
+
Add a Python Interpreter component to your flow.
+
+-
+
To modify the Python Interpreter component's code, click Edit Code.
+
+-
+
To pass a URL input to the Python Interpreter component, make the following changes to the code:
+a. Add the URL input field to the inputs list. This creates the input port that other components can connect to.
+b. Update the get_globals method to extract the URL value and add it to the globals dictionary.
+This makes the url variable available in the component's Python code.
+c. Update the default Python code value to use the url variable.
+The following example demonstrates these modifications.
+Python code example
_121import importlib_121_121from langchain_experimental.utilities import PythonREPL_121from lfx.custom.custom_component.component import Component_121from lfx.io import MultilineInput, Output, StrInput_121from lfx.schema.data import Data_121from lfx.schema.message import Message # Needed to extract text from Message objects_121_121class PythonREPLComponent(Component):_121 display_name = "Python Interpreter"_121 description = "Run Python code with optional imports. Use print() to see the output."_121 documentation: str = "https://docs.langflow.org/python-interpreter"_121 icon = "square-terminal"_121_121 inputs = [_121 StrInput(_121 name="global_imports",_121 display_name="Global Imports",_121 info="A comma-separated list of modules to import globally, e.g. 'math,numpy,pandas'.",_121 value="math,pandas",_121 required=True,_121 ),_121 MultilineInput(_121 name="python_code",_121 display_name="Python Code",_121 info="The Python code to execute. Only modules specified in Global Imports can be used. Use 'url' variable if URL input is connected.",_121 value="print(f'URL: {url}')", # Updated to make the URL variable available to the Python code execution_121 input_types=["Message"],_121 tool_mode=True,_121 required=True,_121 ),_121 # Add the URL input field to inputs list_121 StrInput(_121 name="url",_121 display_name="URL",_121 info="URL variable that can be used in Python code. Connect a Text component or enter manually.",_121 value="",_121 input_types=["Text", "Message"],_121 required=False,_121 ),_121 ]_121_121 outputs = [_121 Output(_121 display_name="Results",_121 name="results",_121 type_=Data,_121 method="run_python_repl",_121 ),_121 ]_121_121 def get_globals(self, global_imports: str | list[str]) -> dict:_121 """Create a globals dictionary with only the specified allowed imports and input variables."""_121 global_dict = {}_121_121 try:_121 if isinstance(global_imports, str):_121 modules = [module.strip() for module in global_imports.split(",")]_121 elif isinstance(global_imports, list):_121 modules = global_imports_121 else:_121 msg = "global_imports must be either a string or a list"_121 raise TypeError(msg)_121_121 for module in modules:_121 try:_121 imported_module = importlib.import_module(module)_121 global_dict[imported_module.__name__] = imported_module_121 except ImportError as e:_121 msg = f"Could not import module {module}: {e!s}"_121 raise ImportError(msg) from e_121_121 # Add the URL variable to the component's globals dictionary_121 # Extract from Message object or use the string directly_121 if hasattr(self, "url") and self.url:_121 url_value = self.url.text if isinstance(self.url, Message) else str(self.url)_121 if url_value:_121 global_dict["url"] = url_value # Makes 'url' available in Python code_121 self.log(f"URL variable set: {url_value}")_121_121 except Exception as e:_121 self.log(f"Error in global imports: {e!s}")_121 raise_121 else:_121 self.log(f"Successfully imported modules: {list(global_dict.keys())}")_121 return global_dict_121_121 def run_python_repl(self) -> Data:_121 try:_121 # Extract Python code text if it's a Message object_121 python_code_text = self.python_code_121 if isinstance(python_code_text, Message):_121 python_code_text = python_code_text.text if python_code_text.text else ""_121 elif not isinstance(python_code_text, str):_121 python_code_text = str(python_code_text)_121_121 globals_ = self.get_globals(self.global_imports)_121 python_repl = PythonREPL(_globals=globals_)_121 result = python_repl.run(python_code_text)_121 result = result.strip() if result else ""_121_121 self.log("Code execution completed successfully")_121 return Data(data={"result": result})_121_121 except ImportError as e:_121 error_message = f"Import Error: {e!s}"_121 self.log(error_message)_121 return Data(data={"error": error_message})_121_121 except SyntaxError as e:_121 error_message = f"Syntax Error: {e!s}"_121 self.log(error_message)_121 return Data(data={"error": error_message})_121_121 except (NameError, TypeError, ValueError) as e:_121 error_message = f"Error during execution: {e!s}"_121 self.log(error_message)_121 return Data(data={"error": error_message})_121_121 def build(self):_121 return self.run_python_repl
+
+-
+
To save the modifications, click Check & Save.
+
+-
+
Add a Text component to your flow and set its value, such as google.com.
+
+-
+
Connect the Text component's output to the new URL input field on your customized Python Interpreter component.
+
+
+The Python Interpreter component can now use the url variable in the Python code that it executes.
Python Interpreter parameters​
-Name Type Description global_imports String Input parameter. A comma-separated list of modules to import globally, such as math,pandas,numpy. python_code Code Input parameter. The Python code to execute. Only modules specified in Global Imports can be used. results Data Output parameter. The output of the executed Python code, including any printed results or errors.