Skip to content

Commit e31ff57

Browse files
committed
feat: allow environment variables for config and API base URLs
1 parent 99a0cab commit e31ff57

5 files changed

Lines changed: 514 additions & 5 deletions

File tree

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
source = iclaw
3+
parallel = true

iclaw/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
import os
23
from pathlib import Path
34

4-
CONFIG_PATH = Path.home() / ".config" / "iclaw" / "config.json"
5+
_default_config = Path.home() / ".config" / "iclaw" / "config.json"
6+
CONFIG_PATH = Path(os.environ.get("ICLAW_CONFIG_PATH", str(_default_config)))
57
TOKEN_REFRESH_INTERVAL = 24 * 60 # seconds
68

79

iclaw/github_api.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import os
2+
13
import 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+
310
COPILOT_HEADERS = {
411
"Content-Type": "application/json",
512
"Editor-Version": "vscode/1.85.0",
@@ -11,7 +18,7 @@
1118

1219
def 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

2936
def 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

Comments
 (0)