跳到主要内容

上下文提供者

上下文提供者允许你输入“@”并查看一个包含可作为上下文提供给 LLM 的内容的下拉列表。每个上下文提供者都是一个插件,这意味着如果你想引用一些此处未显示的信息源,可以请求(或构建!)一个新的上下文提供者。

举例来说,假设你正在处理一个新的 GitHub Issue。你输入 '@Issue' 并选择正在处理的那一个。Continue 现在可以看到该 Issue 的标题和内容。你还知道该 Issue 与文件 'readme.md' 和 'helloNested.py' 相关,因此你输入 '@readme' 和 '@hello' 来查找并选中它们。现在这 3 个“上下文项目”会与你的其他输入一起内联显示。

Context Items

上下文块

你可以使用 context将上下文提供者添加到助手。在中心探索可用的上下文块。

内置上下文提供者

你可以将任何内置上下文提供者添加到你的配置文件中,如下所示

@File

引用当前工作区中的任何文件。

config.yaml
context:
- provider: file

@Code

引用项目中特定的函数或类。

config.yaml
context:
- provider: code

@Git Diff

引用当前分支上的所有更改。如果你想总结已完成的工作或在提交前请求对你的工作进行一般性审查,这会很有用。

config.yaml
context:
- provider: diff

@Current File

引用当前打开的文件。

config.yaml
context:
- provider: currentFile

@Terminal

引用你在 IDE 终端中运行的最后一条命令及其输出。

config.yaml
context:
- provider: terminal

@Docs

引用任何文档网站的内容。

config.yaml
context:
- provider: docs

注意,这只会启用 @Docs 上下文提供者。

要使用它,你需要将一个文档网站添加到你的配置文件中。有关更多信息,请参阅文档页面。

@Open

引用所有打开文件的内容。将 onlyPinned 设置为 true 可仅引用已固定的文件。

config.yaml
context:
- provider: open
params:
onlyPinned: true

@Web

引用网络上相关页面,根据你的输入自动确定。

可选地,设置 n 来限制返回结果的数量(默认为 6)。

config.yaml
context:
- provider: web
params:
n: 5

@Codebase

引用代码库中最相关的片段。

config.yaml
context:
- provider: codebase

阅读有关索引和检索的更多信息此处

@Folder

使用与 @Codebase 相同的检索机制,但仅作用于单个文件夹。

config.yaml
context:
- provider: folder

引用代码库搜索结果,就像你在 VS Code 搜索中获得的结果一样。

config.yaml
context:
- provider: search

此上下文提供者由ripgrep驱动。

@Url

引用给定 URL 的 Markdown 转换内容。

config.yaml
context:
- provider: url

@Clipboard

引用最近的剪贴板项目

config.yaml
context:
- provider: clipboard

@Tree

引用当前工作区的结构。

config.yaml
context:
- provider: tree

@Problems

获取当前文件中的问题。

config.yaml
context:
- provider: problems

@Debugger

引用调试器中局部变量的内容。目前仅在 VS Code 中可用。

config.yaml
context:
- provider: debugger
params:
stackDepth: 3

使用该线程调用堆栈的前 n 层(默认为 3 层)。

@Repository Map

引用代码库的概览。默认情况下,仓库映射中会包含签名以及文件。

可以将 includeSignatures 参数设置为 false 以排除签名。对于大型代码库和/或显著减小上下文大小,这可能是必需的。如果禁用了索引,将不包含签名。

config.yaml
context:
- provider: repo-map
params:
includeSignatures: false # default true

提供文件列表以及这些文件中顶级类、函数和方法的调用签名。这有助于模型更好地理解特定代码片段如何与代码库的其余部分相关联。

在出现的子菜单中,你可以选择 Entire codebase,或指定一个子文件夹来生成仓库映射。

此上下文提供者受到Aider 的仓库映射的启发。

@Operating System

引用当前操作系统的架构和平台。

config.yaml
context:
- provider: os

模型上下文协议

模型上下文协议是 Anthropic 提出的一个标准,旨在统一提示、上下文和工具使用。Continue 支持任何具有 MCP 上下文提供者的 MCP 服务器。阅读他们的快速入门以了解如何设置本地服务器,然后像这样设置你的配置

config.yaml
mcpServers:
- name: My MCP Server
command: uvx
args:
- mcp-server-sqlite
- --db-path
- /Users/NAME/test.db

然后你就可以输入“@”并在上下文提供者下拉列表中看到“MCP”。

@Issue

引用 GitHub Issue 中的对话。

config.yaml
context:
- provider: issue
params:
repos:
- owner: continuedev
repo: continue
githubToken: ghp_xxx

确保包含你的个人GitHub 个人访问令牌以避免受到速率限制。

@Database

引用 Sqlite、Postgres、MSSQL 和 MySQL 数据库的表结构。

config.yaml
context:
- provider: database
params:
connections:
- name: examplePostgres
connection_type: postgres
connection:
user: username
host: localhost
database: exampleDB
password: yourPassword
port: 5432
- name: exampleMssql
connection_type: mssql
connection:
user: username
server: localhost
database: exampleDB
password: yourPassword
- name: exampleSqlite
connection_type: sqlite
connection:
filename: /path/to/your/sqlite/database.db

每个连接应包含一个唯一的名称、connection_type 以及每种数据库类型所需的连接参数。

可用连接类型

  • postgres
  • mysql
  • sqlite

@Postgres

引用表的结构和一些示例行

config.yaml
context:
- provider: postgres
params:
host: localhost
port: 5436
user: myuser
password: catsarecool
database: animals
schema: public
sampleRows: 3

唯一必需的设置是用于创建数据库连接的参数:hostportuserpassworddatabase

默认情况下,schema 过滤器设置为 publicsampleRows 设置为 3。如果你想包含所有模式中的表,可以取消设置 schema。

这里有一个简短的演示。

@Google

引用 Google 搜索结果。

config.yaml
context:
- provider: google
params:
serperApiKey: <YOUR_SERPER.DEV_API_KEY>

例如,如果你想搜索和讨论学习 Python 的方法,可以输入“@Google python tutorial”。

注意:你可以在serper.dev免费获取 API 密钥。

@Gitlab Merge Request

引用 GitLab 上此分支的开放 MR(合并请求)。

config.yaml
context:
- provider: gitlab-mr
params:
token: "..."

你需要创建一个个人访问令牌,并具有 read_api 范围。

使用自托管 GitLab

你可以通过设置配置中的 domain 参数来指定通信域名。默认情况下,此参数设置为 gitlab.com

config.yaml
context:
- provider: gitlab-mr
params:
token: "..."
domain: "gitlab.example.com"

过滤评论

如果你选择了要编辑的代码,上下文提供者可以过滤掉其他文件的评论。要启用此功能,请将 filterComments 设置为 true

@Jira

引用 Jira Issue 中的对话。

config.yaml
context:
- provider: jira
params:
domain: company.atlassian.net
token: ATATT...

确保包含你的个人Atlassian API 令牌,或者使用你的 emailtoken(token 设置为你的密码)进行基本身份验证。如果你使用自己的 Atlassian API 令牌,请不要配置你的电子邮件。

Jira Datacenter 支持

此上下文提供者支持 Jira API 版本 2 和 3。默认情况下它将使用版本 3,因为这是云版本使用的,但如果你使用的是 Jira 的 Datacenter 版本,则需要使用 apiVersion 属性将 API 版本设置为 2。

config.yaml
context:
- provider: jira
params:
apiVersion: "2"

Issue 查询

默认情况下,将使用以下查询来查找 Issue

assignee = currentUser() AND resolution = Unresolved order by updated DESC

你可以通过设置 issueQuery 参数来覆盖此查询。

最大结果数

你可以设置 maxResults 参数来限制返回结果的数量。默认值为 50

@Discord

引用 Discord 频道中的消息。

config.yaml
context:
- provider: discord
params:
discordKey: "bot token"
guildId: "1234567890"
channels:
- id: "123456"
name: "example-channel"
- id: "678901"
name: "example-channel-2"

确保包含你的Bot 令牌,并将其加入你的相关服务器。如果你想更精细地控制搜索哪些频道,可以指定要搜索的频道 ID 列表。如果你不想指定任何频道,只需包含 guild id(服务器 ID),所有频道都将包含在内。此提供者仅读取文本频道。

@HTTP

HttpContextProvider 会向配置中传递的 URL 发送 POST 请求。服务器必须返回 200 OK,并包含一个 ContextItem 对象或一个 ContextItems 数组。

config.yaml
context:
- provider: http
params:
url: "https://api.example.com/v1/users"

接收 URL 应期望接收以下参数

POST 参数
{
query: string,
fullInput: string
}

200 OK 响应应是一个具有以下结构的 JSON 对象

响应
[
{
"name": "",
"description": "",
"content": ""
}
]

// OR
{
"name": "",
"description": "",
"content": ""
}

@Commits

引用特定的 Git 提交元数据和差异,或引用所有最近的提交。

config.yaml
context:
- provider: commit
params:
Depth: 50
LastXCommitsDepth: 10

depth 参数决定了子菜单中将加载多少提交,默认为 50。LastXCommitsDepth 参数决定了将包含多少最近的提交,默认为 10。

@Greptile

查询当前仓库/分支的Greptile索引。

config.yaml
context:
- provider: greptile
params:
greptileToken: "..."
githubToken: "..."

请求上下文提供者

没有找到你想要的?在此处创建 Issue 来请求一个新的上下文提供者。