Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,22 @@ api_key = st.secrets["groq_api_key"]
|
|
7 |
|
8 |
# Function to interact with Groq API
|
9 |
def get_groq_response(prompt):
|
10 |
-
url = "https://api.groq.com/openai/v1/chat/completions"
|
11 |
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
response = requests.post(url, headers=headers, json=data)
|
15 |
if response.status_code == 200:
|
16 |
-
return response.json().get("
|
17 |
else:
|
18 |
return f"Error: {response.status_code}, {response.text}"
|
19 |
|
|
|
20 |
# Streamlit app code
|
21 |
st.title("Groq API Chatbot")
|
22 |
|
|
|
7 |
|
8 |
# Function to interact with Groq API
|
9 |
def get_groq_response(prompt):
|
10 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
11 |
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
12 |
+
|
13 |
+
# Assuming the API requires a 'messages' field
|
14 |
+
data = {
|
15 |
+
"model": "gpt-3.5-turbo", # Specify the model if required
|
16 |
+
"messages": [{"role": "user", "content": prompt}]
|
17 |
+
}
|
18 |
|
19 |
response = requests.post(url, headers=headers, json=data)
|
20 |
if response.status_code == 200:
|
21 |
+
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response")
|
22 |
else:
|
23 |
return f"Error: {response.status_code}, {response.text}"
|
24 |
|
25 |
+
|
26 |
# Streamlit app code
|
27 |
st.title("Groq API Chatbot")
|
28 |
|