File size: 1,103 Bytes
8ed954c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import time
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI

load_dotenv()
api_key = os.getenv("OPENROUTER_API_KEY")

models_to_test = [
    "meta-llama/llama-3.3-70b-instruct:free",
    "nousresearch/hermes-3-llama-3.1-405b:free",
    "mistralai/mistral-small-3.1-24b-instruct:free",
    "qwen/qwen3-coder:free",
    "google/gemma-3-27b-it:free"
]

prompt = "Extract a stock ticker from this text: Apple is launching new iPhones. I am buying AAPL calls tomorrow. Reply only with the ticker."

print("🚀 Starting OpenRouter Free Model Benchmark...\n")

for m in models_to_test:
    print(f"--- Testing {m} ---")
    llm = ChatOpenAI(
        model=m, 
        api_key=api_key,
        base_url="https://openrouter.ai/api/v1",
        temperature=0
    )
    t0 = time.time()
    try:
        res = llm.invoke(prompt)
        elapsed = time.time() - t0
        print(f"✅ Success! Response time: {elapsed:.2f}s")
        print(f"🤖 Output: {res.content.strip()}\n")
    except Exception as e:
        print(f"❌ Failed after {time.time() - t0:.2f}s. Error: {e}\n")