Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from groq import Groq
|
2 |
+
from config import GROQ_API_KEY, MODEL_NAME
|
3 |
+
|
4 |
+
# Initialize Groq client
|
5 |
+
client = Groq(api_key=GROQ_API_KEY)
|
6 |
+
|
7 |
+
def generate_response(user_input):
|
8 |
+
"""
|
9 |
+
Generate a response from Groq API.
|
10 |
+
"""
|
11 |
+
try:
|
12 |
+
response = client.chat.completions.create(
|
13 |
+
messages=[{"role": "user", "content": user_input}],
|
14 |
+
model=MODEL_NAME,
|
15 |
+
)
|
16 |
+
return response.choices[0].message.content
|
17 |
+
except Exception as e:
|
18 |
+
return f"Error: {e}"
|