Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, Request, HTTPException
|
| 2 |
import requests
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
@@ -8,6 +9,31 @@ BOT_USERNAME = "@DiscussionBot"
|
|
| 8 |
INFERENCE_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
|
| 9 |
PROMPT = "Pretend you're a robot responding to machine learning discussions and reply to the following comment :\n"
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
@app.post("/")
|
| 13 |
async def webhook(request: Request) -> Dict[str, Any]:
|
|
|
|
| 1 |
from fastapi import FastAPI, Request, HTTPException
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
+
from typing import Dict, Any
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
|
|
| 9 |
INFERENCE_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
|
| 10 |
PROMPT = "Pretend you're a robot responding to machine learning discussions and reply to the following comment :\n"
|
| 11 |
|
| 12 |
+
@app.get("/")
|
| 13 |
+
async def root(request: Request) -> Dict[str, Any]:
|
| 14 |
+
"""
|
| 15 |
+
Gère les requêtes GET pour vérifier l'état du serveur et afficher les détails de la requête.
|
| 16 |
+
Inclut une gestion d'erreurs robuste pour capturer et signaler tout problème.
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
# Préparer les détails de la requête
|
| 20 |
+
request_details = {
|
| 21 |
+
"method": request.method,
|
| 22 |
+
"headers": dict(request.headers),
|
| 23 |
+
"query_params": dict(request.query_params),
|
| 24 |
+
"message": "Webhook server is running. Use POST to interact with the bot."
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Validation des paramètres de requête (exemple : vérifier si un paramètre spécifique existe)
|
| 28 |
+
if "test_error" in request.query_params:
|
| 29 |
+
if request.query_params["test_error"] == "simulate_error":
|
| 30 |
+
# Simuler une erreur pour tester la gestion des exceptions
|
| 31 |
+
raise ValueError("Simulated error triggered by query parameter 'test_error=simulate_error'")
|
| 32 |
+
|
| 33 |
+
# Log de la requête GET reçue
|
| 34 |
+
print(f"GET request received: headers={request_details['headers']}, query_params={request_details['query_params']}")
|
| 35 |
+
|
| 36 |
+
return request_details
|
| 37 |
|
| 38 |
@app.post("/")
|
| 39 |
async def webhook(request: Request) -> Dict[str, Any]:
|