File size: 638 Bytes
6bc6f1b
 
5ecbdf1
6bc6f1b
5ecbdf1
6bc6f1b
 
 
 
 
 
 
 
 
 
5ecbdf1
6bc6f1b
 
 
 
 
5ecbdf1
 
6bc6f1b
5ecbdf1
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
import axios from "axios";

const API_KEY = process.env.GROQ_API_KEY;

export async function askGroq(question) {
  try {
    const res = await axios.post(
      "https://api.groq.com/openai/v1/chat/completions",
      {
        model: "llama-3.3-70b-versatile",
        messages: [{ role: "user", content: question }],
      },
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${API_KEY}`,
        },
      }
    );
    return res.data.choices[0].message.content;
  } catch (err) {
    console.error("Groq error:", err);
    return "Sorry, I couldn't reach the AI service.";
  }
}