Allow prompt templates to be overridden in the zed configuration directory (#15887)

I need this to refine our prompts on the fly as I work.

Release Notes:

- Templates for prompts driving inline transformation in editors and the
terminal can now be overridden in the `~/.config/zed/prompts/templates`
directory. This is an advanced feature, and prevents you from getting
upstream changes. It's intended for use by Zed developers.
This commit is contained in:
Nathan Sobo
2024-08-06 19:30:48 -06:00
committed by GitHub
parent 6065db174a
commit c8f1358629
12 changed files with 569 additions and 168 deletions
+73
View File
@@ -151,3 +151,76 @@ To create a custom keybinding that prefills a prompt, you can add the following
}
]
```
## 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.
```
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.
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.