An integration package connecting GithubcopilotChat and LangChain
Project description
LangChain GitHub Copilot Chat
This package provides a LangChain integration for GitHub Copilot, allowing you to use Copilot's models (including GPT-4o, Claude 3.5 Sonnet, etc.) as standard LangChain BaseChatModel components.
Unlike other integrations, this package mimics the official VS Code Copilot Chat extension behavior, providing access to the full suite of models available to Copilot subscribers.
🚀 Features
- Real Copilot API: Connects to
api.githubcopilot.comusing official VS Code headers. - Easy Auth: Built-in GitHub Device Flow for acquiring a valid Copilot Token.
- Model Discovery: Dynamic fetching of all models authorized for your account.
- LangChain Native: Full support for Streaming, Tool Calling, and Async operations.
📦 Installation
pip install -U langchain-githubcopilot-chat
🔐 Authentication
To use GitHub Copilot, you need a valid Copilot Token. You can obtain one interactively using the built-in helper:
from langchain_githubcopilot_chat import get_vscode_token
# This will prompt you to visit a GitHub URL and enter a code
token = get_vscode_token()
print(f"Your Token: {token}")
For custom output handling (e.g., in GUI applications), pass a callback:
from langchain_githubcopilot_chat import get_copilot_token
def on_message(msg):
# Handle status messages (e.g., display in UI)
print(f"[Copilot] {msg}")
token = get_vscode_token(callback=on_message)
Alternatively, set it as an environment variable:
export GITHUB_TOKEN="your_copilot_token_here"
🛠 Usage
Chat Models
Access any model supported by Copilot (e.g., gpt-4o, gpt-4o-mini, claude-3.5-sonnet).
from langchain_githubcopilot_chat import ChatGithubCopilot
# Initialize with a specific model
llm = ChatGithubCopilot(
model="gpt-4o",
temperature=0.7
)
# Simple invocation
response = llm.invoke("Explain Quantum Entanglement in one sentence.")
print(response.content)
# Streaming
for chunk in llm.stream("Write a short poem about coding."):
print(chunk.content, end="", flush=True)
Discovery Available Models
GitHub Copilot periodically updates its available models. You can list what's currently available for your token:
from langchain_githubcopilot_chat import get_available_models
models = get_available_models()
for model in models:
print(f"ID: {model['id']} - Name: {model.get('name')}")
Embeddings
Use Copilot's embedding models for RAG or semantic search:
from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
embeddings = GithubcopilotChatEmbeddings(model="text-embedding-3-small")
vector = embeddings.embed_query("GitHub Copilot is awesome!")
📖 Advanced: Tool Calling
from pydantic import BaseModel, Field
from langchain_githubcopilot_chat import ChatGithubCopilot
class GetWeather(BaseModel):
"""Get the current weather in a given location."""
location: str = Field(..., description="The city and state, e.g. San Francisco, CA")
llm = ChatGithubCopilot(model="gpt-4o")
llm_with_tools = llm.bind_tools([GetWeather])
ai_msg = llm_with_tools.invoke("What's the weather like in Tokyo?")
print(ai_msg.tool_calls)
⚖️ Disclaimer
This project is an independent community integration and is not affiliated with, endorsed by, or supported by GitHub, Inc. Usage of this package must comply with GitHub's Terms of Service.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_githubcopilot_chat-0.5.0.tar.gz.
File metadata
- Download URL: langchain_githubcopilot_chat-0.5.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9796bbcf287febc75c19fa48c4327d1f480c1f105e498b165a464844121da0e9
|
|
| MD5 |
d657b202d0aad58b5889346652f34dc4
|
|
| BLAKE2b-256 |
fa86a3d3b67a90317f7bdce9c72f06ebfa402be259eb1cf74f528614da1bb56a
|
Provenance
The following attestation bundles were made for langchain_githubcopilot_chat-0.5.0.tar.gz:
Publisher:
publish.yml on BANG404/langchain-githubcopilot-chat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_githubcopilot_chat-0.5.0.tar.gz -
Subject digest:
9796bbcf287febc75c19fa48c4327d1f480c1f105e498b165a464844121da0e9 - Sigstore transparency entry: 1142272515
- Sigstore integration time:
-
Permalink:
BANG404/langchain-githubcopilot-chat@4f3f3eae256162a01e0ce41eff6be3521585dd25 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/BANG404
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4f3f3eae256162a01e0ce41eff6be3521585dd25 -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_githubcopilot_chat-0.5.0-py3-none-any.whl.
File metadata
- Download URL: langchain_githubcopilot_chat-0.5.0-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c112a5d6c9cf60b3a630befdb4b211320e3e982a43c8625cc3710e6fb0b5a74
|
|
| MD5 |
a0851a7704823fdac3f386afca0b7b67
|
|
| BLAKE2b-256 |
63a53da3d370656786937961360beb42763f5919dbcbb1edea20e44b84be1557
|
Provenance
The following attestation bundles were made for langchain_githubcopilot_chat-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on BANG404/langchain-githubcopilot-chat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_githubcopilot_chat-0.5.0-py3-none-any.whl -
Subject digest:
4c112a5d6c9cf60b3a630befdb4b211320e3e982a43c8625cc3710e6fb0b5a74 - Sigstore transparency entry: 1142272647
- Sigstore integration time:
-
Permalink:
BANG404/langchain-githubcopilot-chat@4f3f3eae256162a01e0ce41eff6be3521585dd25 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/BANG404
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4f3f3eae256162a01e0ce41eff6be3521585dd25 -
Trigger Event:
release
-
Statement type: