Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,29 +9,33 @@ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
| 9 |
GROQ_URL = "https://groq.com"
|
| 10 |
|
| 11 |
# --- SERVICES DE DONNÉES ---
|
| 12 |
-
|
| 13 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=10))
|
| 14 |
def generer_actu_ia(joueur):
|
|
|
|
|
|
|
|
|
|
| 15 |
headers = {
|
| 16 |
-
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 17 |
"Content-Type": "application/json"
|
| 18 |
}
|
|
|
|
| 19 |
payload = {
|
| 20 |
"model": "mixtral-8x7b-32768",
|
| 21 |
-
"messages": [
|
|
|
|
|
|
|
|
|
|
| 22 |
"temperature": 0.7
|
| 23 |
}
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
response = requests.post(GROQ_URL, headers=headers, json=payload, timeout=10)
|
| 26 |
-
|
| 27 |
-
# Si erreur, on affiche le message de l'API pour débugger
|
| 28 |
if response.status_code != 200:
|
| 29 |
st.error(f"Erreur API Groq ({response.status_code}): {response.text}")
|
| 30 |
response.raise_for_status()
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
return resultat['choices'][0]['message']['content'].strip()
|
| 35 |
|
| 36 |
def obtenir_image_fond(sujet):
|
| 37 |
"""Récupère une image de sport sur Pexels via l'API officielle."""
|
|
|
|
| 9 |
GROQ_URL = "https://groq.com"
|
| 10 |
|
| 11 |
# --- SERVICES DE DONNÉES ---
|
|
|
|
| 12 |
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=10))
|
| 13 |
def generer_actu_ia(joueur):
|
| 14 |
+
# L'URL DOIT être celle-ci pour les complétions de chat
|
| 15 |
+
url = "https://groq.com"
|
| 16 |
+
|
| 17 |
headers = {
|
| 18 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 19 |
"Content-Type": "application/json"
|
| 20 |
}
|
| 21 |
+
|
| 22 |
payload = {
|
| 23 |
"model": "mixtral-8x7b-32768",
|
| 24 |
+
"messages": [
|
| 25 |
+
{"role": "system", "content": "Tu es un expert foot qui écrit des news virales."},
|
| 26 |
+
{"role": "user", "content": f"Écris une news très courte sur {joueur}."}
|
| 27 |
+
],
|
| 28 |
"temperature": 0.7
|
| 29 |
}
|
| 30 |
+
|
| 31 |
+
response = requests.post(url, headers=headers, json=payload, timeout=10)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
if response.status_code != 200:
|
| 34 |
st.error(f"Erreur API Groq ({response.status_code}): {response.text}")
|
| 35 |
response.raise_for_status()
|
| 36 |
|
| 37 |
+
# Correction de l'indexation : [0] est crucial car 'choices' est une liste
|
| 38 |
+
return response.json()['choices'][0]['message']['content'].strip()
|
|
|
|
| 39 |
|
| 40 |
def obtenir_image_fond(sujet):
|
| 41 |
"""Récupère une image de sport sur Pexels via l'API officielle."""
|