What Is GitHub Copilot Chat?
GitHub Copilot Chat is a feature within GitHub Copilot, an AI coding assistant developed by GitHub and OpenAI. Copilot Chat is a chat interface that allows users to interact directly with GitHub Copilot using natural language prompts. It is integrated within GitHub.com and various supported Integrated Development Environments (IDEs) such as Visual Studio Code, Visual Studio, and the JetBrains suite of IDEs.
GitHub Copilot Chat can handle a broad spectrum of coding queries and tasks, understanding syntax, programming concepts, testing techniques, and debugging strategies. However, it is important to note that the chat is exclusively focused on coding-related questions and does not cater to general information or non-coding inquiries.
Source: GitHub
How GitHub Copilot Chat Works
GitHub Copilot is based on OpenAI’s GPT series of large language models (LLMs), especially tuned for coding tasks. As of March 2024, Copilot Chat is based on GPT-4 Turbo, which has a knowledge cutoff date of December 2023 (it was trained based on data available until that time) and has a context window of 128,000 tokens (allowing it to reference around 60,000 words in as context for its responses).
When you use Copilot Chat, the tool goes through the following steps:
1. Input Processing
The initial stage involves pre-processing the input provided by the user. This input could be in the form of code snippets or written in plain language, tailored to seek answers for coding-related inquiries. The system prepares the received input, ensuring it is in an optimal format before it is forwarded to a language model for analysis and response formulation.
2. Language Model Analysis
Once the input is pre-processed, it undergoes analysis by the Copilot Chat language model. This model is a neural network based on the Transformer architecture, trained on a vast array of text data encompassing various programming languages and coding scenarios. It examines the context and the specifics of the prompt to find the most accurate understanding of the query presented.
3. Response Generation
This response is crafted based on the model’s analysis of the input and the context in which the question was asked. The context could include the current code being worked on in the IDE, the organization’s private repositories, or knowledge bases (depending on Copilot plan). Responses can manifest in several forms, including but not limited to generated code, suggestions for code modification, or thorough explanations of the logic behind existing code.
4. Output Formatting
Copilot Chat employs various formatting techniques such as syntax highlighting, appropriate indentation, and others to enhance the clarity and readability of the response. Depending on the nature of the query, the response may also include links to additional resources or documentation that the model referenced to generate its answer.
Use Cases for GitHub Copilot Chat
Here are some examples of ways to use Copilot Chat.
Automatically Generating Code
GitHub Copilot Chat can automatically generate code based on the user’s prompts or questions. This feature is particularly beneficial for rapidly prototyping ideas or filling in boilerplate code that is repetitive and time-consuming to write. By providing a description of the desired functionality, users can receive immediate code suggestions that are ready to be reviewed and integrated into their projects.
Generating Unit Test Cases
Copilot Chat streamlines the creation of unit test cases by generating code snippets tailored to the user’s current code context or highlighted snippets within the editor. This facilitates the writing of test cases, particularly for repetitive tasks, by suggesting possible input parameters, expected output values, and assertions based on the function’s details and surrounding code.
Explaining Code and Suggesting Improvements
For code explanation, Copilot Chat generates natural language descriptions that detail the functionality and purpose of selected code. This is useful for understanding code behavior or for non-technical stakeholders. It also offers suggestions for code improvement, including better error handling and readability enhancements.
Proposing Code Fixes
When bugs arise, Copilot Chat can propose fixes, suggesting relevant code snippets and solutions. This feature is especially useful in troubleshooting, as it provides guidance based on the error context, syntax, and surrounding code, although the user must review and test these suggestions.
Answering Coding Questions
Copilot Chat also serves as a resource for answering specific coding questions, providing responses in both natural language and code snippet formats. This support covers a range of common coding tasks and challenges, offering guidance to programmers.
Limitations of GitHub Copilot Chat
While Copilot Chat can be a convenient tool for coders, it also has several limitations.
Limited Scope
Despite being trained on a large array of coding data, it has its limitations regarding the complexity of code structures or less common programming languages it can proficiently handle. The effectiveness and quality of the suggestions it provides are significantly influenced by the amount and diversity of training data available for each language.
Languages like JavaScript, which have a strong presence in public code repositories, receive more accurate and comprehensive support compared to languages with less public code available.
Potential Biases
The source of Copilot Chat’s training data—public repositories of existing code—contains inherent biases and inaccuracies that the tool might inadvertently replicate. This situation could lead to a predisposition towards specific programming languages or coding methodologies, potentially resulting in recommendations that are not the most effective or are incomplete.
Security Risks
Given that Copilot Chat generates code suggestions based on the context of the user’s current work, there is a risk of unintentionally exposing sensitive information or introducing security vulnerabilities. It is crucial for users, especially those working on security-sensitive projects, to thoroughly review and test any code generated by Copilot Chat to ensure it does not compromise the application’s integrity or security.
Matches with Public Code
While Copilot Chat is designed to create new code suggestions through a probabilistic approach, there is a small chance that it may produce code snippets that closely resemble existing code in its training set.
Although filters are in place to prevent direct matches with publicly available code on GitHub repositories, users are advised to exercise the same level of caution as they would with any code. This includes conducting comprehensive testing, intellectual property scanning, and security vulnerability assessments to confirm the appropriateness and originality of the suggested code.
Tutorial: Using GitHub Copilot Chat in Visual Studio Code
Let’s see how to get started with GitHub Copilot Chat in a popular IDE, Visual Studio Code.
Enable Copilot Chat
To enable GitHub Copilot Chat, you need to have an Individual subscription or be part of an organization with a GitHub Copilot Business or Enterprise subscription.
To enable or disable GitHub Copilot Chat for your organization:
- Go to GitHub.com and log in to your account.
- Click on your profile photo in the upper-right corner and select Your organizations from the dropdown menu.
- Choose the organization you want to manage and click Settings.
- Navigate to the Code, planning, and automation section on the sidebar and select Copilot.
- Click on Policies.
- Next to the Copilot Chat in the IDE option, you’ll see a dropdown menu. Here, you can select Enabled to activate Copilot Chat.
Install the Copilot Chat Extension in Visual Studio Code
To start using GitHub Copilot Chat in Visual Studio Code, follow these steps to install the extension:
- Open Visual Studio Code and access the Extensions view by selecting the icon in the activity bar on the left side.
- In the Search Extensions in Marketplace search box, type “GitHub Copilot Chat” and hit enter.
- Find the GitHub Copilot Chat extension in the search results and click Install.
- After installation, you might need to select Reload required to update Visual Studio Code.
- If prompted, click Sign in to GitHub in the toast notification at the bottom right corner of Visual Studio Code. Sign in with your GitHub ID that has a Copilot license or is assigned a Copilot seat through an organization.
- Follow the prompts in Visual Studio Code and on GitHub to sign-in and complete the authentication process.
- To confirm the installation, click the GitHub Copilot Chat icon in the activity bar to open the chat window.
Ask a Question
To ask your first question:
- Click the Copilot Chat icon in the activity bar to open the chat.
Source: GitHub
- At the bottom of the window, there will be a text box titled Ask Copilot a question or type / for topics. Type your code-related question here and click Enter.
- Copilot Chat processes the question and provides an answer, including code suggestions where relevant.
Use Code Suggestions from Copilot Chat
When you receive code suggestions from GitHub Copilot Chat:
- Hover over the suggestion in the chat window to see your options.
Source: GitHub
- You can:
- Copy the suggestion to your clipboard by clicking on Copy.
- Insert the suggestion into your code at the cursor’s current location by clicking on Insert at Cursor.
- For more options, select the … icon, where you can choose to insert the suggestion into a new file or run it in the Visual Studio Code terminal.
Ask Questions About the Code
GitHub Copilot Chat can provide explanations about a variety of coding-related topics:
- Open the file you need help with in Visual Studio Code.
- Ask GitHub Copilot Chat a question related to the open file. For example, to understand the file’s purpose, ask, “What does the file do?” For unit test generation, highlight the relevant code and ask, “Write a unit test for the code.” For bug fixes, simply request, “Fix the bug.”
Related content: Read our guide to GitHub copilot pricing (coming soon)
Complementing GitHub Copilot with Swimm
GitHub Copilot Business provides basic responses to developer inquiries, sourcing its context exclusively from the code editor. GitHub Copilot Enterprise offers more nuanced conversations by integrating customization from your own repositories. However, Copilot’s context remains confined to code, which doesn’t encompass the entire narrative.
Swimm, on the other hand, integrates a wide range of organizational knowledge sources, ensuring highly precise and relevant answers.