7.2 KiB
| title | description | keywords | ||||
|---|---|---|---|---|---|---|
| Context Providers | Type '@' to select content to the LLM as context |
|
Context Providers
Context Providers allow you to type '@' and see a dropdown of content that can all be fed to the LLM as context. Every context provider is a plugin, which means if you want to reference some source of information that you don't see here, you can request (or build!) a new context provider.
As an example, say you are working on solving a new GitHub Issue. You type '@issue' and select the one you are working on. Continue can now see the issue title and contents. You also know that the issue is related to the files 'readme.md' and 'helloNested.py', so you type '@readme' and '@hello' to find and select them. Now these 3 "Context Items" are displayed inline with the rest of your input.
Built-in Context Providers
To use any of the built-in context providers, open ~/.continue/config.json and add it to the contextProviders list.
Git Diff
Type '@diff' to reference all of the changes you've made to your current branch. This is useful if you want to summarize what you've done or ask for a general review of your work before committing.
{ "name": "diff" }
Terminal
Type '@terminal' to reference the contents of your IDE's terminal.
{ "name": "terminal" }
Open Files
Type '@open' to reference the contents of all of your open files. Set onlyPinned to true to only reference pinned files.
{ "name": "open", "params": { "onlyPinned": true } }
Codebase Retrieval
Type '@codebase' to automatically retrieve the most relevant snippets from your codebase. Read more about indexing and retrieval here.
{ "name": "codebase" }
Folders
Type '@folder' to use the same retrieval mechanism as '@codebase', but only on a single folder.
{ "name": "folder" }
Exact Search
Type '@search' to reference the results of codebase search, just like the results you would get from VS Code search. This context provider is powered by ripgrep.
{ "name": "search" }
File Tree
Type '@tree' to reference the structure of your current workspace. The LLM will be able to see the nested directory structure of your project.
{ "name": "tree" }
Type '@google' to reference the results of a Google search. For example, type "@google python tutorial" if you want to search and discuss ways of learning Python.
{
"name": "google",
"params": { "serperApiKey": "<your serper.dev api key>" }
}
Note: You can get an API key for free at serper.dev.
GitHub Issues
Type '@issue' to reference the conversation in a GitHub issue. Make sure to include your own GitHub personal access token to avoid being rate-limited:
{
"name": "issue",
"params": {
"repos": [
{
"owner": "continuedev",
"repo": "continue"
}
],
"githubToken": "ghp_xxx"
}
}
Requesting Context Providers
Not seeing what you want? Create an issue here to request a new ContextProvider.
Building Your Own Context Provider
Currently custom context providers are only supported in VS Code, but are coming soon to JetBrains IDEs.
Introductory Example
To write your own context provider, you just have to implement the CustomContextProvider
interface:
interface CustomContextProvider {
title: string;
displayTitle?: string;
description?: string;
getContextItems(
query: string,
extras: ContextProviderExtras
): Promise<ContextItem[]>;
}
As an example, let's say you have a set of internal documents that have been indexed in a vector database. You've set up a simple REST API that allows internal users to query and get back relevant snippets. This context provider will send the query to this server and return the results from the vector database.
const RagContextProvider: CustomContextProvider = {
title: "rag",
displayTitle: "RAG",
description:
"Retrieve snippets from our vector database of internal documents",
getContextItems: async (
query: string,
extras: ContextProviderExtras
): Promise<ContextItem[]> => {
const response = await fetch("https://internal_rag_server.com/retrieve", {
method: "POST",
body: JSON.stringify({ query }),
});
const results = await response.json();
return results.map((result) => ({
name: result.title,
description: result.title,
content: result.contents,
}));
},
};
It can then be added in config.ts like so:
export function modifyConfig(config: Config): Config {
if (!config.contextProviders) {
config.contextProviders = [];
}
config.contextProviders.push(RagContextProvider);
return config;
}
No modification in config.json is necessary.
Importing outside modules
Context providers run in a NodeJS environment, but for the time being the
modifyConfigfunction will be called both from NodeJS and the browser. This means that if you are importing packages requiring NodeJS, you should dynamically import them inside of the context provider (e.g.const moduleA = await import('./moduleA');).
To include outside Node modules in your config.ts, run npm install <module_name> from the ~/.continue directory, and then import them in config.ts.
Continue will use esbuild to bundle your config.ts and any dependencies into a single Javascript file. The exact configuration used can be found here.
CustomContextProvider Reference
title: An identifier for the context providerdisplayTitle(optional): The title displayed in the dropdowndescription(optional): The longer description displayed in the dropdown when hoveredgetContextItems: A function that returns the documents to include in the prompt. It should return a list ofContextItems, and is given access to the following arguments:extras.fullInput: A string representing the user's full input to the text box. This can be used for example to generate an embedding to compare against a set of other embedded documentsextras.embeddingsProvider: The embeddings provider has anembedfunction that will convert text (such asfullInput) to an embeddingextras.llm: The current default LLM, which you can use to make completion requestsextras.ide: An instance of theIDEclass, which lets you gather various sources of information from the IDE, including the contents of the terminal, the list of open files, or any warnings in the currently open file.query: (not currently used) A string representing the query
