Elffuss BraidHub

kikocis/continue public

e8ee99375f3e · 10.1 KiBRenderedRawPermalink
1---
2title: 上下文提供者
3description: 输入 '@' 选择内容到 LLM 作为上下文
4keywords: [上下文, "@", 提供者, LLM]
5---
6
7上下文提供者允许你输入 '@' ,看到一个上下文下拉框,都可以提供给 LLM 作为上下文。每个上下文提供者是一个插件,也就是说,如果你想要关联一些没有在这里看到的信息源,你可以请求(或构建!)一个新的上下文提供者。
8
9举一个例子,比如你工作在解决一个新的 GitHub Issue 。你输入 '@Issue' 并选择你工作的那个。 Continue 现在可以看到 issue 标题和内容。你还知道那个 issue 关联到文件 'readme.md' 和 'helloNested.py' ,所以你输入 '@readme' 和 '@hello' 查看并选择它们。现在,这里有 3 个 "上下文条目" 在行内显示,和你的其他输入一起。
10
11![上下文条目](/img/context-provider-example.png)
12
13## 内置的上下文提供者
14
15为了使用任何内置的上下文提供者,打开 `config.json` 并将它添加到 `contextProviders` 列表中。
16
17### `@File`
18
19关联你的当前工作区的任何文件。
20
21```json title="config.json"
22{
23 "contextProviders": [
24 {
25 "name": "file"
26 }
27 ]
28}
29```
30
31### `@Code`
32
33关联你的项目中特定的函数或类。
34
35```json title="config.json"
36{
37 "contextProviders": [
38 {
39 "name": "code"
40 }
41 ]
42}
43```
44
45### `@Git Diff`
46
47关联你对当前分支所在的所有修改。这是有用的,如果你想要在提交之前,总结你做了什么,或询问一个关于你的工作通用的评审。
48
49```json title="config.json"
50{
51 "contextProviders": [
52 {
53 "name": "diff"
54 }
55 ]
56}
57```
58
59### `@Terminal`
60
61关联你的 IDE 终端的内容。
62
63```json title="config.json"
64{
65 "contextProviders": [
66 {
67 "name": "terminal"
68 }
69 ]
70}
71```
72
73### `@Docs`
74
75关联任何文档网站的内容。
76
77```json title="config.json"
78{
79 "contextProviders": [
80 {
81 "name": "docs"
82 }
83 ]
84}
85```
86
87注意这只启用 `@Docs` 上下文提供者。
88
89为了使用它,你需要添加一个文档网站到你的 `config.json` 。查看 [docs](../customize/deep-dives/docs.md) 页面获取更多信息。
90
91### `@Open`
92
93关联你打开的所有文件的内容。设置 `onlyPinned` 为 `true` 只关联固定的文件。
94
95```json title="config.json"
96{
97 "contextProviders": [
98 {
99 "name": "open",
100 "params": {
101 "onlyPinned": true
102 }
103 }
104 ]
105}
106```
107
108### `@Codebase`
109
110关联你的代码库中最相关的片段。
111
112```json title="config.json"
113{
114 "contextProviders": [
115 {
116 "name": "codebase"
117 }
118 ]
119}
120```
121
122在 [这里](../customize/deep-dives/codebase.md) 查看更多关于索引和检索。
123
124### `@Folder`
125
126使用和 `@Codebase` 相同的检索机制,但是只在一个单独的文件夹上。
127
128```json title="config.json"
129{
130 "contextProviders": [
131 {
132 "name": "folder"
133 }
134 ]
135}
136```
137
138### `@Search`
139
140关联代码库搜索的结果,就像你从 VS Code 搜索获得的结果。
141
142```json title="config.json"
143{
144 "contextProviders": [
145 {
146 "name": "search"
147 }
148 ]
149}
150```
151
152这个上下文提供者是由 [ripgrep](https://github.com/BurntSushi/ripgrep) 支持的。
153
154### `@Url`
155
156关联给定 URL 的 markdown 转换内容。
157
158```json title="config.json"
159{
160 "contextProviders": [
161 {
162 "name": "url"
163 }
164 ]
165}
166```
167
168### `@Tree`
169
170关联你当前工作区的结构。
171
172```json title="config.json"
173{
174 "contextProviders": [
175 {
176 "name": "tree"
177 }
178 ]
179}
180```
181
182### `@Google`
183
184关联 Google 搜索的结果。
185
186```json title="config.json"
187{
188 "contextProviders": [
189 {
190 "name": "google",
191 "params": {
192 "serperApiKey": "<your serper.dev api key>"
193 }
194 }
195 ]
196}
197```
198
199例如,输入 "@Google python tutorial" ,如果你想要搜索或讨论学习 Python 的方法。
200
201注意:你可以在 [serper.dev](https://serper.dev) 免费获得 API key 。
202
203### `@Issue`
204
205关联一个 GitHub issue 的交谈信息。
206
207```json title="config.json"
208{
209 "contextProviders": [
210 {
211 "name": "issue",
212 "params": {
213 "repos": [
214 {
215 "owner": "continuedev",
216 "repo": "continue"
217 }
218 ],
219 "githubToken": "ghp_xxx"
220 }
221 }
222 ]
223}
224```
225
226确保包含你自己的 [GitHub 个人访问 token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) 来避免频率限制。
227
228### `@Gitlab Merge Request`
229
230关联一个 Gitlab 上这个分支上打开的 MR 。
231
232```json title="config.json"
233{
234 "contextProviders": [
235 {
236 "name": "gitlab-mr",
237 "params": {
238 "token": "..."
239 }
240 }
241 ]
242}
243```
244
245你需要创建一个使用 `read_api` 范围的 [个人访问 token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html)。
246
247#### 使用自托管的 GitLab
248
249你可以指定要访问的域名,通过在你的配置中设置 `domain` 参数。默认情况下是 `gitlab.com` 。
250
251```json title="config.json"
252{
253 "contextProviders": [
254 {
255 "name": "gitlab-mr",
256 "params": {
257 "token": "...",
258 "domain": "gitlab.example.com"
259 }
260 }
261 ]
262}
263```
264
265#### 过滤评论
266
267如果你选择一些代码被编辑,你可以有上下文提供者过滤其他文件的评论。要启用这个特性,设置 `filterComments` 为 `true` 。
268
269### `@Jira`
270
271关联一个 Jira issue 的交谈信息。
272
273```json title="config.json"
274{
275 "contextProviders": [
276 {
277 "name": "jira",
278 "params": {
279 "domain": "company.atlassian.net",
280 "token ": "ATATT..."
281 }
282 }
283 ]
284}
285```
286
287确认包含你自己的 [Atlassian API Token](https://id.atlassian.com/manage-profile/security/api-tokens) ,或者使用你的 `email` 和 `token` , token 设置为你的密码获得基本认证。如果你使用自己的 Atlassian API Token ,不要配置你的邮箱。
288
289#### Jira Datacenter 支持
290
291这个上下文提供者支持 Jira API 版本 2 和 3 。默认情况下,它将使用版本 3 ,因为这是云版本使用的,但是如果你有 datacenter 版本的 Jira ,你需要使用 `apiVersion` 属性设置 API Version 为 2 。
292
293```json title="config.json"
294{
295 "contextProviders": [
296 {
297 "name": "jira",
298 "params": {
299 "apiVersion": "2"
300 }
301 }
302 ]
303}
304```
305
306#### Issue 查询
307
308默认情况下,以下查询用来查找 issue :
309
310```jql
311assignee = currentUser() AND resolution = Unresolved order by updated DESC
312```
313
314你可以覆盖这个查询,通过设置 `issueQuery` 参数。
315
316### `@Postgres`
317
318关联表的 schema ,和一些示例行
319
320```json title="config.json"
321{
322 "contextProviders": [
323 {
324 "name": "postgres",
325 "params": {
326 "host": "localhost",
327 "port": 5436,
328 "user": "myuser",
329 "password": "catsarecool",
330 "database": "animals",
331 "schema": "public",
332 "sampleRows": 3
333 }
334 }
335 ]
336}
337```
338
339仅需要的配置是那些创建数据库连接所需要的: `host`, `port`, `user`, `password` 和 `database` 。
340
341默认情况下, `schema` 过滤器设置为 `public` , `sampleRows` 设置为 3 。你可以取消设置 schema ,如果你想要包含所有 schema 的表。
342
343[这是一个简单的 demo](https://github.com/continuedev/continue/pull/859) 。
344
345### `@Database`
346
347关联 Sqlite, Postgres 和 MySQL 数据库的表 schema 。
348
349```json title="config.json"
350{
351 "contextProviders": [
352 {
353 "name": "database",
354 "params": {
355 "connections": [
356 {
357 "name": "examplePostgres",
358 "connection_type": "postgres",
359 "connection": {
360 "user": "username",
361 "host": "localhost",
362 "database": "exampleDB",
363 "password": "yourPassword",
364 "port": 5432
365 }
366 },
367 {
368 "name": "exampleSqlite",
369 "connection_type": "sqlite",
370 "connection": {
371 "filename": "/path/to/your/sqlite/database.db"
372 }
373 }
374 ]
375 }
376 }
377 ]
378}
379```
380
381每个连接应该有一个单独的名称,`connection_type` ,以及每个数据库类型特定的必须的连接参数。
382
383可用的连接类型:
384
385- `postgres`
386- `mysql`
387- `sqlite`
388
389### `@Locals`
390
391关联调试器中本地变量的内容。
392
393```json title="config.json"
394{
395 "contextProviders": [
396 {
397 "name": "locals",
398 "params": {
399 "stackDepth": 3
400 }
401 }
402 ]
403}
404```
405
406使用最多 _n_ 级 (默认是 3) 的当前线程的调用栈。
407
408### `@Repository Map`
409
410关联你的代码库的概览。
411
412```json title="config.json"
413{
414 "contextProviders": [
415 {
416 "name": "repo-map"
417 }
418 ]
419}
420```
421
422提供一个文件列表,以及这些文件中的最高级的类、函数和方法的调用签名。这帮助模型更好地理解,一段特定的代码如何关联其他的代码库。
423
424在出现的子菜单中,你可以选择 `Entire codebase` 或指定一个子文件夹,来生成仓库映射。
425
426这个上下文提供者想法来自 [Aider's repository map](https://aider.chat/2023/10/22/repomap.html) 。
427
428### `@Operating System`
429
430关联你当前操作系统的架构和平台。
431
432```json title="config.json"
433{
434 "contextProviders": [
435 {
436 "name": "os"
437 }
438 ]
439}
440```
441
442### `@HTTP`
443
444HttpContextProvider 创建一个 POST 请求到配置中的 url 。服务器必须返回 200 OK ,以及一个 ContextItem 对象或一个 ContextItems 列表。
445
446```json title="config.json"
447{
448 "contextProviders": [
449 {
450 "name": "http",
451 "params": {
452 "url": "https://api.example.com/v1/users"
453 }
454 }
455 ]
456}
457```
458
459接收的 URL 应该接收下面的参数:
460
461```json title="POST parameters"
462{
463 query: string,
464 fullInput: string
465}
466```
467
468响应 200 OK 应该是一个有以下结构的 JSON 对象:
469
470```json title="Response"
471[
472 {
473 "name": "",
474 "description": "",
475 "content": ""
476 }
477]
478
479// OR
480{
481 "name": "",
482 "description": "",
483 "content": ""
484}
485```
486
487### 请求上下文提供者
488
489没有看到你想要的?[在这里](https://github.com/continuedev/continue/issues/new?assignees=TyDunn&labels=enhancement&projects=&template=feature-request-%F0%9F%92%AA.md&title=) 创建一个 issue 来请求一个新的上下文提供者。