|
|
|
|
|
import requests |
|
import os |
|
|
|
|
|
DEEPSEEK_KEYS = [ |
|
"sk-5b4ecbbd66864a88925525fab14430d1", |
|
"sk-9c216dd03c9945218f12475a0fa6c8c4", |
|
"sk-79f0d8a98b88447880c01d012c572831", |
|
"sk-2be33a5e561b4788b9446e4e4e99bc2e" |
|
] |
|
|
|
OPENAI_KEYS = [ |
|
"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", |
|
"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", |
|
"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", |
|
"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", |
|
"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" |
|
] |
|
|
|
|
|
def try_deepseek(prompt, key): |
|
try: |
|
url = "https://api.deepseek.com/v1/chat/completions" |
|
headers = { |
|
"Authorization": f"Bearer {key}", |
|
"Content-Type": "application/json" |
|
} |
|
data = { |
|
"model": "deepseek-chat", |
|
"messages": [ |
|
{"role": "system", "content": "You are a helpful assistant."}, |
|
{"role": "user", "content": prompt} |
|
] |
|
} |
|
res = requests.post(url, headers=headers, json=data) |
|
result = res.json() |
|
if "choices" in result: |
|
return result["choices"][0]["message"]["content"] |
|
return f"[ERROR] DeepSeek: {result.get('error', {}).get('message', 'Unknown Error')}" |
|
except Exception as e: |
|
return f"[ERROR] DeepSeek Exception: {str(e)}" |
|
|
|
|
|
def try_openai(prompt, key): |
|
try: |
|
url = "https://api.openai.com/v1/chat/completions" |
|
headers = { |
|
"Authorization": f"Bearer {key}", |
|
"Content-Type": "application/json" |
|
} |
|
data = { |
|
"model": "gpt-3.5-turbo", |
|
"messages": [ |
|
{"role": "system", "content": "You are a helpful assistant."}, |
|
{"role": "user", "content": prompt} |
|
] |
|
} |
|
res = requests.post(url, headers=headers, json=data) |
|
result = res.json() |
|
if "choices" in result: |
|
return result["choices"][0]["message"]["content"] |
|
return f"[ERROR] OpenAI: {result.get('error', {}).get('message', 'Unknown Error')}" |
|
except Exception as e: |
|
return f"[ERROR] OpenAI Exception: {str(e)}" |
|
|
|
|
|
|
|
def multi_query(prompt): |
|
for key in DEEPSEEK_KEYS: |
|
output = try_deepseek(prompt, key) |
|
if not output.startswith("[ERROR]"): |
|
return output |
|
|
|
for key in OPENAI_KEYS: |
|
output = try_openai(prompt, key) |
|
if not output.startswith("[ERROR]"): |
|
return output |
|
|
|
return "[ALL APIs FAILED: Out of quota or network error]" |
|
|