/ debug_openrouter.py
debug_openrouter.py
 1  #!/usr/bin/env python3
 2  import os
 3  import requests
 4  import json
 5  
 6  print("🔍 DEBUGGING OPENROUTER RESPONSES")
 7  print("="*60)
 8  
 9  key = os.getenv('OPENROUTER_API_KEY')
10  url = "https://openrouter.ai/api/v1/chat/completions"
11  
12  test_queries = [
13      "What is the capital of France?",
14      "Say 'Paris'",
15      "Answer with just one word: What is the capital of France?"
16  ]
17  
18  headers = {
19      "Authorization": f"Bearer {key}",
20      "Content-Type": "application/json",
21      "HTTP-Referer": "https://github.com/ai-orchestrator",
22      "X-Title": "AI Debugger"
23  }
24  
25  for i, query in enumerate(test_queries, 1):
26      print(f"\nTest {i}: '{query}'")
27      
28      # Test different prompting strategies
29      prompts = [
30          # Strategy 1: Simple
31          [{"role": "user", "content": query}],
32          
33          # Strategy 2: With system prompt
34          [
35              {"role": "system", "content": "You are a helpful assistant. Provide direct, concise answers."},
36              {"role": "user", "content": query}
37          ],
38          
39          # Strategy 3: Explicit instruction
40          [
41              {"role": "system", "content": "Answer questions directly without any additional formatting or explanation."},
42              {"role": "user", "content": query}
43          ]
44      ]
45      
46      for j, messages in enumerate(prompts, 1):
47          data = {
48              "model": "mistralai/mistral-7b-instruct:free",
49              "messages": messages,
50              "max_tokens": 50,
51              "temperature": 0.1  # Low temperature for deterministic responses
52          }
53          
54          try:
55              response = requests.post(url, headers=headers, json=data, timeout=10)
56              if response.status_code == 200:
57                  result = response.json()
58                  answer = result['choices'][0]['message']['content']
59                  print(f"  Strategy {j}: '{answer}' (len={len(answer)})")
60              else:
61                  print(f"  Strategy {j}: Error {response.status_code}")
62          except Exception as e:
63              print(f"  Strategy {j}: Exception - {str(e)[:50]}")