import requests
import os
from dotenv import load_dotenv

load_dotenv()
api_key = os.getenv('GROQ_API_KEY')
url = "https://api.groq.com/openai/v1/chat/completions"

def test_query(message):
    payload = {
        "model": "llama-3.3-70b-versatile",
        "messages": [
            {
                "role": "system",
                "content": "You are a world-class academic and technical expert. Provide definitively correct, concise, and professional answers."
            },
            {
                "role": "user",
                "content": message
            }
        ],
        "temperature": 0.3,
        "max_completion_tokens": 1024,
        "top_p": 1,
        "stream": False
    }
    
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {api_key}'
    }
    
    try:
        response = requests.post(url, json=payload, headers=headers, timeout=20)
        print(f"Status Code: {response.status_code}")
        if response.status_code != 200:
            print(f"Error: {response.text}")
        else:
            result = response.json()
            print("Response:", result['choices'][0]['message']['content'])
    except Exception as e:
        print(f"Exception: {e}")

if __name__ == "__main__":
    test_query("Solve for x: 5x^2 + 10x = 20. Use LaTeX for the solution.")
