A Journey into AI Assisted Development with GitHub Copilot
The first ever Experts Live Kenya , Conference in Africa, was nothing short of extraordinary and I am incredibly grateful to have been part of this community gathering of tech enthusiasts exploring Microsoft technologies. As we live in the Era of AI ??, I believe that developers need to embrace AI integrations in the tools they use every day, and learn how to use them to boost their productivity, efficiency and creativity.
I'm thrilled to share my talk on GitHub Copilot with you, comprising of an introduction to GitHub Copilot - what it is, how it works and why you should care, common and unexpected features of GitHub Copilot, Tips and Tricks to get the most out of it, limitations of GitHub Copilot and resources to kick you off on your AI-Assisted development journey ??.
??Lifting Off with GitHub Copilot
What it is ...
With GitHub Copilot, your AI Pair programmer, you can now accomplish programming-related tasks faster and better. Think of GitHub Copilot as a master developer, an expert in programming across multiple languages and frameworks, who is trained on a variety of programming-related problems and solutions, at your disposal to teach and guide you as you build software.
How it works ...
What better way to understand a tool, than to pop the hood ??and see what powers it and how it works right?
At the core of GitHub Copilot lies the OpenAI Codex and GPT-4 transformer-based Large Language Models that power its capabilities. While you interface with copilot, either through your IDE, the CLI, GitHub mobile or github.com , context is collated and used to construct a prompt. The prompt is sent over to the model (encrypted while in transit), but passes through a proxy service which:
i) Sanitizes the prompt ??- dropping Personal Identifiable Information (PII), secrets etc.
ii) Terminates prompts ? with questions unrelated to programming, hack attempts and toxic expressions.
The final prompt is sent to the model, which formulates a response/ suggestion which is then sent back to the user via the proxy service to:
i) Perform a quick code scan ?? and get rid of any obvious bugs/ security vulnerabilities
ii) Run the response through the Duplicate Detection Filter to discard any code that matches public code.
More on the Duplicate Detection Filter ...
Have you ever gotten such a response while working with GitHub Copilot?
Before the suggestion formulated by the model is shown to you, the suggestion and it's surrounding of about 150 characters is ran against the full index of copilot's training dataset (code from public repositories), and if there is an exact or near match, then the suggestion will not be shown to you. This rarely happens but in case it does, try providing more context to GitHub Copilot to formulate a more relevant and customized suggestion for you. (We'll touch more on context further below)
??Charting the Course: Copilot’s Features
There are several approaches to interacting with GitHub Copilot, each approach offering a set of functionalities to get you writing code as fast as possible and in the most optimal way. Let's look at a few examples of the common use cases of Copilot:
Direct Code writing
You can use comments to quickly invoke copilot for quick assistance on code snippets/ commonly used functions, following standard patterns.
In-Depth technical assistance via copilot chat
Through the GitHub Copilot chat approach, you can expound more on your prompts through a conversational interface, and copilot temporarily stores your prompts and context to allow you to build on top of an existing chat.
Code refactoring
GitHub Copilot helps you improve quality of your code, by using more meaningful variable/ function names, adding comments, to make it more readable and understandable.
Writing tests
GitHub Copilot is useful for generating test cases based on your code, greatly speeding up your development process.
Generating commit messages
GitHub Copilot analyzes your local changes and generates meaningful commit messages, ensuring clear communication on your work for an improved collaboration experience within your team.
Interacting with your repository using natural language
领英推荐
You can use copilot directly on github.com , indexing a specific repository, allowing you to use natural language for queries related to that project.
Generating PR descriptions
With copilot, you can significantly improve your contributions by writing comprehensive and clear descriptions for your Pull Requests. The quality of your PR description directly influences the quality of the feedback you receive during code reviews. Think of PR descriptions as the bridge between your thought process as a contributor and the reviewer's understanding. Copilot analyzes your commits and generates a well-written description with a proper summary of your contributions.
??Navigating like a Pro: Tips and Tricks
Now that you know what GitHub Copilot is and its common use cases, let's take a moment to go through some tips and tricks to get the most out of copilot.
2. Neighboring Tabs. While using Copilot, ensure to open files that are related to what you are working on, or which contain any relevant information to your queries. This is important because the prompt is constructed from the code before and after the position of your cursor and from any open tabs on your editor. This ensures that the most relevant information is sent over to the model to give you the best responses.
3. Providing meaningful names. Normalize giving meaningful names to variables, functions, classes and even files, as these names also inform the prompt.
4. Use of Single-Short-Specific comments. Before you start writing your code, summarize your task at the top of the file in form of a comment to give copilot a goal. Using an overall comment allows copilot to reference the comment every time throughout your project, ensuring that the suggestions are in line with what you are trying to achieve.
5. Leverage Slash commands, participants and variables to write code even faster
Slash commands on GitHub are designed to help you accomplish common use cases without having to spend a lot of time designing prompts. For example, if you highlight a code section and use the /docs command, copilot understands out of the box that you need it to add documentation to that code.
Open GitHub Copilot chat or inline and type / to see the available slash commands.
Participants (or Agents), represented by the @ symbol are used to help narrow down the scope for copilot. For example, say you only want help from Copilot regarding the activities in your terminal, you can use the @terminal participant to only send context from your terminal to Copilot.
Open GitHub Copilot chat or inline and type @ to see the available participants.
Variables are used to pass in data/ values into your chat prompt, allowing you to be even more specific in your context.
Open GitHub Copilot chat or inline and type # to see the available chat variables.
??Turbulence Ahead: Understanding Copilot’s Limitations
?? Landing Smoothly: Wrapping Up Our Journey
Now that you have a proper introduction to GitHub Copilot and its features, now it's time to take action. I strongly recommend taking the free Mastering GitHub Copilot for AI Paired Programming Course by Microsoft, comprising of 8-Lessons that will teach you everything you need to know about harnessing GitHub Copilot. Take the course here ??https://aka.ms/GitHubCopilotAI
To understand more about what copilot can do for your organization, how it handles data, establishing trust in copilot and measuring impact in your organization, check out these articles ?? https://aka.ms/GitHubCopilotEssentials
If you attended my talk, please share feedback via https://aka.ms/ExpertsLiveKE/speaker-feedback . Your feedback will help me improve future deliveries and will be valuable to the event organizers to ensure future events meet your expectations.
Big shout out to the team behind the planning & execution of the Conference ??- You guys are the real heroes!
Joylynn Kirui Margaret Kamau Shadrack Kiprotich, Microsoft MVP Bethany J. Josh Ndemenge Humphrey Muriungi Marjan Hussein Jacklyne Mbuthia Dr. Paula Musuva Tabitha Musya
See you on the next one ??
Founder and CEO at H&A Visions
3 个月Great work????
Software Engineer | Devops
3 个月Great Work!
Forever Curious | Digital Native | Ecosystem Builder | GitOps | K8s
3 个月That's awesome!
Trainee at Microsoft ADC and Garage East Africa
3 个月Great article?? It was awesome working with you??
Digital Marketing Analyst @ Sivantos
3 个月That's awesome to hear! Your article sounds intriguing. AI in coding? Count me in! ???? #InnovativeCoding #AIRevolution Julia Muiruri