File size: 1,313 Bytes
88e9276
52de7b8
 
 
97a67c2
 
6024016
97a67c2
52de7b8
97a67c2
52de7b8
97a67c2
52de7b8
 
 
97a67c2
52de7b8
 
 
97a67c2
 
52de7b8
 
 
88e9276
 
 
 
 
 
 
 
97a67c2
52de7b8
 
88e9276
97a67c2
88e9276
52de7b8
97a67c2
52de7b8
 
97a67c2
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
# multi_inference.py (Groq-only version with error handling)

import requests

# === HARDCODED GROQ KEY ===
GROQ_API_KEY = "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"  # ✅ Active key

def try_groq(prompt):
    try:
        url = "https://api.groq.com/openai/v1/chat/completions"
        headers = {
            "Authorization": f"Bearer {GROQ_API_KEY}",
            "Content-Type": "application/json"
        }
        data = {
            "model": "llama3-70b-8192",
            "messages": [
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt}
            ],
            "temperature": 0.7
        }

        res = requests.post(url, headers=headers, json=data)

        if res.status_code != 200:
            return f"[ERROR] Groq HTTP {res.status_code}: {res.text}"

        try:
            result = res.json()
        except Exception:
            return "[ERROR] Groq returned invalid JSON"

        if "choices" in result:
            return result["choices"][0]["message"]["content"]

        return f"[ERROR] Groq: {result.get('error', {}).get('message', 'Unknown error')}"

    except Exception as e:
        return f"[ERROR] Groq Exception: {str(e)}"

def multi_query(prompt):
    return try_groq(prompt)