Files

81 lines
2.5 KiB
Python

import httpx, json, re, subprocess
# Add tokens to env
with open("/etc/litellm/.env", "a") as f:
f.write("GITHUB_TOKEN_1=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\n")
f.write("GITHUB_TOKEN_2=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\n")
f.write("GITHUB_TOKEN_3=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\n")
print("Tokens added to .env")
# Test each GitHub token
tokens = [
"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",
"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",
"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",
]
for i, token in enumerate(tokens, 1):
try:
r = httpx.post(
"https://models.inference.ai.azure.com/chat/completions",
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
json={"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "hai"}], "max_tokens": 10},
timeout=15
)
if r.status_code == 200:
content = r.json()["choices"][0]["message"]["content"]
print(f"✅ GitHub {i}: {content[:50]}")
else:
print(f"❌ GitHub {i}: HTTP {r.status_code} - {r.text[:80]}")
except Exception as e:
print(f"❌ GitHub {i}: {str(e)[:60]}")
# Now add GitHub providers to proxy script
with open("/opt/ai-proxy/proxy.py") as f:
code = f.read()
# Add github providers after openrouter-3 section
github_block = '''
{
"name": "github-1",
"client": lambda: AsyncOpenAI(
api_key=os.getenv("GITHUB_TOKEN_1"),
base_url="https://models.inference.ai.azure.com"
),
"models": ["gpt-4o-mini", "gpt-4o"],
"priority": 4,
},
{
"name": "github-2",
"client": lambda: AsyncOpenAI(
api_key=os.getenv("GITHUB_TOKEN_2"),
base_url="https://models.inference.ai.azure.com"
),
"models": ["gpt-4o-mini"],
"priority": 5,
},
{
"name": "github-3",
"client": lambda: AsyncOpenAI(
api_key=os.getenv("GITHUB_TOKEN_3"),
base_url="https://models.inference.ai.azure.com"
),
"models": ["gpt-4o-mini"],
"priority": 6,
},'''
# Insert after openrouter-3 (after priority 3)
code = code.replace(
' "priority": 3,\n },',
' "priority": 3,\n },' + github_block
)
with open("/opt/ai-proxy/proxy.py", "w") as f:
f.write(code)
print("GitHub providers added to proxy!")
subprocess.run(["systemctl", "restart", "ai-proxy"], capture_output=True)
print("Proxy restarted!")