from dotenv import load_dotenv
import os
from groq import Groq
import json

# Load environment variables
load_dotenv()

# Initialize Groq client
client = Groq(
    api_key=os.getenv("GROQ_API_KEY"),
)

def chat_with_groq(prompt: str, model: str = "llama-3.3-70b-versatile") -> str:
    try:
        # Create a chat completion
        chat_completion = client.chat.completions.create(
            messages=[
                {
                    "role": "system",
                    "content": "you are a helpful AI engineer assistant."
                },
                {
                    "role": "user",
                    "content": prompt
                }
            ],
            model=model,
        )
        # Return the response content
        return chat_completion.choices[0].message.content
    except Exception as e:
        return f"An error occurred: {e}"