Student3331 commited on
Commit
626f69a
·
verified ·
1 Parent(s): 304f2dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -2,33 +2,32 @@ import os
2
  import requests
3
  import streamlit as st
4
 
5
- # Set the Groq API key from environment variables
6
- GROQ_API_KEY = os.getenv("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") # Replace with your actual API key if needed
7
 
8
- # The API URL (update with the correct URL if needed)
9
- GROQ_API_URL = 'https://api.groq.com/v1/chat/completions' # Update with actual endpoint
 
10
 
11
- # Function to interact with the Groq API
12
  def get_chat_completion(user_message):
13
  headers = {
14
  'Authorization': f'Bearer {GROQ_API_KEY}',
15
  'Content-Type': 'application/json',
16
  }
17
 
18
- # Prepare the request payload
19
  payload = {
20
- "messages": [
21
- {"role": "user", "content": user_message}
22
- ],
23
- "model": "llama3-8b-8192", # Replace with the model you're using
24
  }
25
 
26
- # Send the request to the API
27
  response = requests.post(GROQ_API_URL, json=payload, headers=headers)
28
 
29
  if response.status_code == 200:
30
  # Return the response content
31
- return response.json()['choices'][0]['message']['content']
32
  else:
33
  # Handle error response
34
  return f"Error: {response.status_code} - {response.text}"
 
2
  import requests
3
  import streamlit as st
4
 
5
+ # Get the Groq API key from the environment variable
6
+ GROQ_API_KEY = os.getenv("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") # Use your actual API key if needed
7
 
8
+ # Correct Groq API URL (Ensure this is the correct URL you need to use)
9
+ # Check Groq documentation for the correct API endpoint
10
+ GROQ_API_URL = 'https://api.groq.com/v1/chat/completions' # Replace with the correct endpoint
11
 
12
+ # Function to make a request to the Groq API
13
  def get_chat_completion(user_message):
14
  headers = {
15
  'Authorization': f'Bearer {GROQ_API_KEY}',
16
  'Content-Type': 'application/json',
17
  }
18
 
19
+ # Prepare the payload (customize this based on Groq API documentation)
20
  payload = {
21
+ "messages": [{"role": "user", "content": user_message}],
22
+ "model": "your-model-id-here" # Replace with the actual model name or ID you're using
 
 
23
  }
24
 
25
+ # Send the request to the Groq API
26
  response = requests.post(GROQ_API_URL, json=payload, headers=headers)
27
 
28
  if response.status_code == 200:
29
  # Return the response content
30
+ return response.json().get('choices', [{}])[0].get('message', {}).get('content', "No response.")
31
  else:
32
  # Handle error response
33
  return f"Error: {response.status_code} - {response.text}"