Skip to content

A GitHub Copilot plugin for the llm CLI tool

Notifications You must be signed in to change notification settings

cavanaug/llm-github-copilot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI Changelog Tests

llm-github-copilot

A plugin for LLM adding support for GitHub Copilot.

Installation

You can install this plugin using the LLM command-line tool:

llm install llm-github-copilot

Authentication

This plugin uses GitHub's device code authentication flow to obtain the initial access_token. This access_token is what is used to initiate and obtain an api_key that is used for communication with the GitHub Copilot API. This api_key is automatically obtained and refreshed as needed using the access_token. The access_token is obtained from the LLM key storage or via the environment variable GH_COPILOT_TOKEN or GITHUB_COPILOT_TOKEN

Free plan includes up to 2,000 completions and 50 chat requests per month.

Auth Command Help


$ llm github-copilot auth --help
Usage: llm github-copilot auth [OPTIONS] COMMAND [ARGS]...

  Manage GitHub Copilot authentication.

Options:
  --help  Show this message and exit.

Commands:
  login    Authenticate with GitHub Copilot to generate a new access token.
  logout   Remove GitHub Copilot authentication credentials.
  refresh  Force refresh the GitHub Copilot API key.
  status   Check GitHub Copilot authentication status.

Authentication Login

When you run the login command, the plugin will:

  1. Start the GitHub device code authentication flow
  2. Provide you with a code and URL to visit
  3. Wait for you to authenticate on GitHub's website
  4. Generate and store an access token
  5. Fetch an API key using the access token

Example login output:

Usage: llm github-copilot auth login [OPTIONS]

  Authenticate with GitHub Copilot to generate a new access token.

Options:
  -f, --force  Force login even if already authenticated
  --help       Show this message and exit.
$ llm github-copilot auth login
Starting GitHub Copilot authentication to generate a new access token...
Please visit https://github.com/login/device and enter code XXXX-XXXX to authenticate GitHub Copilot.

Waiting for authorization... (attempt 1/12)
Authentication successful!

You can force a new login and obtain a new access_token even if already authenticated:

llm github-copilot auth login --force

Authentication Status

You can check your authentication status with:

$ llm github-copilot auth status
GitHub Copilot authentication: ✓ Authenticated

For more detailed information, use the verbose flag:

$ llm github-copilot auth status --verbose
GitHub Copilot authentication: ✓ Authenticated
Access token: ghu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (from LLM key storage)
API key expires: 2025-04-14 12:34:56
API key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Usage

Once installed, you can use GitHub Copilot models with the llm command:

# Chat with GitHub Copilot
llm -m github-copilot "Write a Python function that calculates the Fibonacci sequence."

# Specify options like length
llm -m github-copilot "Tell me a joke" -o max_tokens 100

Options

The GitHub Copilot plugin supports the following options:

  • max_tokens: Maximum number of tokens to generate (default: 1024)
  • temperature: Controls randomness in the output (default: 0.7)

Development

To develop this plugin:

# Clone the repository
git clone https://github.com/yourusername/llm-github-copilot.git
cd llm-github-copilot

# Install in development mode
llm install -e .

Testing

To run the tests:

# Install test dependencies
pip install -e ".[test]"

# Run tests
pytest

If you want to record new VCR cassettes for tests, set your API key:

export PYTEST_GITHUB_COPILOT_API_KEY=your_api_key_here
pytest --vcr-record=new_episodes

About

A GitHub Copilot plugin for the llm CLI tool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%