Use Generative AI in Jupyter Notebook

Configure your Jupyter Notebook app for use with generative AI.

Used wisely, generative AI can bring efficiency to your daily tasks. It can increase your productivity and minimize errors and gaps. It can also help you hone your skills and work more creatively. Here are just a few of the areas in which generative AI can add significant value to the developers:

  • Ask questions about source code and get feedback.

  • Get help with coding problems.

  • Generate documentation from source code.

Before you begin:

You need access to at least one model provider. For more information on the available model providers, see the model providers documentation.

  1. 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.

  2. In your project, install the JupyterLab+GenAI 4.0 Python 3.10 app from the Saagie repository.

  3. From your project’s The "Apps" page icon is a PC screen with a star in the middle. Apps page, open your app by clicking Open The icon for external technologies is a square with an arrow pointing to the upper right corner. on the corresponding card.
    The Jupyter Notebook interface opens.

  4. In your app, load the jupyter_ai extension with the following command line:

    %load_ext jupyter_ai
  5. 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.