Ecommerce-Project / src /groqClient.js
Afeefa123's picture
Update src/groqClient.js
5ecbdf1 verified
raw
history blame contribute delete
638 Bytes
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.";
}
}