Afeefa123 commited on
Commit
5ecbdf1
·
verified ·
1 Parent(s): 703629a

Update src/groqClient.js

Browse files
Files changed (1) hide show
  1. src/groqClient.js +6 -6
src/groqClient.js CHANGED
@@ -1,8 +1,8 @@
1
  import axios from "axios";
2
 
3
- const API_KEY = import.meta.env.VITE_GROQ_API_KEY;
4
 
5
- export const askGroq = async (question) => {
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 API error:", err);
23
- return "AI service is currently unavailable.";
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
+ }