Code Runner
Python
Reference documentation for the hunch
Python module available in the Code Runner
Functions
hunch.output
Appends the given values to the output file. This function has a similar
signature to the built-in print
.
Parameters:
*values
object : The values to be written to the output.sep
Optional[str] : The separator between values. Defaults to a space.end
Optional[str] : The string appended after the last value. Defaults to a newline.
Example:
hunch.input
Loads and returns the input JSON.
Returns:
- Input : The validated input data
Example:
hunch.compiled_prompt
Gets the entire compiled prompt.
Parameters:
instructions
bool : Whether to include the instructions of the code runner block. Defaults to false.titles
bool : Whether to include the titles of the blocks. Defaults to true.
Returns:
- str : The compiled prompt
Example:
hunch.extract_url
Extracts the first URL from the upstream blocks.
Returns:
- str : The first URL found.
Raises:
- Error : If no URL is found
Example:
hunch.extract_urls
Extracts all URLs from the upstream blocks.
Returns:
- list[str] : A list of all URLs found
Example:
hunch.block
Fetches an upstream block from the input.
Parameters:
title
Optional[str] : The title of the block to fetchititle
Optional[str] : The case-insensitive title of the block to fetch
Returns:
- Block : The block.
Raises:
- Error : If the specified block is not found or if invalid arguments are provided.
Example:
Classes
class hunch.Input
Attributes
instructions
Optional[str] : The instructions on the code runner blockfiles
Optional[list[File]] : The files contained in the instructionsblocks
list[Block] : The blocks upstream of the code runner
class hunch.Block
Attributes
title
str : The title of the block.output
str : The output of the block or the content if the block is a content blockfiles
Optional[list[File]] : The files contained in the block output
Methods
extract_url(self) -> str
: Extracts the first URL from the block outputextract_urls(self) -> list[str]
: Extracts all URLs from the block output
class hunch.File
Represents a file contained in a block.
Attributes
media_type
Optional[str] : The media type of the file (e.g. “application/pdf”, “image/jpeg”)url
str : The URL to download the filepath
Optional[Path]: The path to the file, if it has been downloaded
Methods
download(self, path: str | Path) -> None
: Downloads the file to the given path and updates thepath
attribute
class hunch.Error
Raised when a hunch module specific error occurs.
Example: