-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_groq.py
More file actions
36 lines (32 loc) · 1.14 KB
/
Copy pathtest_groq.py
File metadata and controls
36 lines (32 loc) · 1.14 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
import os
import requests
from dotenv import load_dotenv
if os.path.exists(".ignore/.env"):
load_dotenv(".ignore/.env")
else:
load_dotenv()
groq_key = os.getenv("GROQ_API_KEY")
print("Groq Key exists:", bool(groq_key))
if groq_key:
# Print length and sanitized representation for debugging without exposing the full key
print("Groq Key Length:", len(groq_key))
print("Groq Key Starts With:", groq_key[:8] if len(groq_key) > 8 else groq_key)
headers = {
"Authorization": f"Bearer {groq_key}",
"Content-Type": "application/json"
}
payload = {
"model": "llama-3.1-8b-instant",
"messages": [{"role": "user", "content": "Hi"}],
"temperature": 0
}
try:
print("Sending POST request to Groq API...")
response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=payload, timeout=10.0)
print("Response Status Code:", response.status_code)
if response.status_code == 200:
print("Success! Reply:", response.json()["choices"][0]["message"]["content"])
else:
print("Failure JSON:", response.json())
except Exception as e:
print("Network/Request Exception:", e)