-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.py
More file actions
50 lines (41 loc) · 1.5 KB
/
test_api.py
File metadata and controls
50 lines (41 loc) · 1.5 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
#!/usr/bin/env python3
"""
Quick test script for LLM7.io API
"""
import openai
from dotenv import load_dotenv
import os
load_dotenv()
def test_llm7_api():
"""Test the LLM7.io API directly"""
# Initialize OpenAI client with LLM7.io settings
client = openai.OpenAI(
base_url="https://api.llm7.io/v1",
api_key="unused"
)
print("🧪 Testing LLM7.io API...")
print(f"Base URL: https://api.llm7.io/v1")
print(f"API Key: unused")
try:
# Test with models from the official example
models_to_test = ["gpt-4.1-nano-2025-04-14", "gemini", "mistral-large-2411", "gpt-4"]
for model in models_to_test:
print(f"\n🔄 Testing model: {model}")
try:
response = client.chat.completions.create(
model=model,
messages=[
{"role": "user", "content": "¿Wha is the capital of Spain?"}
]
)
print(f"✅ Model {model} worked!")
print(f"Response: {response.choices[0].message.content}")
break
except Exception as model_error:
print(f"❌ Model {model} failed: {str(model_error)}")
continue
except Exception as e:
print(f"❌ General API error: {str(e)}")
print(f"Error type: {type(e)}")
if __name__ == "__main__":
test_llm7_api()