study-interface / llm_check.py
Rachel Kim
first commit
0793785
Raw History Blame Contribute Delete
943 Bytes
import yaml
import openai
import os
from dotenv import load_dotenv
load_dotenv()
def main():
with open("config.yaml", "r") as f:
data = yaml.safe_load(f)
models = data['models']
for i, model in enumerate(models):
try:
client = openai.OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENROUTER_API_KEY")
)
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "Hi"}],
timeout=60,
max_tokens=20
)
except openai.APITimeoutError:
print(f"Error: Request timed out after 60 seconds")
continue
except Exception as e:
print(f"{model} Error: {str(e)}")
continue
print(f"{i} Success: {model}")
if __name__ == '__main__':
main()