langchain-githubcopilot-chat 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YIhan Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.1
2
+ Name: langchain-githubcopilot-chat
3
+ Version: 0.3.0
4
+ Summary: An integration package connecting GithubcopilotChat and LangChain
5
+ Home-page: https://github.com/langchain-ai/langchain
6
+ License: MIT
7
+ Author: YIhan Wu
8
+ Author-email: iumm@ibat.ac.cn
9
+ Requires-Python: >=3.10,<4.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Dist: httpx (>=0.28.1)
17
+ Requires-Dist: langchain-core (>=1.1.0,<2.0.0)
18
+ Project-URL: Repository, https://github.com/langchain-ai/langchain
19
+ Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22githubcopilot-chat%3D%3D0%22&expanded=true
20
+ Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/githubcopilot-chat
21
+ Description-Content-Type: text/markdown
22
+
23
+ # LangChain GitHub Copilot Chat
24
+
25
+ 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.
26
+
27
+ 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.
28
+
29
+ ## 🚀 Features
30
+
31
+ - **Real Copilot API**: Connects to `api.githubcopilot.com` using official VS Code headers.
32
+ - **Easy Auth**: Built-in GitHub Device Flow for acquiring a valid Copilot Token.
33
+ - **Model Discovery**: Dynamic fetching of all models authorized for your account.
34
+ - **LangChain Native**: Full support for Streaming, Tool Calling, and Async operations.
35
+
36
+ ## 📦 Installation
37
+
38
+ ```bash
39
+ pip install -U langchain-githubcopilot-chat
40
+ ```
41
+
42
+ ## 🔐 Authentication
43
+
44
+ To use GitHub Copilot, you need a valid Copilot Token. You can obtain one interactively using the built-in helper:
45
+
46
+ ```python
47
+ from langchain_githubcopilot_chat import get_vscode_token
48
+
49
+ # This will prompt you to visit a GitHub URL and enter a code
50
+ token = get_vscode_token()
51
+ print(f"Your Token: {token}")
52
+ ```
53
+
54
+ For custom output handling (e.g., in GUI applications), pass a callback:
55
+
56
+ ```python
57
+ from langchain_githubcopilot_chat import get_copilot_token
58
+
59
+ def on_message(msg):
60
+ # Handle status messages (e.g., display in UI)
61
+ print(f"[Copilot] {msg}")
62
+
63
+ token = get_vscode_token(callback=on_message)
64
+ ```
65
+
66
+ Alternatively, set it as an environment variable:
67
+ ```bash
68
+ export GITHUB_TOKEN="your_copilot_token_here"
69
+ ```
70
+
71
+ ## 🛠 Usage
72
+
73
+ ### Chat Models
74
+
75
+ Access any model supported by Copilot (e.g., `gpt-4o`, `gpt-4o-mini`, `claude-3.5-sonnet`).
76
+
77
+ ```python
78
+ from langchain_githubcopilot_chat import ChatGithubCopilot
79
+
80
+ # Initialize with a specific model
81
+ llm = ChatGithubCopilot(
82
+ model="gpt-4o",
83
+ temperature=0.7
84
+ )
85
+
86
+ # Simple invocation
87
+ response = llm.invoke("Explain Quantum Entanglement in one sentence.")
88
+ print(response.content)
89
+
90
+ # Streaming
91
+ for chunk in llm.stream("Write a short poem about coding."):
92
+ print(chunk.content, end="", flush=True)
93
+ ```
94
+
95
+ ### Discovery Available Models
96
+
97
+ GitHub Copilot periodically updates its available models. You can list what's currently available for your token:
98
+
99
+ ```python
100
+ from langchain_githubcopilot_chat import get_available_models
101
+
102
+ models = get_available_models()
103
+ for model in models:
104
+ print(f"ID: {model['id']} - Name: {model.get('name')}")
105
+ ```
106
+
107
+ ### Embeddings
108
+
109
+ Use Copilot's embedding models for RAG or semantic search:
110
+
111
+ ```python
112
+ from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
113
+
114
+ embeddings = GithubcopilotChatEmbeddings(model="text-embedding-3-small")
115
+ vector = embeddings.embed_query("GitHub Copilot is awesome!")
116
+ ```
117
+
118
+ ## 📖 Advanced: Tool Calling
119
+
120
+ ```python
121
+ from pydantic import BaseModel, Field
122
+ from langchain_githubcopilot_chat import ChatGithubCopilot
123
+
124
+ class GetWeather(BaseModel):
125
+ """Get the current weather in a given location."""
126
+ location: str = Field(..., description="The city and state, e.g. San Francisco, CA")
127
+
128
+ llm = ChatGithubCopilot(model="gpt-4o")
129
+ llm_with_tools = llm.bind_tools([GetWeather])
130
+
131
+ ai_msg = llm_with_tools.invoke("What's the weather like in Tokyo?")
132
+ print(ai_msg.tool_calls)
133
+ ```
134
+
135
+ ## ⚖️ Disclaimer
136
+
137
+ 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](https://docs.github.com/en/site-policy/github-terms/github-terms-of-service).
@@ -0,0 +1,115 @@
1
+ # LangChain GitHub Copilot Chat
2
+
3
+ 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.
4
+
5
+ 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.
6
+
7
+ ## 🚀 Features
8
+
9
+ - **Real Copilot API**: Connects to `api.githubcopilot.com` using official VS Code headers.
10
+ - **Easy Auth**: Built-in GitHub Device Flow for acquiring a valid Copilot Token.
11
+ - **Model Discovery**: Dynamic fetching of all models authorized for your account.
12
+ - **LangChain Native**: Full support for Streaming, Tool Calling, and Async operations.
13
+
14
+ ## 📦 Installation
15
+
16
+ ```bash
17
+ pip install -U langchain-githubcopilot-chat
18
+ ```
19
+
20
+ ## 🔐 Authentication
21
+
22
+ To use GitHub Copilot, you need a valid Copilot Token. You can obtain one interactively using the built-in helper:
23
+
24
+ ```python
25
+ from langchain_githubcopilot_chat import get_vscode_token
26
+
27
+ # This will prompt you to visit a GitHub URL and enter a code
28
+ token = get_vscode_token()
29
+ print(f"Your Token: {token}")
30
+ ```
31
+
32
+ For custom output handling (e.g., in GUI applications), pass a callback:
33
+
34
+ ```python
35
+ from langchain_githubcopilot_chat import get_copilot_token
36
+
37
+ def on_message(msg):
38
+ # Handle status messages (e.g., display in UI)
39
+ print(f"[Copilot] {msg}")
40
+
41
+ token = get_vscode_token(callback=on_message)
42
+ ```
43
+
44
+ Alternatively, set it as an environment variable:
45
+ ```bash
46
+ export GITHUB_TOKEN="your_copilot_token_here"
47
+ ```
48
+
49
+ ## 🛠 Usage
50
+
51
+ ### Chat Models
52
+
53
+ Access any model supported by Copilot (e.g., `gpt-4o`, `gpt-4o-mini`, `claude-3.5-sonnet`).
54
+
55
+ ```python
56
+ from langchain_githubcopilot_chat import ChatGithubCopilot
57
+
58
+ # Initialize with a specific model
59
+ llm = ChatGithubCopilot(
60
+ model="gpt-4o",
61
+ temperature=0.7
62
+ )
63
+
64
+ # Simple invocation
65
+ response = llm.invoke("Explain Quantum Entanglement in one sentence.")
66
+ print(response.content)
67
+
68
+ # Streaming
69
+ for chunk in llm.stream("Write a short poem about coding."):
70
+ print(chunk.content, end="", flush=True)
71
+ ```
72
+
73
+ ### Discovery Available Models
74
+
75
+ GitHub Copilot periodically updates its available models. You can list what's currently available for your token:
76
+
77
+ ```python
78
+ from langchain_githubcopilot_chat import get_available_models
79
+
80
+ models = get_available_models()
81
+ for model in models:
82
+ print(f"ID: {model['id']} - Name: {model.get('name')}")
83
+ ```
84
+
85
+ ### Embeddings
86
+
87
+ Use Copilot's embedding models for RAG or semantic search:
88
+
89
+ ```python
90
+ from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
91
+
92
+ embeddings = GithubcopilotChatEmbeddings(model="text-embedding-3-small")
93
+ vector = embeddings.embed_query("GitHub Copilot is awesome!")
94
+ ```
95
+
96
+ ## 📖 Advanced: Tool Calling
97
+
98
+ ```python
99
+ from pydantic import BaseModel, Field
100
+ from langchain_githubcopilot_chat import ChatGithubCopilot
101
+
102
+ class GetWeather(BaseModel):
103
+ """Get the current weather in a given location."""
104
+ location: str = Field(..., description="The city and state, e.g. San Francisco, CA")
105
+
106
+ llm = ChatGithubCopilot(model="gpt-4o")
107
+ llm_with_tools = llm.bind_tools([GetWeather])
108
+
109
+ ai_msg = llm_with_tools.invoke("What's the weather like in Tokyo?")
110
+ print(ai_msg.tool_calls)
111
+ ```
112
+
113
+ ## ⚖️ Disclaimer
114
+
115
+ 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](https://docs.github.com/en/site-policy/github-terms/github-terms-of-service).
@@ -1,12 +1,14 @@
1
1
  import time
2
- from typing import Optional
2
+ from typing import Callable, Optional
3
3
 
4
4
  import httpx
5
5
 
6
6
  CLIENT_ID = "Iv1.b507a08c87ecfe98"
7
7
 
8
8
 
9
- def get_copilot_token(client_id: str = CLIENT_ID) -> Optional[str]:
9
+ def get_copilot_token(
10
+ client_id: str = CLIENT_ID, callback: Optional[Callable[[str], None]] = None
11
+ ) -> Optional[str]:
10
12
  """
11
13
  Authenticate via GitHub Device Flow to get a Copilot Token.
12
14
  This function will block and wait for the user to complete the
@@ -15,11 +17,20 @@ def get_copilot_token(client_id: str = CLIENT_ID) -> Optional[str]:
15
17
  Args:
16
18
  client_id: The GitHub OAuth App Client ID to use. Defaults
17
19
  to the VS Code Copilot Chat client ID.
20
+ callback: Optional callable that receives status messages instead of
21
+ printing them. If None, messages are printed to stdout.
18
22
 
19
23
  Returns:
20
24
  The fetched Copilot Token string, or None if authentication failed.
21
25
  """
22
- print("1. Requesting device code from GitHub...") # noqa: T201 # noqa: T201
26
+
27
+ def _print(msg: str) -> None:
28
+ if callback:
29
+ callback(msg)
30
+ else:
31
+ print(msg) # noqa: T201
32
+
33
+ _print("1. Requesting device code from GitHub...")
23
34
  with httpx.Client() as client:
24
35
  res = client.post(
25
36
  "https://github.com/login/device/code",
@@ -34,11 +45,11 @@ def get_copilot_token(client_id: str = CLIENT_ID) -> Optional[str]:
34
45
  verification_uri = data.get("verification_uri")
35
46
  interval = data.get("interval", 5)
36
47
 
37
- print("\n==========================================") # noqa: T201
38
- print(f"Please open your browser to: {verification_uri}") # noqa: T201
39
- print(f"And enter the authorization code: {user_code}") # noqa: T201
40
- print("==========================================\n") # noqa: T201
41
- print(f"Waiting for authorization (checking every {interval} seconds)...") # noqa: T201
48
+ _print("\n==========================================")
49
+ _print(f"Please open your browser to: {verification_uri}")
50
+ _print(f"And enter the authorization code: {user_code}")
51
+ _print("==========================================\n")
52
+ _print(f"Waiting for authorization (checking every {interval} seconds)...")
42
53
 
43
54
  access_token = None
44
55
  with httpx.Client() as client:
@@ -55,14 +66,14 @@ def get_copilot_token(client_id: str = CLIENT_ID) -> Optional[str]:
55
66
 
56
67
  if "access_token" in token_res:
57
68
  access_token = token_res["access_token"]
58
- print( # noqa: T201 # noqa: T201
69
+ _print(
59
70
  "\n✅ Authorization successful! Exchanging for Copilot Token..."
60
71
  )
61
72
  break
62
73
  elif token_res.get("error") == "authorization_pending":
63
74
  time.sleep(interval)
64
75
  else:
65
- print(f"\n❌ Authorization failed: {token_res}") # noqa: T201 # noqa: T201
76
+ _print(f"\n❌ Authorization failed: {token_res}")
66
77
  return None
67
78
 
68
79
  # Exchange the standard access token for a Copilot internal token
@@ -78,8 +89,8 @@ def get_copilot_token(client_id: str = CLIENT_ID) -> Optional[str]:
78
89
 
79
90
  if copilot_res.status_code == 200:
80
91
  copilot_token = copilot_res.json().get("token")
81
- print("🎉 Successfully acquired Copilot Token!") # noqa: T201 # noqa: T201
92
+ _print("🎉 Successfully acquired Copilot Token!")
82
93
  return copilot_token
83
94
  else:
84
- print(f"❌ Failed to acquire Copilot Token: {copilot_res.text}") # noqa: T201 # noqa: T201
95
+ _print(f"❌ Failed to acquire Copilot Token: {copilot_res.text}")
85
96
  return None
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "langchain-githubcopilot-chat"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "An integration package connecting GithubcopilotChat and LangChain"
9
9
  authors = ["YIhan Wu <iumm@ibat.ac.cn>"]
10
10
  readme = "README.md"
@@ -1,69 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: langchain-githubcopilot-chat
3
- Version: 0.2.0
4
- Summary: An integration package connecting GithubcopilotChat and LangChain
5
- Home-page: https://github.com/langchain-ai/langchain
6
- License: MIT
7
- Author: YIhan Wu
8
- Author-email: iumm@ibat.ac.cn
9
- Requires-Python: >=3.10,<4.0
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Programming Language :: Python :: 3.13
16
- Requires-Dist: httpx (>=0.28.1)
17
- Requires-Dist: langchain-core (>=1.1.0,<2.0.0)
18
- Project-URL: Repository, https://github.com/langchain-ai/langchain
19
- Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22githubcopilot-chat%3D%3D0%22&expanded=true
20
- Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/githubcopilot-chat
21
- Description-Content-Type: text/markdown
22
-
23
- # langchain-githubcopilot-chat
24
-
25
- This package contains the LangChain integration with GithubcopilotChat
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install -U langchain-githubcopilot-chat
31
- ```
32
-
33
- And you should configure credentials by setting the following environment variables:
34
-
35
- * TODO: fill this out
36
-
37
- ## Chat Models
38
-
39
- `ChatGithubcopilotChat` class exposes chat models from GithubcopilotChat.
40
-
41
- ```python
42
- from langchain_githubcopilot_chat import ChatGithubcopilotChat
43
-
44
- llm = ChatGithubcopilotChat()
45
- llm.invoke("Sing a ballad of LangChain.")
46
- ```
47
-
48
- ## Embeddings
49
-
50
- `GithubcopilotChatEmbeddings` class exposes embeddings from GithubcopilotChat.
51
-
52
- ```python
53
- from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
54
-
55
- embeddings = GithubcopilotChatEmbeddings()
56
- embeddings.embed_query("What is the meaning of life?")
57
- ```
58
-
59
- ## LLMs
60
-
61
- `GithubcopilotChatLLM` class exposes LLMs from GithubcopilotChat.
62
-
63
- ```python
64
- from langchain_githubcopilot_chat import GithubcopilotChatLLM
65
-
66
- llm = GithubcopilotChatLLM()
67
- llm.invoke("The meaning of life is")
68
- ```
69
-
@@ -1,46 +0,0 @@
1
- # langchain-githubcopilot-chat
2
-
3
- This package contains the LangChain integration with GithubcopilotChat
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pip install -U langchain-githubcopilot-chat
9
- ```
10
-
11
- And you should configure credentials by setting the following environment variables:
12
-
13
- * TODO: fill this out
14
-
15
- ## Chat Models
16
-
17
- `ChatGithubcopilotChat` class exposes chat models from GithubcopilotChat.
18
-
19
- ```python
20
- from langchain_githubcopilot_chat import ChatGithubcopilotChat
21
-
22
- llm = ChatGithubcopilotChat()
23
- llm.invoke("Sing a ballad of LangChain.")
24
- ```
25
-
26
- ## Embeddings
27
-
28
- `GithubcopilotChatEmbeddings` class exposes embeddings from GithubcopilotChat.
29
-
30
- ```python
31
- from langchain_githubcopilot_chat import GithubcopilotChatEmbeddings
32
-
33
- embeddings = GithubcopilotChatEmbeddings()
34
- embeddings.embed_query("What is the meaning of life?")
35
- ```
36
-
37
- ## LLMs
38
-
39
- `GithubcopilotChatLLM` class exposes LLMs from GithubcopilotChat.
40
-
41
- ```python
42
- from langchain_githubcopilot_chat import GithubcopilotChatLLM
43
-
44
- llm = GithubcopilotChatLLM()
45
- llm.invoke("The meaning of life is")
46
- ```