-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_openrouter.py
More file actions
62 lines (53 loc) · 1.82 KB
/
Copy pathverify_openrouter.py
File metadata and controls
62 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
API_KEY = os.getenv("OPENROUTER_API_KEY")
BASE_URL = "https://openrouter.ai/api/v1"
if not API_KEY:
print("❌ Error: OPENROUTER_API_KEY not found in environment.")
exit(1)
client = OpenAI(
base_url=BASE_URL,
api_key=API_KEY,
default_headers={
"HTTP-Referer": "http://localhost:5173",
"X-Title": "MultiModalDocIntel"
}
)
models = [
"deepseek/deepseek-r1:free",
"deepseek/deepseek-chat:free",
"qwen/qwen-2.5-coder-32b-instruct:free",
"meta-llama/llama-3.2-11b-vision-instruct:free",
"google/gemini-2.0-pro-exp-02-05:free",
"google/gemini-exp-1206:free",
"gryphe/mythomax-l2-13b:free"
]
print("--- Testing OpenRouter Models ---")
for model in models:
print(f"\nTesting {model}...")
try:
# Try simple Text first
completion = client.chat.completions.create(
model=model,
messages=[
{"role": "user", "content": "Return simple JSON: {\"status\": \"ok\"}"}
],
)
print(f"✅ Text Success! Content: {completion.choices[0].message.content[:50]}...")
# Try JSON Mode
try:
completion = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "Output JSON only."},
{"role": "user", "content": "Return simple JSON: {\"status\": \"ok\"}"}
],
response_format={"type": "json_object"}
)
print(f"✅ JSON Mode Success!")
except Exception as json_err:
print(f"⚠️ JSON Mode Failed: {json_err}")
except Exception as e:
print(f"❌ Failed: {e}")