OpenAI Python SDK
Code execution for OpenAI in Python
Get your Freestyle API Key from the Freestyle Dashboard
Set up the Code Executor
The simplest code executor looks like this:
Adding Node Modules
When you want your AI code execution to have access to specific node modules, you can pass them in through the configuration parameter:
Adding Environment Variables
You can also pass in environment variables that your AI code execution will have access to:
Other Configuration Options
- timeout: The maximum time in seconds that the code execution is allowed to run.
- networkPermissions: A list of URLs that the code execution is allowed to access.
- peerDependencyResolution: Configure if peer dependencies should be resolved — do not use this unless you know what you are doing.
Set up the OpenAI Python SDK
The
definition
and runner
variables are from the code executor setup. The definition
is an OpenAI compatible tool definition, and the runner
is a function that takes in an OpenAI Compatible Model response and returns the output of the code execution if there is one. Runner
is made to be called on every response from the OpenAI model, if there is no code execution then it returns None
and does nothing.