Use Generative AI in Jupyter Notebook
You need access to at least one model provider. For more information on the available model providers, see the model providers documentation.
-
In Saagie, create the
$OPENAI_API_KEY
environment variable at the project level. It must contain your API key for the model provider you want to use. -
In your project, install the
JupyterLab+GenAI 4.0 Python 3.10
app from the Saagie repository. -
From your project’s Apps page, open your app by clicking Open image:0-reuse:icons-svg on the corresponding card.
The Jupyter Notebook interface opens. -
In your app, load the
jupyter_ai
extension with the following command line:%load_ext jupyter_ai
-
Make your request to the generative AI using the
%%ai
magic command or the chat interface.Example 1. Request a Python program with ChatGPT%%ai chatgpt Write a Python program that implements the quicksort algorithm in a function and uses it to sort a list of 100 random integers. Show the list before and after sorting.
For more information on supported language model providers, see Choosing a provider and model.