Generative Artificial Intelligence for Jupyter Notebooks with Magic Commands

Jupyter AI, an official subproject of Project Jupyter, brings generative artificial intelligence to Jupyter notebooks. It allows users to explain and generate code, fix errors, summarize content, and even generate entire notebooks from natural language prompts. The tool connects Jupyter with large language models (LLMs) from various providers, including AI21, Anthropic, AWS, Cohere, and OpenAI, supported by LangChain.

Designed with responsible AI and data privacy in mind, Jupyter AI empowers users to choose their preferred LLM, embedding model, and vector database to suit their specific needs. The software’s underlying prompts, chains, and components are open source, ensuring data transparency. Moreover, it saves metadata about model-generated content, facilitating tracking of AI-generated code within the workflow. Importantly, Jupyter AI respects user data privacy and only contacts LLMs when requested, never reading or transmitting data without explicit consent.

To start using Jupyter AI, users can install the appropriate version for their JupyterLab (version 3 or 4) using pip. The software provides two interfaces for interacting with LLMs: a chat UI within JupyterLab and a magic command interface for supported notebook environments. Jupyter Naut, the AI assistant within the chat interface, communicates through text and offers a wide range of capabilities. It can answer general questions, explain code in plain English or other languages, modify code, and identify errors. Additionally, users can generate entire notebooks from text prompts using the “/generate” command.

The chat interface allows users to teach Jupyternaut about local files using the “/learn” command. Jupyternaut employs an embedding model to convert data and store it in a local vector database, enabling users to ask questions about these files using the “/ask” command. The AI then responds based on the stored information.

In notebook environments, users can utilize magic commands like “%%ai” to interact with LLMs. The software supports multiple providers, and users can customize the output format using the “–format” parameter. Furthermore, variable interpolation enables dynamic interactions with AI models.

Jupyter AI is a valuable tool for AI-driven code generation and assistance in Jupyter notebooks with a focus on ethical considerations, privacy, and data transparency. Users are encouraged to review AI-generated code before execution, following the same practices as human-written code. In conclusion, Jupyter AI is a powerful and ethical addition to Project Jupyter, offering AI-driven code generation, assistance, and explanations while maintaining data privacy and responsible AI practices.