跳到主要内容

编辑角色

选择与响应聊天提示不同的模型来响应编辑提示通常很有用,因为编辑通常更特定于代码,并且可能需要较少的对话可读性。

在 Continue 中,您可以将 edit 添加到模型的角色中,以指定它可以用于 Edit 请求。如果未指定任何 edit 模型,则使用选定的 chat 模型。

使用模型角色。

config.yaml
models:
- name: Claude 3.5 Sonnet
provider: anthropic
model: claude-3-5-sonnet-latest
apiKey: <YOUR_ANTHROPIC_API_KEY>
roles:
- edit

中心探索编辑模型。通常,我们对 Edit 的推荐与对 Chat 的推荐重叠。

提示模板化

您可以通过在模型配置中设置 promptTemplates.edit 属性来自定义用于编辑代码的提示模板。Continue 使用 Handlebars 语法进行模板化。

编辑模板的可用变量

  • {{{userInput}}} - 用户的编辑请求/指令
  • {{{language}}} - 代码的编程语言
  • {{{codeToEdit}}} - 正在编辑的代码
  • {{{prefix}}} - 编辑区域之前的内容
  • {{{suffix}}} - 编辑区域之后的内容
  • {{{supportsCompletions}}} - 模型是否支持 Completions API
  • {{{supportsPrefill}}} - 模型是否支持预填充功能

示例

models:
- name: My Custom Edit Template
provider: openai
model: gpt-4o
promptTemplates:
edit: |
`Here is the code before editing:
\`\`\`{{{language}}}
{{{codeToEdit}}}
\`\`\`

Here is the edit requested:
"{{{userInput}}}"

Here is the code after editing:`