Python Tool step
Use the Python Tool step to run a custom API call to another product / service
The Python Tool step allows you to use Python to take outputs from other Tool steps and manipulate data for other Tool steps and LLMs.
What is Python?
Python is a widely used programming language known for its clarity and simplicity. It’s popular among beginners and experts alike because it’s easy to read, quick to write, and versatile enough for tasks ranging from web development and automation to data analysis and machine learning. With a massive library ecosystem and strong community support, Python is a powerful tool for solving real-world problems efficiently.
Add the Python Tool step to your Tool
You can add the Python Tool step to your Tool by:
- Creating a new Tool, then searching for the ‘Convert PDF to text’ Tool step
- Click ‘Expand’ to see the full Tool step
- Enter your code in the ‘Code’ field
- Click ’+ New item’ under ‘PyPl Packages’ if you need to install any packages
- Click ‘Run step’ to run the Tool step
Accessing variables
You can access Tool input variables, other Tool step outputs, and API keys you’ve created in Relevance in your Python Tool step.
Input variables
You can access Input variables by following this syntax, where ‘name’ is the variable for your input.
Other Tool step outputs
You can access other Tool step outputs by following this syntax, where ‘tool_step’ is the variable for the Tool step you’re trying to access the output of.
You can then access a specific output of that Tool step by adding another variable.
API keys
You can access one of your saved API keys by using this syntax, where ‘api_key’ is the variable for the key you’re trying to access.
Advanced Settings
Backend
You can choose between two backend services to run the code, ‘Modal Labs’ or ‘e2b.dev’.
Runtime Commands
You can include a list of Linux terminal commands to be run before running your code.
Session ID
Define a custom session that saves all local variables between Python executions.
Enable ‘Long Output’ Mode
Allow the output to be longer than 127,000 characters, in exchange for 2-4 seconds of extra latency.
Number of GPUs
Allows you to specify a number of GPUs for your code to use.
Number of CPU Cores
Allows you to specify a number of CPU cores for your code to use.
Memory Size
Allows you to specify an amount of RAM for your code to use.
Session Timeout
Allows you to specify (in seconds) how long the code should run before timing out.
Raise Error
Allows you to specify how errors are raised:
- Error with Full Traceback
- Error
- Print Error to Stderr
Enable fallback
If the selected backend fails, when this is selected, your code will attempt to run via the other backend.