Getting Started
Create and run your first Code Runner block in Hunch
Introduction
Code Runner blocks are powerful tools in Hunch that allow you to execute custom Python or Bash code within your canvas. This feature enables you to process data, interact with external services, and create dynamic outputs, enhancing your AI workflows with custom logic and integrations.
Setting Up Your First Code Runner Block
Follow these steps to create and run your first Code Runner block:
- Create a new Canvas in Hunch.
- Change the initial Auto-AI Block into a Code Runner by selecting All -> Code Runner:
- Enter your code as a markdown code block, specifying the language as either
python
orbash
: - Click the ‘Run’ button to execute your code.
Simple Script Examples
Python Example
Here’s a simple Python script that outputs “Hello, World!”:
Bash Example
Here’s a simple Bash script that achieves the same result:
Troubleshooting Guide
If you encounter issues with your Code Runner block, consider these common problems and solutions:
- Syntax Errors: Double-check your code for syntax errors. Use an IDE or online linter for assistance.
- Permissions: Ensure you have the necessary permissions for accessing resources or executing commands.
- Input/Output Handling: Verify that you’re using the correct methods for input and output (e.g.,
hunch.output()
for Python, writing to/output.md
for Bash). - External Dependencies: When using external libraries in Python, confirm they are imported correctly and available in the environment.
Advanced Topics and Next Steps
Now that you’re familiar with the basics of Code Runner blocks, explore more advanced topics:
- Working with complex inputs and data structures
- Performing advanced data transformations
- Integrating with external APIs and services
- Optimizing code performance
- Implementing error handling and logging best practices
Check out the other sections of this documentation for in-depth guidance on these topics and to unlock the full potential of Code Runner blocks in your Hunch workflows.