Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Build a GitHub Copilot Extension in Python

draft: true
cascade:
draft: true

minutes_to_complete: 20

who_is_this_for: This is an introductory topic for software developers who want to learn how to build a simple GitHub Copilot Extension.

learning_objectives:
- Create a simple GitHub Copilot Extension in Python.
- Use ngrok to expose the extension to Copilot.
- Add a GitHub App to your GitHub account and use your Copilot Extension.

prerequisites:
- A GitHub account.
- A Linux computer with Python installed.

author_primary: Jason Andrews

### Tags
skilllevels: Introductory
subjects: ML
armips:
- Neoverse
tools_software_languages:
- Python
- GitHub
operatingsystems:
- Linux


### FIXED, DO NOT MODIFY
# ================================================================================
weight: 1 # _index.md always has weight of 1 to order correctly
layout: "learningpathall" # All files under learning paths have this same wrapper
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---

further_reading:
- resource:
title: GitHub Marketplace for Copilot extensions
link: https://github.com/marketplace?type=apps&copilot_app=true/
type: website
- resource:
title: About building Copilot Extensions
link: https://docs.github.com/en/copilot/building-copilot-extensions/about-building-copilot-extensions/
type: documentation
- resource:
title: Copilot Extensions repository
link: https://github.com/copilot-extensions/
type: documentation


# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================
weight: 21 # set to always be larger than the content in this path, and one more than 'review'
title: "Next Steps" # Always the same
layout: "learningpathall" # All files under learning paths have this same wrapper
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Learn about GitHub Copilot Extensions
weight: 2

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## What are GitHub Copilot Extensions?

Copilot Extensions provide an integration point to expand the functionality of Copilot chat, allowing developers to introduce external tools, services, and custom behaviors into the chat experience.

You can use an extension to customize the capabilities of Copilot in a variety of ways. Some examples include targeting Copilot for a specific type of user, such as an Arm software developer, by querying specific documentation or prioritizing responses for the developers environment. Copilot Extensions can also integrate additional LLMs, use different APIs, and connect to other AI tools that are not used by Copilot.

A Copilot Extension allows you to build curated experiences that are targeted for specific developer topics.

Think about what you want to offer, or build for yourself, that is beyond or better than what Copilot can already do. If you have ideas, you can try them using a Copilot Extension.

Extensions can be private, public, or shared in the GitHub Marketplace.

This Learning Path is a "hello world" tutorial for a simple extension in Python. It explains how to create a private extension by running Python on a Linux computer, using ngrok to expose the endpoint, and creating a GitHub App to configure the extension in your GitHub account. After this, you can invoke your private extension from GitHub chat.

## How do I get started with GitHub Copilot?

Before building an extension, make sure Copilot is configured and working in your GitHub account.

Refer to the [Quickstart for GitHub Copilot](https://docs.github.com/en/copilot/quickstart) to get started.

You can use [GitHub Copilot free](https://github.com/features/copilot?utm_source=topcopilotfree&utm_medium=blog&utm_campaign=launch) with no cost (subject to usage limits).

## How do I invoke GitHub Copilot Extensions?

You can use extensions on any platform where Copilot chat can be used. This includes the GitHub website, various IDEs, and the command line.

Extensions are invoked using `@` followed by the name of the extension. For example, the [Arm extension for GitHub Copilot](https://github.com/marketplace/arm-for-github-copilot) is invoked using `@arm` in the chat.

You can install the Arm extension from the GitHub marketplace and practice using `@arm` to invoke it. Information about how to use it is in the [Arm for GitHub Copilot repository](https://github.com/arm/copilot-extension).

Continue to learn how to create your own extension using Python.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: Test your Copilot Extension
weight: 6

### FIXED, DO NOT MODIFY
layout: learningpathall
---

You are now ready to test your GitHub Copilot extension.

Go to any of the Copilot chat interfaces you are currently using, such as browser or VS Code.

Enter `@your-extension` and a test prompt such as:

```console
tell me about Java vs Python
```

On the first prompt, you get an authorization dialog to enable your extension.

Confirming the authorization takes you to an ngrok page in the browser, click the button and you will see the message from the GET request from your Python server in the browser:

```output
Hello! Welcome to the example GitHub Copilot Extension in Python!
```

You see the extension invoked in the terminal where Python is running and information about the chat printed:

```output
127.0.0.1 - - [31/Jan/2025 23:33:18] "POST / HTTP/1.1" 200 -
User: jasonrandrews
Payload: {'copilot_thread_id': 'eceb9ea8-70a1-4a75-93b6-9096db87c4c6', 'messages': [{'role': 'user', 'content': '@jasonrandrews-cp tell me about Java vs Python', 'copilot_references': [], 'copilot_confirmations': None}, {'role': 'assistant', 'content': "@jasonrandrews Java and Python are both popular programming languages used for different purposes. Here are some key differences between the two:\n\n1. Syntax: Java has a more verbose syntax with strict rules, whereas Python has a more concise and readable syntax. Python's syntax is considered more beginner-friendly.\n\n2. Typing: Java is a statically-typed language, which means you need to declare the type of a variable before using it. Python, on the other hand, is dynamically-typed, allowing you to change the type of a variable during runtime.\n\n3. Performance: Java is typically faster than Python because it is a compiled language, while Python is an interpreted language. However, Python has many libraries and frameworks that leverage lower-level languages like C to improve performance.\n\n4. Application domains: Java is commonly used for building enterprise-level applications, Android apps, and large-scale systems due to its performance and robustness. Python is often used for web development, data analysis, scientific computing, and scripting due to its simplicity and extensive libraries.\n\n5. Community and ecosystem: Both Java and Python have vibrant communities and extensive libraries and frameworks. However, Java has been around longer, resulting in a larger ecosystem and support for enterprise development.\n\nUltimately, the choice between Java and Python depends on your specific needs, the type of application you are building, and personal preference. Both languages have their strengths and weaknesses, and it's worth considering the requirements of your project and your familiarity with each language.", 'copilot_references': [], 'copilot_confirmations': None}, {'role': 'user', 'content': "Current Date and Time (UTC - YYYY-MM-DD HH:MM:SS formatted): 2025-01-31 23:33:54\nCurrent User's Login: jasonrandrews\n", 'name': '_session', 'copilot_references': [{'type': 'github.current-url', 'data': {'url': 'https://github.com/jasonrandrews/arm-learning-paths'}, 'id': 'https://github.com/jasonrandrews/arm-learning-paths', 'is_implicit': True, 'metadata': {'display_name': 'https://github.com/jasonrandrews/arm-learning-paths', 'display_icon': '', 'display_url': ''}}], 'copilot_confirmations': None}, {'role': 'user', 'content': 'how do I install the aws cli on Arm Linux?', 'copilot_references': [], 'copilot_confirmations': []}], 'stop': None, 'top_p': 0, 'temperature': 0, 'max_tokens': 0, 'presence_penalty': 0, 'frequency_penalty': 0, 'response_format': None, 'copilot_skills': None, 'agent': 'jasonrandrews-cp', 'client_id': 'Iv23liSj0dAnWIBmCjzi', 'tools': [], 'functions': None, 'model': ''}
```

You also see HTTP requests on the terminal where ngrok is running.

```output
23:33:18.042 UTC POST / 200 OK
23:33:00.991 UTC GET / 200 OK
```

Lastly, the chat output from your extension is printed. Here it is in VS Code:

![#Copilot output](_images/output.png)

Your GitHub Copilot Extension is now responding to chat prompts. You have the basic structure to build more interesting Copilot Extensions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Configure GitHub app
weight: 5

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## How do I connect my Copilot extension to my GitHub account?

Create a GitHub App to connect your Python extension to your GitHub account.

Click on your photo in the upper-right corner of GitHub and select `Settings`.

Scroll to the bottom left and select `Developer settings`.

### Create a new GitHub App

Select the `GitHub Apps` on the left slide and click `New GitHub App`.

![#New GitHub App](_images/gh-cp1.png)

The important fields to complete or modify are listed below.

| Field | Description |
|------|-------------|
| GitHub App Name | This can be any name, but it must be unique across all of GitHub. This is also the name you will use to invoke your extension in Copilot using the `@name` syntax. One way to avoid conflicts is to use your GitHub handle as the name or add some text to your handle, such as `@jasonrandrews-cp`. |
| Homepage URL | This needs to be filled in but is not used for a private extension, any URL can be entered such as https://learn.arm.com |
| Callback URL | Enter the URL of your ngrok domain such as `https://your-domain.ngrok-free.app` (substitute your domain). |
| Webhook | Uncheck the `Active` box. |
| Permissions | Select `Account permissions` and set the `GitHub Copilot Chat` and `GitHub Copilot Chat` to `Read-only`. |
| Where can this GitHub App be installed? | Confirm `Only this account` is selected to make the GitHub App only for your use. |

Click the `Create GitHub App` to save the configuration.

![#Create GitHub App](_images/gh-cp2.png)

### Configure the Copilot settings

### Configure the Copilot settings

Click on the left side Copilot sidebar.

Modify and update the following fields:

| Step | Description |
|------|-------------|
| 1. Set the App Type | Set the `App Type` to `Agent`. |
| 2. Agent Definition | Enter your ngrok URL in the URL box, such as `https://your-domain.ngrok-free.app`. |
| 3. Interface Description | Any text can be added. |


The Copilot settings are shown below:

![#Copilot configuration](_images/gh-cp3.png)

Click the `Save` button when the information is entered.

### Install your GitHub App

When the GitHub App has been configured and save, install it into your account using the `Install App` tab on the left site and the `Install` button.

You may need to agree to install the GitHub App in your account.

Once installed, you see the App in your account's [Applications](https://github.com/settings/installations)

Your GitHub App is now ready to use with Copilot.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Start ngrok to serve the extension
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## How can I connect my Python extension with GitHub Copilot?

For development, you can use [ngrok](https://ngrok.com/) to connect your extension to Copilot.

ngrok is a tool that creates a secure tunnel to your localhost, allowing you to expose a local server to the internet. This is useful for testing and development purposes.

## How do I install and configure ngrok?

Follow the steps below to set up ngrok.

### Download and install ngrok

If needed, create a new account.

Refer to the [Setup & installation](https://dashboard.ngrok.com/get-started/setup/linux) section for installation details.

If you are using a Debian based Linux system, run the command:

```console
curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \
&& echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
| sudo tee /etc/apt/sources.list.d/ngrok.list \
&& sudo apt update \
&& sudo apt install ngrok
```

### Configure your ngrok account

Before starting the ngrok server, you need an Authtoken. If you don't currently have one, create a new Authtoken from the [Authtoken](https://dashboard.ngrok.com/get-started/your-authtoken) settings.

Once you have the token, add it to the Linux computer where you are running your Python extension.

Substitute your token in the command below:

```console
ngrok config add-authtoken <your-authtoken>
```

ngrok is easier to use if you create a domain name. Go to the [Domains](https://dashboard.ngrok.com/domains) section and add a new randomly generated domain name. You can create 1 domain name in a free account.

Use the domain name in the next section to start the server.

### Start your local server

In a terminal, run the ngrok command to start the server.

Substitute your domain name in the command below to start the server on port 3000.

```console
ngrok http --domain=your-domain.ngrok-free.app 3000
```

![#Run ngrok](_images/ngrok.png)

In the next section, you will use the public URL of your domain to configure a GitHub App in your GitHub account.
Loading