Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,33 +2,32 @@ import os
|
|
| 2 |
import requests
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
GROQ_API_KEY = os.getenv("
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
# Function to
|
| 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
|
| 19 |
payload = {
|
| 20 |
-
"messages": [
|
| 21 |
-
|
| 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()
|
| 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}"
|