Expand assistant docs (#16501)

This PR significantly expands the assistant documentation, breaking it
out into sections, adding examples and further documenting features.

This PR introduces a convention in docs for swapping keybindings for mac
vs linux:

`<kbd>cmd-enter|ctrl-enter</kbd>`

In the above example, the first will be shown for mac, the second for
linux or windows.

TODO:

- [ ] Fix table style (for `/assistant/configuration`)
- [x] Add script to swap keybindings based on platform
- It should take in this format: [`cmd-n` (mac)|`ctrl-n`(linux)] and
return just the correct binding for the viewer's platform.
- [ ] Add image/video assets (non-blocking)

Release Notes:

- Updated assistant documentation
This commit is contained in:
Nate Butler 2024-08-19 23:50:09 -04:00 committed by GitHub
parent 395a68133d
commit 1f0dc8b754
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 715 additions and 294 deletions

View file

@ -9,8 +9,8 @@ site-url = "/docs/"
[output.html]
no-section-label = true
preferred-dark-theme = "light"
additional-css = ["theme/page-toc.css"]
additional-js = ["theme/page-toc.js"]
additional-css = ["theme/page-toc.css", "theme/plugins.css"]
additional-js = ["theme/page-toc.js", "theme/plugins.js"]
[output.html.print]
enable = false

View file

@ -22,7 +22,6 @@
# Using Zed
- [Multibuffers](./multibuffers.md)
- [Assistant](./assistant.md)
- [Code Completions](./completions.md)
- [Channels](./channels.md)
- [Collaboration](./collaboration.md)
@ -31,6 +30,16 @@
- [Remote Development](./remote-development.md)
- [REPL](./repl.md)
# Assistant
- [Assistant](./assistant/assistant.md)
- [Configuration](./assistant/configuration.md)
- [Assistant Panel](./assistant/assistant-panel.md)
- [Contexts](./assistant/contexts.md)
- [Inline Assistant](./assistant/inline-assistant.md)
- [Commands](./assistant/commands.md)
- [Prompts](./assistant/prompting.md)
# Extensions
- [Overview](./extensions.md)

View file

@ -1,291 +1 @@
# Assistant
## Assistant Panel
The assistant panel provides you with a way to interact with large language models. The assistant is useful for various tasks, such as generating code, asking questions about existing code, and even writing plaintext, such as emails and documentation. To open the assistant panel, toggle the right dock by using the `workspace: toggle right dock` action in the command palette or by using the `cmd-r` (Mac) or `ctrl-alt-b` (Linux) shortcut.
> **Note**: A custom [key binding](./key-bindings.md) can be set to toggle the right dock.
Once you have configured a provider, you can interact with the provider's language models in a context editor.
To create a new context editor, use the menu in the top right of the assistant panel and select the `New Context` option.
In the context editor, select a model from one of the configured providers, type a message in the `You` block, and submit with `cmd-enter` (or `ctrl-enter` on Linux).
## Setup
- [OpenAI API Setup Instructions](#openai)
- [OpenAI API Custom Endpoint](#openai-custom-endpoint)
- [Ollama Setup Instructions](#ollama)
- [Anthropic API Setup Instructions](#anthropic)
- [Google Gemini API Setup Instructions](#google-gemini)
- [GitHub Copilot Chat](#github-copilot)
### Having a Conversation
The assistant editor in Zed functions similarly to any other editor. You can use custom key bindings and work with multiple cursors, allowing for seamless transitions between coding and engaging in discussions with the language models. However, the assistant editor differs with the inclusion of message blocks. These blocks serve as containers for text that correspond to different roles within the conversation. These roles include:
- `You`
- `Assistant`
- `System`
To begin, select a model and type a message in a `You` block.
![Asking a question](https://zed.dev/img/assistant/ask-a-question.png)
As you type, the remaining tokens count for the selected model is updated.
Inserting text from an editor is as simple as highlighting the text and running `cmd->` (`assistant: quote selection`); Zed will wrap it in a fenced code block if it is code.
![Quoting a selection](https://zed.dev/img/assistant/quoting-a-selection.png)
To submit a message, use `cmd-enter` (`assistant: assist`). Unlike typical chat applications where pressing `enter` would submit the message, in the assistant editor, our goal was to make it feel as close to a regular editor as possible. So, pressing `enter` simply inserts a new line.
After submitting a message, the assistant's response will be streamed below, in an `Assistant` message block.
![Receiving an answer](https://zed.dev/img/assistant/receiving-an-answer.png)
The stream can be canceled at any point with `escape`. This is useful if you realize early on that the response is not what you were looking for.
If you want to start a new conversation at any time, you can hit `cmd-n` or use the `New Context` menu option in the hamburger menu at the top left of the panel.
Simple back-and-forth conversations work well with the assistant. However, there may come a time when you want to modify the previous text in the conversation and steer it in a different direction.
### Editing a Conversation
The assistant gives you the flexibility to have control over the conversation. You can freely edit any previous text, including the responses from the assistant. If you want to remove a message block entirely, simply place your cursor at the beginning of the block and use the `delete` key. A typical workflow might involve making edits and adjustments throughout the conversation to refine your inquiry or provide additional context. Here's an example:
1. Write text in a `You` block.
2. Submit the message with `cmd-enter`.
3. Receive an `Assistant` response that doesn't meet your expectations.
4. Cancel the response with `escape`.
5. Erase the content of the `Assistant` message block and remove the block entirely.
6. Add additional context to your original message.
7. Submit the message with `cmd-enter`.
Being able to edit previous messages gives you control over how tokens are used. You don't need to start up a new context to correct a mistake or to add additional context, and you don't have to waste tokens by submitting follow-up corrections.
Some additional points to keep in mind:
- You are free to change the model type at any point in the conversation.
- You can cycle the role of a message block by clicking on the role, which is useful when you receive a response in an `Assistant` block that you want to edit and send back up as a `You` block.
### Saving and Loading Conversations
After you submit your first message, a name for your conversation is generated by the language model, and the conversation is automatically saved to your file system in `~/.config/zed/conversations`. You can access and load previous messages by clicking on the hamburger button in the top-left corner of the assistant panel.
![Viewing assistant history](https://zed.dev/img/assistant/assistant-history.png)
### Adding Prompts
You can customize the default prompts used in new context editors by opening the `Prompt Library`.
Open the `Prompt Library` using either the menu in the top right of the assistant panel and choosing the `Prompt Library` option, or by using the `assistant: deploy prompt library` command when the assistant panel is focused.
### Viewing Past Contexts
You can view all previous contexts by opening the `History` tab in the assistant panel.
Open the `History` using the menu in the top right of the assistant panel and choosing `History`.
### Slash Commands
Slash commands enhance the assistant's capabilities. Begin by typing a `/` at the beginning of the line to see a list of available commands:
- `/default`: Inserts the default prompt into the context
- `/diagnostics`: Injects errors reported by the project's language server into the context
- `/fetch`: Inserts the content of a webpage and inserts it into the context
- `/file`: Inserts a single file or a directory of files into the context
- `/now`: Inserts the current date and time into the context
- `/prompt`: Adds a custom-configured prompt to the context (see Prompt Library)
- `/search`: Performs semantic search for content in your project based on natural language
- `/symbols`: Inserts the current tab's active symbols into the context
- `/tab`: Inserts the content of the active tab or all open tabs into the context
- `/terminal`: Inserts a select number of lines of output from the terminal
## Inline Assistant
You can use `ctrl-enter` to open the inline assistant in both a normal editor, within the assistant panel, and even within the terminal panel.
The inline assistant allows you to send the current selection (or the current line) to a language model and modify the selection with the language model's response. You can also perform multiple generation requests in parallel by pressing `ctrl-enter` with multiple cursors, or by pressing `ctrl-enter` with a selection that spans multiple excerpts in a multibuffer.
The inline assistant pulls its context from the assistant panel, allowing you to provide additional instructions or rules for code transformations.
To create a custom keybinding that prefills a prompt, you can add the following format in your keymap:
```json
[
{
"context": "Editor && mode == full",
"bindings": {
"ctrl-shift-enter": [
"assistant::InlineAssist",
{ "prompt": "Build a snake game" }
]
}
}
]
```
## Advanced: Overriding Prompt Templates
Zed allows you to override the default prompts used for various assistant features by placing custom Handlebars (.hbs) templates in your `~/.config/zed/prompts/templates` directory. The following templates can be overridden:
1. `content_prompt.hbs`: Used for generating content in the editor.
Format:
```handlebars
You are an AI programming assistant. Your task is to
{{#if is_insert}}insert{{else}}rewrite{{/if}}
{{content_type}}{{#if language_name}} in {{language_name}}{{/if}}
based on the following context and user request. Context:
{{#if is_truncated}}
[Content truncated...]
{{/if}}
{{document_content}}
{{#if is_truncated}}
[Content truncated...]
{{/if}}
User request:
{{user_prompt}}
{{#if rewrite_section}}
Please rewrite the section enclosed in
<rewrite_this></rewrite_this>
tags.
{{else}}
Please insert your response at the
<insert_here></insert_here>
tag.
{{/if}}
Provide only the
{{content_type}}
content in your response, without any additional explanation.
```
2. `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
Format:
```handlebars
You are an AI assistant for a terminal emulator. Provide helpful responses to
user queries about terminal commands, file systems, and general computer
usage. System information: - Operating System:
{{os}}
- Architecture:
{{arch}}
{{#if shell}}
- Shell:
{{shell}}
{{/if}}
{{#if working_directory}}
- Current Working Directory:
{{working_directory}}
{{/if}}
Latest terminal output:
{{#each latest_output}}
{{this}}
{{/each}}
User query:
{{user_prompt}}
Provide a clear and concise response to the user's query, considering the
given system information and latest terminal output if relevant.
```
3. `edit_workflow.hbs`: Used for generating the edit workflow prompt.
4. `step_resolution.hbs`: Used for generating the step resolution prompt.
You can customize these templates to better suit your needs while maintaining the core structure and variables used by Zed. Zed will automatically reload your prompt overrides when they change on disk. Consult Zed's assets/prompts directory for current versions you can play with.
Be sure you want to override these, as you'll miss out on iteration on our built-in features. This should be primarily used when developing Zed.
## Setup Instructions
### OpenAI
<!--
TBD: OpenAI Setup flow: Review/Correct/Simplify
-->
1. Create an [OpenAI API key](https://platform.openai.com/account/api-keys)
2. Make sure that your OpenAI account has credits
3. Open the assistant panel, using either the `assistant: toggle focus` or the `workspace: toggle right dock` action in the command palette (`cmd-shift-p`).
4. Make sure the assistant panel is focused:
![The focused assistant panel](https://zed.dev/img/assistant/assistant-focused.png)
The OpenAI API key will be saved in your keychain.
Zed will also use the `OPENAI_API_KEY` environment variable if it's defined.
#### OpenAI Custom Endpoint
You can use a custom API endpoint for OpenAI, as long as it's compatible with the OpenAI API structure.
To do so, add the following to your Zed `settings.json`:
```json
{
"language_models": {
"openai": {
"api_url": "http://localhost:11434/v1"
}
}
}
```
The custom URL here is `http://localhost:11434/v1`.
### Ollama
Download and install Ollama from [ollama.com/download](https://ollama.com/download) (Linux or macOS) and ensure it's running with `ollama --version`.
You can use Ollama with the Zed assistant by making Ollama appear as an OpenAPI endpoint.
1. Download, for example, the `mistral` model with Ollama:
```sh
ollama pull mistral
```
2. Make sure that the Ollama server is running. You can start it either via running the Ollama app, or launching:
```sh
ollama serve
```
3. In the assistant panel, select one of the Ollama models using the model dropdown.
4. (Optional) If you want to change the default URL that is used to access the Ollama server, you can do so by adding the following settings:
```json
{
"language_models": {
"ollama": {
"api_url": "http://localhost:11434"
}
}
}
```
### Anthropic
You can use Claude 3.5 Sonnet with the Zed assistant by choosing it via the model dropdown in the assistant panel.
You can obtain an API key [here](https://console.anthropic.com/settings/keys).
Even if you pay for Claude Pro, you will still have to [pay for additional credits](https://console.anthropic.com/settings/plans) to use it via the API.
### Google Gemini
You can use Gemini 1.5 Pro/Flash with the Zed assistant by choosing it via the model dropdown in the assistant panel.
You can obtain an API key [here](https://aistudio.google.com/app/apikey).
### GitHub Copilot Chat
You can use GitHub Copilot chat with the Zed assistant by choosing it via the model dropdown in the assistant panel.

View file

@ -0,0 +1,70 @@
# Assistant Panel
The assistant panel provides you with a way to interact with large language models. The assistant is useful for various tasks, such as generating code, asking questions about existing code, and even writing plaintext, such as emails and documentation.
To open the assistant panel, toggle the right dock by using the `workspace: toggle right dock` action in the command palette or by using the <kbd>cmd-r|ctrl-alt-b</kbd> shortcut.
> **Note**: A custom [key binding](./key-bindings.md) can be set to toggle the right dock.
Once you have [configured a provider](/assistant/configuration.md#providers), you can interact with the provider's language models in a context editor.
![](https://private-user-images.githubusercontent.com/1714999/359287532-abd8f918-e65f-44ce-a853-1e90f852e206.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxMDk2OTIsIm5iZiI6MTcyNDEwOTM5MiwicGF0aCI6Ii8xNzE0OTk5LzM1OTI4NzUzMi1hYmQ4ZjkxOC1lNjVmLTQ0Y2UtYTg1My0xZTkwZjg1MmUyMDYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTlUMjMxNjMyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDhlMjZhMjI0NjM3M2JiZmEzMWU5ZWIwYWRjZjhkNTI3NTkyM2JlNmNjODcyMjg3YjkxNjIxNmI5ZTk1ZWRjZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.NiiQkF65VvBKCJs_zNxmjpyvKGK6Hw1aIWA3Xc87XRs)
To create a new context editor, press <kbd>cmd-n|ctrl-n</kbd> or use the menu in the top right of the assistant panel and select the `New Context` option.
In the context editor, select a model from one of the configured providers, type a message in the `You` block, and submit with <kbd>cmd-enter|ctrl-enter</kbd>.
### Interacting with the Assistant
The context editor in Zed functions similarly to any other editor. You can use custom key bindings and work with multiple cursors, allowing for seamless transitions between coding and engaging in discussions with the language models.
However, the assistant editor differs with the inclusion of message blocks. These blocks serve as containers for text that correspond to different roles within the context. These roles include:
- `You`
- `Assistant`
- `System`
To begin, select a model and type a message in a `You` block.
![Asking a question](https://zed.dev/img/assistant/ask-a-question.png)
As you type, the remaining tokens count for the selected model is updated.
Inserting text from an editor is as simple as highlighting the text and running `assistant: quote selection` (<kbd>cmd+shift+>|ctrl+shift+></kbd>); Zed will wrap it in a fenced code block if it is code.
![Quoting a selection](https://zed.dev/img/assistant/quoting-a-selection.png)
To submit a message, use <kbd>cmd-enter|ctrl-enter</kbd> (`assistant: assist`). Unlike typical chat applications where pressing <kbd>enter</kbd> would submit the message, in the assistant editor, our goal was to make it feel as close to a regular editor as possible. So, pressing <kbd>enter</kbd> simply inserts a new line.
After submitting a message, the assistant's response will be streamed below, in an `Assistant` message block.
![Receiving an answer](https://zed.dev/img/assistant/receiving-an-answer.png)
The stream can be canceled at any point with <kbd>escape</kbd>. This is useful if you realize early on that the response is not what you were looking for.
If you want to start a new conversation at any time, you can hit <kbd>cmd-n|ctrl-n</kbd> or use the `New Context` menu option in the hamburger menu at the top left of the panel.
Simple back-and-forth conversations work well with the assistant. However, there may come a time when you want to modify the previous text in the conversation and steer it in a different direction.
### Editing a Context
> **Note**: Wondering about Context vs Conversation? [Read more here](/assistant/contexts.md).
The assistant gives you the flexibility to have control over the context. You can freely edit any previous text, including the responses from the assistant. If you want to remove a message block entirely, simply place your cursor at the beginning of the block and use the `delete` key. A typical workflow might involve making edits and adjustments throughout the context to refine your inquiry or provide additional information. Here's an example:
1. Write text in a `You` block.
2. Submit the message with <kbd>cmd-enter|ctrl-enter</kbd>.
3. Receive an `Assistant` response that doesn't meet your expectations.
4. Cancel the response with <kbd>escape</kbd>.
5. Erase the content of the `Assistant` message block and remove the block entirely.
6. Add additional context to your original message.
7. Submit the message with <kbd>cmd-enter|ctrl-enter</kbd>.
Being able to edit previous messages gives you control over how tokens are used. You don't need to start up a new context to correct a mistake or to add additional information, and you don't have to waste tokens by submitting follow-up corrections.
> **Note**: The act of editing past messages is often referred to as "Rewriting History" in the context of the language models.
Some additional points to keep in mind:
- You are free to change the model type at any point in the conversation.
- You can cycle the role of a message block by clicking on the role, which is useful when you receive a response in an `Assistant` block that you want to edit and send back up as a `You` block.

View file

@ -0,0 +1,17 @@
# Assistant
The Assistant is a powerful tool that integrates large language models into your development workflow.
This section covers various aspects of the Assistant:
- [Assistant Panel](/assistant/assistant-panel.md): Create and collaboratively edit new contexts, and manage interactions with language models.
- [Inline Assistant](/assistant/inline-assistant.md): Discover how to use the Assistant to power inline transformations directly within your code editor and terminal.
- [Providers & Configuration](/assistant/configuration.md): Configure the Assistant, and set up different language model providers like Anthropic, OpenAI, Ollama, Google Gemini, and GitHub Copilot Chat.
- [Introducing Contexts](/assistant/contexts.md): Learn about contexts (similar to conversations), and learn how they power your interactions between you, your project, and the assistant/model.
- [Using Commands](/assistant/commands.md): Explore slash commands that enhance the Assistant's capabilities and future extensibility.
- [Prompting & Prompt Library](/assistant/prompting.md): Learn how to write and save prompts, how to use the Prompt Library, and how to edit prompt templates.

View file

@ -0,0 +1,117 @@
# Assistant Commands
## Overview
Slash commands enhance the assistant's capabilities. Begin by typing a `/` at the beginning of the line to see a list of available commands:
- `/default`: Inserts the default prompt into the context
- `/diagnostics`: Injects errors reported by the project's language server into the context
- `/fetch`: Inserts the content of a webpage and inserts it into the context
- `/file`: Inserts a single file or a directory of files into the context
- `/now`: Inserts the current date and time into the context
- `/prompt`: Adds a custom-configured prompt to the context (see Prompt Library)
- `/symbols`: Inserts the current tab's active symbols into the context
- `/tab`: Inserts the content of the active tab or all open tabs into the context
- `/terminal`: Inserts a select number of lines of output from the terminal
### Other Commands:
- `/search`: Performs semantic search for content in your project based on natural language
- Not generally available yet, but some users may have access to it.
- `/workflow`: Opts into the edit workflow for a specific context
- Not generally available yet.
> **Note:** Remember, commands are only evaluated when the context is created or when the command is inserted, so a command like `/now` won't continuously update, or `/file` commands won't keep their contents up to date.
## `/default`
Read more about `/default` in the [Prompting: Editing the Default Prompt](/assistant/prompting.md#default-prompt) section.
Usage: `/default`
## `/diagnostics`
The `/diagnostics` command injects errors reported by the project's language server into the context. This is useful for getting an overview of current issues in your project.
Usage: `/diagnostics [--include-warnings] [path]`
- `--include-warnings`: Optional flag to include warnings in addition to errors.
- `path`: Optional path to limit diagnostics to a specific file or directory.
## `/file`
The `/file` command inserts the content of a single file or a directory of files into the context. This allows you to reference specific parts of your project in your conversation with the assistant.
Usage: `/file <path>`
You can use glob patterns to match multiple files or directories.
Examples:
- `/file src/index.js` - Inserts the content of `src/index.js` into the context.
- `/file src/*.js` - Inserts the content of all `.js` files in the `src` directory.
- `/file src` - Inserts the content of all files in the `src` directory.
## `/now`
The `/now` command inserts the current date and time into the context. This can be useful letting the language model know the current time (and by extension, how old their current knowledge base is).
Usage: `/now`
## `/prompt`
The `/prompt` command inserts a prompt from the prompt library into the context. It can also be used to nest prompts within prompts.
Usage: `/prompt <prompt_name>`
Related: `/default`
## `/search` (Not generally available)
The `/search` command performs a semantic search for content in your project based on natural language queries. This allows you to find relevant code or documentation within your project.
Usage: `/search <query> [--n <limit>]`
- `query`: The natural language query to search for.
- `--n <limit>`: Optional flag to limit the number of results returned.
## `/symbols`
The `/symbols` command inserts the active symbols (functions, classes, etc.) from the current tab into the context. This is useful for getting an overview of the structure of the current file.
Usage: `/symbols`
## `/tab`
The `/tab` command inserts the content of the active tab or all open tabs into the context. This allows you to reference the content you're currently working on.
Usage: `/tab [tab_name|all]`
- `tab_name`: Optional name of a specific tab to insert.
- `all`: Insert content from all open tabs.
Examples:
- `/tab` - Inserts the content of the active tab.
- `/tab "index.js"` - Inserts the content of the tab named "index.js".
- `/tab all` - Inserts the content of all open tabs.
## `/terminal`
The `/terminal` command inserts a select number of lines of output from the terminal into the context. This is useful for referencing recent command outputs or logs.
Usage: `/terminal [--line-count <number>]`
- `--line-count <number>`: Optional flag to specify the number of lines to insert (default is a predefined number).
## `/workflow` (Not generally available)
The `/workflow` command inserts a prompt that opts into the edit workflow. This sets up the context for the assistant to suggest edits to your code.
Usage: `/workflow`
## Extensibility
The Zed team plans for assistant commands to be extensible, but this isn't quite ready yet. Stay tuned!
Zed is open source, and all the slash commands are defined in the [assistant crate](https://github.com/zed-industries/zed/tree/main/crates/assistant/src/slash_command). If you are interested in creating your own slash commands a good place to start is by learning from the existing commands.

View file

@ -0,0 +1,153 @@
# Configuring the Assistant
## Settings
| key | type | default | description |
| ------------- | ------ | ------- | ----------------------------- |
| version | string | "2" | The version of the assistant. |
| default_model | object | {} | The default model to use. |
### Configuring the default model
The `default_model` object can contain the following keys:
```json
// settings.json
{
"assistant": {
"default_model": {
"provider": "zed.dev",
"model": "claude-3-5-sonnet"
}
}
}
```
## Common Panel Settings
| key | type | default | description |
| -------------- | ------- | ------- | ------------------------------------------------------------------------------------- |
| enabled | boolean | true | Disabling this will completely disable the assistant |
| button | boolean | true | Show the assistant icon |
| dock | string | "right" | The default dock position for the assistant panel. Can be ["left", "right", "bottom"] |
| default_height | string | null | The pixel height of the assistant panel when docked to the bottom |
| default_width | string | null | The pixel width of the assistant panel when docked to the left or right |
## Example Configuration
```json
// settings.json
{
"assistant": {
"default_model": {
"provider": "zed.dev",
"model": "claude-3-5-sonnet-20240620"
},
"version": "2",
"button": true,
"default_width": 480,
"dock": "right",
"enabled": true
}
}
```
## Providers {#providers}
The following providers are supported:
- Zed AI (Configured by default when signed in)
- [Anthropic](#anthropic)
- [GitHub Copilot Chat](#github-copilot-chat)
- [Google Gemini](#google-gemini)
- [Ollama](#ollama)
- [OpenAI](#openai)
- [OpenAI Custom Endpoint](#openai-custom-endpoint)
### Zed AI {#zed-ai}
A hosted service providing convenient and performant support for AI-enabled coding in Zed, powered by Anthropic's Claude 3.5 Sonnet and accessible just by signing in.
### Anthropic {#anthropic}
You can use Claude 3.5 Sonnet via [Zed AI](#zed-ai) for free. To use other Anthropic models you will need to configure it by providing your own API key.
You can obtain an API key [here](https://console.anthropic.com/settings/keys).
Even if you pay for Claude Pro, you will still have to [pay for additional credits](https://console.anthropic.com/settings/plans) to use it via the API.
### GitHub Copilot Chat {#github-copilot-chat}
You can use GitHub Copilot chat with the Zed assistant by choosing it via the model dropdown in the assistant panel.
### Google Gemini {#google-gemini}
You can use Gemini 1.5 Pro/Flash with the Zed assistant by choosing it via the model dropdown in the assistant panel.
You can obtain an API key [here](https://aistudio.google.com/app/apikey).
### Ollama {#ollama}
Download and install Ollama from [ollama.com/download](https://ollama.com/download) (Linux or macOS) and ensure it's running with `ollama --version`.
You can use Ollama with the Zed assistant by making Ollama appear as an OpenAPI endpoint.
1. Download, for example, the `mistral` model with Ollama:
```sh
ollama pull mistral
```
2. Make sure that the Ollama server is running. You can start it either via running the Ollama app, or launching:
```sh
ollama serve
```
3. In the assistant panel, select one of the Ollama models using the model dropdown.
4. (Optional) If you want to change the default URL that is used to access the Ollama server, you can do so by adding the following settings:
```json
{
"language_models": {
"ollama": {
"api_url": "http://localhost:11434"
}
}
}
```
### OpenAI {#openai}
<!--
TBD: OpenAI Setup flow: Review/Correct/Simplify
-->
1. Create an [OpenAI API key](https://platform.openai.com/account/api-keys)
2. Make sure that your OpenAI account has credits
3. Open the assistant panel, using either the `assistant: toggle focus` or the `workspace: toggle right dock` action in the command palette (`cmd-shift-p`).
4. Make sure the assistant panel is focused:
![The focused assistant panel](https://zed.dev/img/assistant/assistant-focused.png)
The OpenAI API key will be saved in your keychain.
Zed will also use the `OPENAI_API_KEY` environment variable if it's defined.
#### OpenAI Custom Endpoint {#openai-custom-endpoint}
You can use a custom API endpoint for OpenAI, as long as it's compatible with the OpenAI API structure.
To do so, add the following to your Zed `settings.json`:
```json
{
"language_models": {
"openai": {
"api_url": "http://localhost:11434/v1"
}
}
}
```
The custom URL here is `http://localhost:11434/v1`.

View file

@ -0,0 +1,17 @@
# Introducing Contexts
Contexts are like conversations in most assistant-like tools. A context is a collaborative tool for sharing information between you, your project, and the assistant/model.
The model can reference content from your active context in the assistant panel, but also elsewhere like the inline assistant.
### Saving and Loading Contexts
After you submit your first message, a name for your context is generated by the language model, and the context is automatically saved to your file system in `~/.config/zed/contexts`. You can access and load previous contexts by clicking on the hamburger button in the top-left corner of the assistant panel.
![Viewing assistant history](https://zed.dev/img/assistant/assistant-history.png)
### Viewing Past Contexts
You can view all previous contexts by opening the `History` tab in the assistant panel.
Open the `History` using the menu in the top right of the assistant panel and choosing `History`.

View file

@ -0,0 +1,44 @@
# Inline Assistant
## Using the Inline Assistant
You can use `ctrl-enter` to open the inline assistant nearly anywhere you can enter text: Editors, the assistant panel, the prompt library, channel notes, and even within the terminal panel.
The inline assistant allows you to send the current selection (or the current line) to a language model and modify the selection with the language model's response.
You can also perform multiple generation requests in parallel by pressing `ctrl-enter` with multiple cursors, or by pressing `ctrl-enter` with a selection that spans multiple excerpts in a multibuffer.
The inline assistant pulls its context from the assistant panel, allowing you to provide additional instructions or rules for code transformations.
> **Note**: The inline assistant sees the entire active context from the assistant panel. This means the assistant panel's context editor becomes one of the most powerful tools for shaping the results of the inline assistant.
## Using Prompts & Commands
While you can't directly use slash commands (and by extension, the `/prompt` command to include prompts) in the inline assistant, you can use them in the active context in the assistant panel.
A common workflow when using the inline assistant is to create a context in the assistant panel, add the desired context through text, prompts and commands, and then use the inline assistant to generate and apply transformations.
### Example Recipe - Fixing Errors with the Inline Assistant
1. Create a new context in the assistant panel.
2. Use the `/diagnostic` command to add current diagnostics to the context.
3. OR use the `/terminal` command to add the current terminal output to the context (maybe a panic, error, or log?)
4. Use the inline assistant to generate a fix for the error.
## Prefilling Prompts
To create a custom keybinding that prefills a prompt, you can add the following format in your keymap:
```json
[
{
"context": "Editor && mode == full",
"bindings": {
"ctrl-shift-enter": [
"assistant::InlineAssist",
{ "prompt": "Build a snake game" }
]
}
}
]
```

View file

@ -0,0 +1,224 @@
# Prompting & Prompt Library
## Using Prompts {#using-prompts}
Prompts are an essential part of interacting with AI assistants in Zed. They help guide the AI's responses and ensure you get the most relevant and useful information.
Every new context will start with the [default prompt](#default-prompt), which can be customized.
Remember that effective prompting is an iterative process. Experiment with different prompt structures and wordings to find what works best for your specific needs and the model you're using.
Here are some tips for using prompts effectively:
1. Be specific: Clearly state what you want the AI to do or explain.
2. Provide context: Include relevant information about your project or problem.
3. Use examples: If applicable, provide examples to illustrate your request.
4. Break down complex tasks: For multi-step problems, consider breaking them into smaller, more manageable prompts.
## Prompt Library {#prompt-library}
The Prompt Library is an interface for writing and managing prompts. Like other text-driven UIs in Zed, it is a full editor with syntax highlighting, keyboard shortcuts, etc.
You can use the inline assistant right in the prompt editor, allowing you to automate and rewrite prompts.
### Opening the Prompt Library
1. Open the assistant panel.
2. Click on the menu in the top right corner.
3. Select "Prompt Library" from the dropdown.
You can also use the `prompt-library: toggle` command.
### Managing Prompts
Once a prompt is selected, you can edit it directly in the editor. It's title can be changed from the editor title bar as well.
Prompts can be duplicated, deleted, or added to the default prompt using the buttons in the prompt editor.
## Creating a Prompt {#creating-a-prompt}
To create a prompt, simply open the Prompt Library and click the "+" button. Prompts are stored locally and can be accessed from the library at any time.
Having a series of prompts specifically tailored to prompt engineering can also help you write consistent and effective prompts.
The process of writing and refining prompts commonly called "prompt engineering".
More on prompt engineering:
- [Anthropic: Prompt Engineering](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview)
- [OpenAI: Prompt Engineering](https://platform.openai.com/docs/guides/prompt-engineering)
## Editing the Default Prompt {#default-prompt}
Zed allows you to customize the default prompt used in new context editors. Or to be more precise, it uses a series of prompts that are combined to form the default prompt.
A default prompt might look something like:
```plaintext
[-] Default
[+] Today's date
[+] You are an expert
[+] Don't add comments
```
Each of the above prompts can be individually expanded, and since Zed's assistant is all text, they can also be edited directly. Edits here will not propagate to the saved prompts.
You can add prompts to the default prompt by clicking the icon in the top right (the "sparkle" icon) of the prompt editor. This will add the prompt to the default prompt.
_Changes to the default prompt will not affect existing contexts. You can remove the default prompt and manually re-add it with `/default` to update an existing context._
Default prompts will show at the top of the prompt list, and will be included with every new context.
You can manually add the default prompt using the `/default` command.
> **Note:** Remember, commands are only evaluated when the context is created, so a command like `/now` won't continuously update, or `/file` commands won't keep their contents up to date.
## Commands in Prompts
[Commands](/assistant/commands.md) can be used in prompts to insert dynamic content or perform actions. For example, if you want to create a prompt where it is important for the model to know the date, you can use the `/now` command to insert the current date.
> **Note:** Slash commands in prompts **must** be on their own line.
See the [Commands](/assistant/commands.md) docs for more information on commands, and what slash commands are available.
### Example:
```plaintext
You are an expert Rust engineer. The user has asked you to review their project and answer some questions.
Here is some information about their project:
/file Cargo.toml
```
In the above example, the `/file` command is used to insert the contents of the `Cargo.toml` file (or all `Cargo.toml` files present in the project) into the prompt.
## Nesting Prompts
Similar to adding prompts to the default prompt, you can nest prompts within other prompts with the `/prompt` command.
You might want to nest prompts to:
- Create templates on the fly
- Break collections like docs or references into smaller, mix-and-matchable parts
- Create variants of a similar prompt (e.g., `Async Rust - Tokio` vs. `Async Rust - Async-std`)
### Example:
```plaintext
Title: Zed-Flavored Rust
## About Zed
/prompt Zed: Zed (a prompt about what Zed is)
## Rust - Zed Style
/prompt Rust: Async - Async-std (zed doesn't use tokio)
/prompt Rust: Zed-style Crates (we have some unique conventions)
/prompt Rust - Workspace deps (bias towards reusing deps from the workspace)
```
_The (text) above are comments and are not part of the prompt._
> **Note:** While you technically _can_ nest a prompt within itself, we wouldn't recommend it (in the strongest of terms.) Use at your own risk!
By using nested prompts, you can create modular and reusable prompt components that can be combined in various ways to suit different scenarios.
## Advanced Concepts
### Prompt Templates
Zed uses prompt templates to power internal assistant features, like the terminal assistant, or the content prompt used in the inline assistant.
Zed has the following internal prompt templates:
- `content_prompt.hbs`: Used for generating content in the editor.
- `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
- `edit_workflow.hbs`: Used for generating the edit workflow prompt.
- `step_resolution.hbs`: Used for generating the step resolution prompt.
At this point it is unknown if we will expand templates further to be user-creatable.
### Overriding Templates
> **Note:** It is not recommended to override templates unless you know what you are doing. Editing templates will break your assistant if done incorrectly.
Zed allows you to override the default prompts used for various assistant features by placing custom Handlebars (.hbs) templates in your `~/.config/zed/prompts/templates` directory.
The following templates can be overridden:
1. `content_prompt.hbs`: Used for generating content in the editor.
Format:
```handlebars
You are an AI programming assistant. Your task is to
{{#if is_insert}}insert{{else}}rewrite{{/if}}
{{content_type}}{{#if language_name}} in {{language_name}}{{/if}}
based on the following context and user request. Context:
{{#if is_truncated}}
[Content truncated...]
{{/if}}
{{document_content}}
{{#if is_truncated}}
[Content truncated...]
{{/if}}
User request:
{{user_prompt}}
{{#if rewrite_section}}
Please rewrite the section enclosed in
<rewrite_this></rewrite_this>
tags.
{{else}}
Please insert your response at the
<insert_here></insert_here>
tag.
{{/if}}
Provide only the
{{content_type}}
content in your response, without any additional explanation.
```
2. `terminal_assistant_prompt.hbs`: Used for the terminal assistant feature.
Format:
```handlebars
You are an AI assistant for a terminal emulator. Provide helpful responses to
user queries about terminal commands, file systems, and general computer
usage. System information: - Operating System:
{{os}}
- Architecture:
{{arch}}
{{#if shell}}
- Shell:
{{shell}}
{{/if}}
{{#if working_directory}}
- Current Working Directory:
{{working_directory}}
{{/if}}
Latest terminal output:
{{#each latest_output}}
{{this}}
{{/each}}
User query:
{{user_prompt}}
Provide a clear and concise response to the user's query, considering the
given system information and latest terminal output if relevant.
```
3. `edit_workflow.hbs`: Used for generating the edit workflow prompt.
4. `step_resolution.hbs`: Used for generating the step resolution prompt.
> **Note:** Be sure you want to override these, as you'll miss out on iteration on our built-in features. This should be primarily used when developing Zed.
You can customize these templates to better suit your needs while maintaining the core structure and variables used by Zed. Zed will automatically reload your prompt overrides when they change on disk.
Consult Zed's [assets/prompts](https://github.com/zed-industries/zed/tree/main/assets/prompts) directory for current versions you can play with.

View file

@ -23,6 +23,7 @@
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
<link rel="stylesheet" href="{{ path_to_root }}plugins.css">
{{#if print_enable}}
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
{{/if}}
@ -251,9 +252,10 @@
<script src="{{ path_to_root }}highlight.js"></script>
<script src="{{ path_to_root }}book.js"></script>
<!-- Custom JS scripts -->
<!-- Custom JS scripts -->
{{#each additional_js}}
<script src="{{ ../path_to_root }}{{this}}"></script>
<script src="{{ path_to_root }}plugins.js"></script>
{{/each}}
{{#if is_print}}

8
docs/theme/plugins.css vendored Normal file
View file

@ -0,0 +1,8 @@
kbd.keybinding {
background-color: #f0f0f0;
padding: 2px 4px;
border-radius: 3px;
font-family: monospace;
display: inline-block;
margin: 0 2px;
}

50
docs/theme/plugins.js vendored Normal file
View file

@ -0,0 +1,50 @@
function detectOS() {
var userAgent = navigator.userAgent;
var platform = navigator.platform;
var macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
var windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
var iosPlatforms = ["iPhone", "iPad", "iPod"];
if (macosPlatforms.indexOf(platform) !== -1) {
return "Mac";
} else if (iosPlatforms.indexOf(platform) !== -1) {
return "iOS";
} else if (windowsPlatforms.indexOf(platform) !== -1) {
return "Windows";
} else if (/Android/.test(userAgent)) {
return "Android";
} else if (/Linux/.test(platform)) {
return "Linux";
}
return "Unknown";
}
// Usage
var os = detectOS();
console.log("Operating System:", os);
(function updateKeybindings() {
const os = detectOS();
const isMac = os === "Mac" || os === "iOS";
function processKeybinding(element) {
const [macKeybinding, linuxKeybinding] = element.textContent.split("|");
element.textContent = isMac ? macKeybinding : linuxKeybinding;
element.classList.add("keybinding");
}
function walkDOM(node) {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.tagName.toLowerCase() === "kbd") {
processKeybinding(node);
} else {
Array.from(node.children).forEach(walkDOM);
}
}
}
// Start the process from the body
walkDOM(document.body);
})();