Search code examples
visual-studio-codevscode-extensions

How to call GitHub Copilot Chat from my VS Code extension?


I want to write a vscode extension that can launch/trigger GitHub Copilot Chat to the do prompt. The expected use case looks like this:

  1. User select a piece of code
  2. User execute Source Action with my command, then my command able to send custom prompt to input box of the GitHub Copilot Chat and send it to get results.

Is that possible at this moment?


Solution

  • This should be possible using the Language Model API:

    https://code.visualstudio.com/api/extension-guides/language-model#send-the-language-model-request

    It allows you to send request directly to copilot-gpt-3.5-turbo and copilot-gpt-4 and handle the response in your extension.

    copilot-gpt-4 is the model used by Copilot Chat, copilot-gpt-3.5-turbo is mainly used for code completions in the editor.

    If you want to build this interaction into the Copilot Chat window itself, your extension can contribute a chat participant:

    https://code.visualstudio.com/api/extension-guides/chat#register-the-chat-extension