Geinji commited on
Commit
59a14fe
·
verified ·
1 Parent(s): 1b3ff95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
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" # Replace with the actual Groq API endpoint
11
  headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
12
- data = {"input": prompt}
 
 
 
 
 
13
 
14
  response = requests.post(url, headers=headers, json=data)
15
  if response.status_code == 200:
16
- return response.json().get("output", "No response")
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