CodeInterpreterSession
The CodeInterpreterSession is the main class that manages a conversational session between the user and AI agent. It handles starting, stopping and checking status of the secure isolated code execution environment.
Key responsibilities:
- Starting and stopping the compute session
- Sending user input and files to the agent
- Running code in the compute container
- Retrieving output files and images
- Managing the chat history
- Logging
It provides methods like:
generate_response()
: Generate AI response for user inputstart() / stop()
: Start and stop the sessionlog()
: Log messagesshow_code
- Callback to print code before running.
The response generation happens through a pipeline:
- User input is parsed
- Code is executed if needed
- Files are processed if needed
- Final response is formatted and returned
The generate_response()
method handles this entire pipeline.
Usage:
from codeinterpreterapi import CodeInterpreterSession
with CodeInterpreterSession() as session:
response = session.generate_response("Plot a histogram of the data")
print(response.content) # print AI response