Note: This file has been modified from its original contents. pearai-submodule is a fork of Continue (https://github.com/continuedev/continue).
🌐 For how to setup, build, and run PearAI, please visit PearAI-App Contributing for the main guide!
- ✨ Writing Slash Commands
- 📜 Writing Context Providers
- 🤖 Adding an LLM Provider
- 🧠 Adding Models
- 📖 Adding Pre-indexed Documentation
- ⚙️ PearAI Architecture
- 🧩 PearAI VS Code Extension
The slash command interface, defined in core/index.d.ts, requires you to define:
name
: The text that will be typed to invoke the command.description
: The text that will be shown in the slash command menu.run
: An async generator function that will be called when the command is invoked. It yields the content to be displayed in the chat and is passed aPearAISDK
object for interacting with the IDE, calling the LLM, and accessing chat history.
export interface SlashCommand {
name: string;
description: string;
params?: { [key: string]: any };
run: (sdk: PearAISDK) => AsyncGenerator<string | undefined>;
}
There are many examples of slash commands in core/commands/slash that we recommend borrowing from. Once you've created your new SlashCommand
in this folder, be sure to complete the following 🌟:
- ✅ Add your command to the array in core/commands/slash/index.ts
- 🔧 Add your command to the list in
config_schema.json
. This ensures that Intellisense shows users what commands are available for your provider when they are editingconfig.json
. If there are any parameters that your command accepts, you should also follow existing examples in adding them to the JSON Schema.
A ContextProvider
is a PearAI plugin that lets you type '@' to quickly select documents as context for the language model. The IContextProvider
interface is defined in core/index.d.ts
, but all built-in context providers extend BaseContextProvider
.
Before defining your context provider, determine which "type" you want to create. The "query"
type will show a small text input when selected, giving the user a chance to enter something like a Google search query for the GoogleContextProvider
. The "submenu"
type will open up a submenu of items that can be searched through and selected. Examples are the GitHubIssuesContextProvider
and the DocsContextProvider
. The "normal"
type will just immediately add the context item. Examples include the DiffContextProvider
and the OpenFilesContextProvider
.
After you've written your context provider, make sure to complete the following 🌟:
- ✅ Add it to the array of context providers in core/context/providers/index.ts
- 🔧 Add it to the
ContextProviderName
type in core/index.d.ts - 📄 Add it to the list in
config_schema.json
. If there are any parameters that your context provider accepts, you should also follow existing examples in adding them to the JSON Schema.
PearAI has support for more than a dozen different LLM "providers", making it easy to use models running on OpenAI, Ollama, Together, LM Studio, and more. You can find all of the existing providers here, and if you see one missing, you can add it with the following steps:
- 🆕 Create a new file in the
core/llm/llms
directory. The name of the file should be the name of the provider, and it should export a class that extendsBaseLLM
. This class should contain the following minimal implementation. We recommend viewing pre-existing providers for more details. The LlamaCpp Provider is a good simple example.
- 📛
providerName
- the identifier for your provider - 📤 At least one of
_streamComplete
or_streamChat
- This is the function that makes the request to the API and returns the streamed response. You only need to implement one because PearAI can automatically convert between "chat" and "raw completion".
- ✅ Add your provider to the
LLMs
array in core/llm/llms/index.ts. - 🖼️ If your provider supports images, add it to the
PROVIDER_SUPPORTS_IMAGES
array in core/llm/index.ts. - 🔧 Add the necessary JSON Schema types to
config_schema.json
. This ensures that Intellisense shows users what options are available for your provider when they are editingconfig.json
. - 📄 Add a documentation page for your provider in
docs/docs/reference/Model Providers
. This should show an example of configuring your provider inconfig.json
and explain what options are available.
While any model that works with a supported provider can be used with PearAI, we keep a list of recommended models that can be automatically configured from the UI or config.json
. The following files should be updated when adding a model:
- 📂 Prompt Templates - In this file you'll find the
autodetectTemplateType
function. Make sure that for the model name you just added, this function returns the correct template type. This is assuming that the chat template for that model is already built in PearAI. If not, you will have to add the template type and corresponding edit and chat templates.
PearAI's @docs context provider lets you easily reference entire documentation sites and then uses embeddings to add the most relevant pages to context. To make the experience as smooth as possible, we pre-index many of the most popular documentation sites. If you'd like to add new documentation to this list, just add an object to the list in preIndexedDocs.ts. startUrl
is where the crawler will start and rootUrl
will filter out any pages not on that site and under the path of rootUrl
.
PearAI consists of 2 parts that are split so that it can be extended to work in other IDEs as easily as possible:
-
🖥️ PearAI GUI - The PearAI GUI is a React application that gives the user control over PearAI. It displays the current chat history, allows the user to ask questions, invoke slash commands, and use context providers. The GUI also handles most state and holds as much of the logic as possible so that it can be reused between IDEs.
-
🔌 PearAI Extension - The PearAI Extension is a plugin for the IDE which implements the IDE Interface. This allows the GUI to request information from or actions to be taken within the IDE. This same interface is used regardless of IDE. The first PearAI extensions we have built are for VS Code and JetBrains, but we plan to build clients for other IDEs in the future. The IDE Client must 1. implement IDE Interface, as is done here for VS Code and 2. display the PearAI GUI in a sidebar, like here.
The starting point for the VS Code extension is activate.ts. The activateExtension
function here will register all commands and load the PearAI GUI in the sidebar of the IDE as a webview.