1+ import os
2+
13import requests
24
5+ GITHUB_API_BASE = os .environ .get ("ICLAW_GITHUB_API_BASE" , "https://api.github.com" )
6+ COPILOT_API_BASE = os .environ .get (
7+ "ICLAW_COPILOT_API_BASE" , "https://api.githubcopilot.com"
8+ )
9+
310COPILOT_HEADERS = {
411 "Content-Type" : "application/json" ,
512 "Editor-Version" : "vscode/1.85.0" ,
1118
1219def get_copilot_token (github_token ):
1320 resp = requests .get (
14- "https://api.github.com /copilot_internal/v2/token" ,
21+ f" { GITHUB_API_BASE } /copilot_internal/v2/token" ,
1522 headers = {
1623 "Authorization" : f"Bearer { github_token } " ,
1724 "Editor-Version" : "vscode/1.85.0" ,
@@ -28,7 +35,7 @@ def get_copilot_token(github_token):
2835
2936def get_models (copilot_token ):
3037 resp = requests .get (
31- "https://api.githubcopilot.com /models" ,
38+ f" { COPILOT_API_BASE } /models" ,
3239 headers = {"Authorization" : f"Bearer { copilot_token } " , ** COPILOT_HEADERS },
3340 )
3441 if not resp .ok :
@@ -40,9 +47,9 @@ def chat(messages, copilot_token, model="gpt-4o", tools=None):
4047 payload = {"model" : model , "messages" : messages , "stream" : False }
4148 if tools :
4249 payload ["tools" ] = tools
43-
50+
4451 resp = requests .post (
45- "https://api.githubcopilot.com /chat/completions" ,
52+ f" { COPILOT_API_BASE } /chat/completions" ,
4653 headers = {"Authorization" : f"Bearer { copilot_token } " , ** COPILOT_HEADERS },
4754 json = payload ,
4855 )
0 commit comments