A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: marimo AI (#4432)
Akshay Agrawal24cc2eeb2b93
diff --git a/docs/_static/docs-ai-install.png b/docs/_static/docs-ai-install.pngnew file mode 100644index 0000000000..7ac08935f8Binary files /dev/null and b/docs/_static/docs-ai-install.png differdiff --git a/docs/_static/docs-ai-variables.png b/docs/_static/docs-ai-variables.pngnew file mode 100644index 0000000000..374680ae6aBinary files /dev/null and b/docs/_static/docs-ai-variables.png differdiff --git a/docs/getting_started/quickstart.md b/docs/getting_started/quickstart.mdindex 1db4a27880..e67e4d9b6f 100644--- a/docs/getting_started/quickstart.md+++ b/docs/getting_started/quickstart.md@@ -125,8 +125,8 @@ _Get started with Copilot_:_Note_: Copilot is not yet available in our conda distribution; please installmarimo from `PyPI` if you need Copilot.-marimo also comes with support for [other copilots](../guides/editor_features/ai_completion.md#codeium-copilot),-and a built-in [AI assistant](../guides/editor_features/ai_completion.md#generate-code-with-our-ai-assistant) that helps you write code.+marimo also comes with support for [other copilots](../guides/editor_features/ai_completion.md#custom-copilots),+and a built-in [AI assistant](../guides/editor_features/ai_completion.md) that helps you write code.## Try our VS Code extensiondiff --git a/docs/guides/editor_features/ai_completion.md b/docs/guides/editor_features/ai_completion.mdindex 5466c2894c..83b3266e5e 100644--- a/docs/guides/editor_features/ai_completion.md+++ b/docs/guides/editor_features/ai_completion.md@@ -1,103 +1,92 @@-# AI completion+# AI-assisted coding-marimo comes with GitHub Copilot, a tool that helps you write code faster by-suggesting in-line code suggestions based on the context of your current code.+marimo is an AI-native editor, with support for full-cell AI code generation:-marimo also comes with the ability to use AI for refactoring a cell, finishing writing a cell, or writing a full cell from scratch.-This feature is currently experimental and is not enabled by default.+* generating new cells from a prompt+* refactoring existing cells from a prompt+* generating entire notebooks-## GitHub Copilot+as well as inline copilots (like GitHub Copilot).-The marimo editor natively supports [GitHub Copilot](https://copilot.github.com/),-an AI pair programmer, similar to VS Code.+This guide provides an overview of these features and how to configure them.-_Get started with Copilot_:+!!! tip "Locating your marimo.toml config file"-1. Install [Node.js](https://nodejs.org/en/download).-2. Enable Copilot via the settings menu in the marimo editor.+ Various instructions in this guide refer to the marimo.toml configuration+ file. Locate this file with `marimo config show | head`.-!!! note "Installation Requirement"- Copilot is not yet available in our conda distribution; please install- marimo using ``pip`` if you need Copilot.-## Codeium Copilot+## Generating cells with AI-1. Go to the Codeium website and sign up for an account: <https://codeium.com/>-2. Install the browser extension: <https://codeium.com/chrome_tutorial>-3. Open the settings for the Chrome extension and click on "Get Token"-4. Right-click on the extension window and select "Inspect" to open the developer tools for the extension. Then click on "Network"-5. Copy the token and paste it into the input area, and then press "Enter Token"-6. This action will log a new API request in the **Network** tab. Click on "Preview" to get the API key.-7. Paste the API key in the marimo settings in the UI, or add it to your `marimo.toml` file as follows:+marimo has built-in support for generating and refactoring code with LLMs.+marimo works with hosted AI providers, such as OpenAI, Anthropic, and Google,+as well as local models served via Ollama.-```toml title="marimo.toml"-[completion]-copilot = "codeium"-codeium_api_key = ""-```+**Enabling AI code generation.** To enable AI code generation, first install+required dependencies through the notebook settings.++<div align="center">+<figure>+<img src="/_static/docs-ai-install.png" width="740px"/>+<figcaption>Install required dependencies for AI generation through the notebook settings.</figcaption>+</figure>+</div>-### Alternative: Obtain Codeium API key using VS Code+Then configure your LLM provider through the AI tab in the settings menu; see+the section on [connecting your LLM](#connecting-to-an-llm) for detailed instructions.-1. Go to the Codeium website and sign up for an account: <https://codeium.com/>-2. Install the [Codeium Visual Studio Code extension](vscode:extension/codeium.codeium) (see [here](https://codeium.com/vscode_tutorial) for complete guide)-3. Sign in to your Codeium account in the VS Code extension-4. Select the Codeium icon on the Activity bar (left side), which opens the Codeium pane-5. Select the **Settings** button (gear icon) in the top-right corner of the Codeium pane+### Variable context++marimo's AI assistant has your notebook code as context. You can additionally+pass variables and their values to the assistant by referencing them by name+with `@`. For example, to include the columns of a dataframe `df` in your+prompt, write `@df`.<div align="center">- <figure>- <img src="/_static/docs-ai-completion-codeium-vscode.png"/>- <figcaption>Open Codeium settings</figcaption>+<figure>+<img src="/_static/docs-ai-variables.png" width="740px"/>+<figcaption>Pass variables to your prompt by tagging them with `@`.</figcaption></figure></div>-6. Click the **Download** link under the **Extension Diagnostics** section-7. Open the diagnostic file and search for `apiKey`++### Refactor existing cells++Make edits to an existing cell by hitting `Ctrl/Cmd-shift-e`, which opens a prompt box+that has your cell's code as input.<div align="center">- <figure>- <img src="/_static/docs-ai-completion-codeium-vscode-download-diagnostics.png"/>- <figcaption>Download diagnostics file with API key</figcaption>- </figure>+<figure>+<video src="/_static/ai-completion.mp4" controls="controls" width="100%" height="100%"></video>+<figcaption>Use AI to modify a cell by pressing `Ctrl/Cmd-Shift-e`.</figcaption>+</figure></div>-8. Copy the value of the `apiKey` to `.marimo.toml` in your home directory-```toml title="marimo.toml"-[completion]-codeium_api_key = "a1e8..." # <-- paste your API key here-copilot = "codeium"-activate_on_typing = true-```-## Custom Copilot+### Generate new cells-marimo also supports integrating with custom LLM providers for code completion suggestions. This allows you to use your own LLM service to provide in-line code suggestions based on internal providers or local models (e.g. Ollama). You may also use OpenAI, Anthropic, or Google AI by providing your own API keys.+#### Generate with AI button-To configure a custom copilot:+At the bottom of every notebook is a button titled "Generate with AI". Click this+button to add entirely new cells to your notebook.-1. Ensure you have an LLM provider that offers API access for code completion (either external or running locally)-2. Add the following configuration to your `marimo.toml` (or configure in the UI settings):+#### Chat panel-```toml title="marimo.toml"-[completion]-copilot = "custom"-api_key = "your-llm-api-key"-model = "your-llm-model-name"-base_url = "http://127.0.0.1:11434/v1" # or https://your-llm-api-endpoint.com-```+The chat panel on the left sidebar lets you chat with an LLM and ask questions+aboutyour notebook. The LLM can also generate code cells that you can insert+into your notebook.-The configuration options include:+??? tip "See the chat panel in action"-- `api_key`: Your LLM provider's API key. This may not be required for local models, so you can set it to any random string.-- `model`: The specific model to use for completion suggestions.-- `base_url`: The endpoint URL for your LLM provider's API+ <iframe width="740" height="420" src="https://www.youtube.com/embed/4DC1E2UBwAM?si=zzrzl0VlvOU6JiZP" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>-## Generate code with our AI assistant+### Generating entire notebooks-marimo has built-in support for generating and refactoring code with AI, with a variety of providers. marimo works with hosted AI providers, such as OpenAI, Anthropic, and Google, as well as local models served via Ollama.+Generate entire notebooks with `marimo new PROMPT` at the command-line; see the+[text-to-notebook docs](../generate_with_ai/text_to_notebook.md) to learn more.-### Custom AI Rules+### Custom rulesYou can customize how the AI assistant behaves by adding rules in the marimo settings. These rules help ensure consistent code generation across all AI providers. You can find more information about marimo's supported plotting libraries and data handling in the [plotting guide](../working_with_data/plotting.md#plotting) and [working with data guide](../working_with_data/index.md).@@ -135,24 +124,22 @@ For plotting:- Set appropriate color schemes```+### Connecting to an LLM++You can connect to an LLM through the notebook settings menu, or by manually editing+your `marimo.toml` configuration file. Prefer going through the notebook settings.+To locate your configuration file, run:```bashmarimo config show```-At the top, the path to your `marimo.toml` file will be shown. You can Ctrl/Cmd+click the path to open it in your editor. For more information about configuration, see the [Configuration Guide](../configuration/index.md).--Below we describe how to connect marimo to your AI provider. Once enabled, you can generate entirely new cells by clicking the "Generate with AI" button at the bottom of your notebook. You can also refactor existing cells by inputting `Ctrl/Cmd-Shift-e` in a cell, opening an input to modify the cell using AI.+At the top, the path to your `marimo.toml` file will be shown.-<div align="center">-<figure>-<video src="/_static/ai-completion.mp4" controls="controls" width="100%" height="100%"></video>-<figcaption>Use AI to modify a cell by pressing `Ctrl/Cmd-Shift-e`.</figcaption>-</figure>-</div>+Below we describe how to connect marimo to your AI provider.-### Using OpenAI+#### OpenAI1. Install openai: `pip install openai`@@ -171,7 +158,7 @@ model = "gpt-4-turbo"base_url = "https://api.openai.com/v1"```-### Using Anthropic+#### AnthropicTo use Anthropic with marimo:@@ -187,7 +174,7 @@ model = "claude-3-7-sonnet-20250219"api_key = "sk-ant-..."```-### Using Google AI+#### Google AITo use Google AI with marimo:@@ -204,7 +191,7 @@ model = "gemini-1.5-flash"api_key = "AI..."```-### Using local models with Ollama { #using-ollama }+#### Local models with Ollama { #using-ollama }Ollama allows you to run open-source LLMs on your local machine. To integrate Ollama with marimo:@@ -248,7 +235,7 @@ model = "codellama" # or another model from `ollama ls`base_url = "http://127.0.0.1:11434/v1"```-### Using other AI providers+#### Other AI providersmarimo supports OpenAI's API by default. Many providers offer OpenAI API-compatible endpoints, which can be used by simply changing the `base_url` in your configuration. For example, providers like [GROQ](https://console.groq.com/docs/openai) and [DeepSeek](https://platform.deepseek.com) follow this pattern.@@ -277,3 +264,91 @@ marimo supports OpenAI's API by default. Many providers offer OpenAI API-compatiFor a comprehensive list of compatible providers and their configurations, please refer to the [liteLLM Providers documentation](https://litellm.vercel.app/docs/providers).For providers not compatible with OpenAI's API, please submit a [feature request](https://github.com/marimo-team/marimo/issues/new?template=feature_request.yaml) or "thumbs up" an existing one.++## Copilots+### GitHub Copilot++The marimo editor natively supports [GitHub Copilot](https://copilot.github.com/),+an AI pair programmer, similar to VS Code:++1. Install [Node.js](https://nodejs.org/en/download).+2. Enable Copilot via the settings menu in the marimo editor.++_GitHUb Copilot is not yet available in our conda distribution; please install+marimo using `pip`/`uv` if you need Copilot._++### Windsurf Copilot++Windsurf (formerly codeium) provides a free coding copilot. You can try+setting up Windsurf with the following:++1. Go to the Windsurf website and sign up for an account: <https://windsurf.com/>+2. Try the method from: <https://github.com/leona/helix-gpt/discussions/60>++Add your key to your marimo.toml file:++```toml title="marimo.toml"+[completion]+copilot = "codeium"+codeium_api_key = ""+```++For official support, please ping the Windsurf team and ask them to support marimo.++??? note "Alternative: Obtain Windsurf API key using VS Code"++ 1. Go to the Codeium website and sign up for an account: <https://codeium.com/>+ 2. Install the [Codeium Visual Studio Code extension](vscode:extension/codeium.codeium) (see [here](https://codeium.com/vscode_tutorial) for complete guide)+ 3. Sign in to your Codeium account in the VS Code extension+ 4. Select the Codeium icon on the Activity bar (left side), which opens the Codeium pane+ 5. Select the **Settings** button (gear icon) in the top-right corner of the Codeium pane++ <div align="center">+ <figure>+ <img src="/_static/docs-ai-completion-codeium-vscode.png"/>+ <figcaption>Open Codeium settings</figcaption>+ </figure>+ </div>++ 6. Click the **Download** link under the **Extension Diagnostics** section+ 7. Open the diagnostic file and search for `apiKey`++ <div align="center">+ <figure>+ <img src="/_static/docs-ai-completion-codeium-vscode-download-diagnostics.png"/>+ <figcaption>Download diagnostics file with API key</figcaption>+ </figure>+ </div>++ 8. Copy the value of the `apiKey` to `.marimo.toml` in your home directory++ ```toml title="marimo.toml"+ [completion]+ codeium_api_key = "a1e8..." # <-- paste your API key here+ copilot = "codeium"+ activate_on_typing = true+ ```++### Custom copilots++marimo also supports integrating with custom LLM providers for code completion suggestions. This allows you to use your own LLM service to provide in-line code suggestions based on internal providers or local models (e.g. Ollama). You may also use OpenAI, Anthropic, or Google AI by providing your own API keys.++To configure a custom copilot:++1. Ensure you have an LLM provider that offers API access for code completion (either external or running locally)+2. Add the following configuration to your `marimo.toml` (or configure in the UI settings):++```toml title="marimo.toml"+[completion]+copilot = "custom"+api_key = "your-llm-api-key"+model = "your-llm-model-name"+base_url = "http://127.0.0.1:11434/v1" # or https://your-llm-api-endpoint.com+```++The configuration options include:++- `api_key`: Your LLM provider's API key. This may not be required for local models, so you can set it to any random string.+- `model`: The specific model to use for completion suggestions.+- `base_url`: The endpoint URL for your LLM provider's API+diff --git a/docs/guides/generate_with_ai/index.md b/docs/guides/generate_with_ai/index.mdnew file mode 100644index 0000000000..560ea74d23--- /dev/null+++ b/docs/guides/generate_with_ai/index.md@@ -0,0 +1,6 @@+# Generate notebooks with AI++| Guide | Description |+|-------|-------------|+| [Zero-shot entire notebooks](text_to_notebook.md) | Generate entire notebooks with AI |+| [AI-assisted coding](../editor_features/ai_completion.md) | Refactor code and generate cells with AI|diff --git a/docs/guides/generate_with_ai/text_to_notebook.md b/docs/guides/generate_with_ai/text_to_notebook.mdnew file mode 100644index 0000000000..945f7d5f60--- /dev/null+++ b/docs/guides/generate_with_ai/text_to_notebook.md@@ -0,0 +1,27 @@+# Generate entire notebooks with AI++Use [`marimo new`](../../cli.md#marimo-new) at the command line to generate entirely new+notebooks using an LLM.++For example, type++```bash+marimo new "Plot an interactive 3D surface with matplotlib."+```++to open a freshly generated notebook in your browser.++For long prompts, you can pass a text file instead:++```bash+marimo new my_prompt.txt+```++marimo's AI knows how to use marimo-specific UI elements and popular libraries+for working with data. To get inspired, visit <https://marimo.app/ai>. Some of+our favorites:++- [Dimensionality reduction](https://marimo.app/ai?q=Show+me+how+to+visualize+handwritten+digits+in+two+dimensions%2C+using+an+Altair+scatterplot.+Include+a+cell+that+shows+the+chart+value.+Make+the+chart+render+as+a+square.)+- [Smooth a time series](https://marimo.app/ai?q=Show+me+how+to+smooth+time+series+data+and+plot+it.+Use+a+well-known+stock+dataset+and+make+it+interactive)+- [Compute code complexity](https://marimo.app/ai?q=Build+a+tool+that+analyzes+Python+code+complexity+metrics+like+cyclomatic+complexity.+Let+me+input+code+snippets+and+see+visualizations+of+the+results.)+- [Visualize sorting algorithms](https://marimo.app/ai?q=Plot+an+interesting+3D+surface+with+matplotlib.+Include+an+interactive+element+to+control+the+shape+of+the+surface.)diff --git a/docs/guides/index.md b/docs/guides/index.mdindex 9660502ce8..50eea9c1c8 100644--- a/docs/guides/index.md+++ b/docs/guides/index.md@@ -17,6 +17,7 @@ These guides cover marimo's core concepts.| [Understanding errors](understanding_errors/index.md) | Understanding marimo's constraints on notebook code || [Working with data](working_with_data/index.md) | Using SQL cells, no-code dataframe, and reactive plots || [Package reproducibility](package_reproducibility.md) | Making notebooks reproducible down to the packages |+| [Generate with AI](generate_with_ai/index.md) | Generate notebooks with AI || [Editor features](editor_features/index.md) | View variables, dataframe schemas, docstrings, and more || [Using your own editor](editor_features/watching.md) | Edit notebooks in your own editor and stream changes back to the browser || [Apps](apps.md) | Running notebooks as apps |diff --git a/mkdocs.yml b/mkdocs.ymlindex 85caeda362..0b52047229 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -98,6 +98,10 @@ nav:- SQL: guides/working_with_data/sql.md- Plotting: guides/working_with_data/plotting.md- Package reproducibility: guides/package_reproducibility.md+ - Generate with AI:+ - Generate with AI: guides/generate_with_ai/index.md+ - Generate entire notebooks: guides/generate_with_ai/text_to_notebook.md+ - AI-assisted coding: guides/editor_features/ai_completion.md- Editor features:- Editor features: guides/editor_features/index.md- Editor overview: guides/editor_features/overview.md