Spaces:
Build error
Build error
Update src/groqClient.js
Browse files- src/groqClient.js +6 -6
src/groqClient.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import axios from "axios";
|
| 2 |
|
| 3 |
-
const API_KEY =
|
| 4 |
|
| 5 |
-
export
|
| 6 |
try {
|
| 7 |
const res = await axios.post(
|
| 8 |
"https://api.groq.com/openai/v1/chat/completions",
|
|
@@ -12,14 +12,14 @@ export const askGroq = async (question) => {
|
|
| 12 |
},
|
| 13 |
{
|
| 14 |
headers: {
|
| 15 |
-
Authorization: `Bearer ${API_KEY}`,
|
| 16 |
"Content-Type": "application/json",
|
|
|
|
| 17 |
},
|
| 18 |
}
|
| 19 |
);
|
| 20 |
return res.data.choices[0].message.content;
|
| 21 |
} catch (err) {
|
| 22 |
-
console.error("Groq
|
| 23 |
-
return "
|
| 24 |
}
|
| 25 |
-
}
|
|
|
|
| 1 |
import axios from "axios";
|
| 2 |
|
| 3 |
+
const API_KEY = process.env.GROQ_API_KEY;
|
| 4 |
|
| 5 |
+
export async function askGroq(question) {
|
| 6 |
try {
|
| 7 |
const res = await axios.post(
|
| 8 |
"https://api.groq.com/openai/v1/chat/completions",
|
|
|
|
| 12 |
},
|
| 13 |
{
|
| 14 |
headers: {
|
|
|
|
| 15 |
"Content-Type": "application/json",
|
| 16 |
+
Authorization: `Bearer ${API_KEY}`,
|
| 17 |
},
|
| 18 |
}
|
| 19 |
);
|
| 20 |
return res.data.choices[0].message.content;
|
| 21 |
} catch (err) {
|
| 22 |
+
console.error("Groq error:", err);
|
| 23 |
+
return "Sorry, I couldn't reach the AI service.";
|
| 24 |
}
|
| 25 |
+
}
|