Spaces:
Running
Running
TahaFawzyElshrif commited on
Commit ·
1fb304c
1
Parent(s): 38d1ff9
add health indicator
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from urllib import request
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.responses import JSONResponse
|
|
|
|
| 5 |
import uvicorn
|
| 6 |
import sys
|
| 7 |
import os
|
|
@@ -46,6 +47,17 @@ redis_conn = redis.Redis(
|
|
| 46 |
|
| 47 |
# Create app instance
|
| 48 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
print("Starting API Server...")
|
| 50 |
|
| 51 |
|
|
@@ -57,26 +69,10 @@ print("Starting API Server...")
|
|
| 57 |
def read_root():
|
| 58 |
return {"message": "Hello From CodeBuddyAI!"}
|
| 59 |
|
| 60 |
-
""
|
| 61 |
-
def
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
state = json.loads(request.last_state)
|
| 65 |
-
except Exception:
|
| 66 |
-
state: ProblemState = {
|
| 67 |
-
"question": request.prompt,
|
| 68 |
-
"memory": request.memory
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
answer = get_response(request.prompt, request.memory,request.ht_token,state,request.user_email,request.user_name)
|
| 72 |
-
|
| 73 |
-
# drop unserlizable keys
|
| 74 |
-
for k in ["llm","rag_model"]:
|
| 75 |
-
answer[k] = ""
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
return {"Data": answer}
|
| 79 |
-
"""
|
| 80 |
|
| 81 |
@app.api_route("/health", methods=["GET", "HEAD", "POST", "OPTIONS"])
|
| 82 |
def get_health():
|
|
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from fastapi.responses import JSONResponse
|
| 5 |
+
import sentry_sdk
|
| 6 |
import uvicorn
|
| 7 |
import sys
|
| 8 |
import os
|
|
|
|
| 47 |
|
| 48 |
# Create app instance
|
| 49 |
app = FastAPI()
|
| 50 |
+
|
| 51 |
+
# Create Sentry Monitoring for better error tracking and performance monitoring
|
| 52 |
+
sentry_sdk.init(
|
| 53 |
+
dsn=os.environ["SENTRY_DSN"],
|
| 54 |
+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
|
| 55 |
+
send_default_pii=True,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
app = FastAPI()
|
| 59 |
+
#redis_send(request.user_id,request.msg_id,{"status": "pending"}) # for performance test
|
| 60 |
+
|
| 61 |
print("Starting API Server...")
|
| 62 |
|
| 63 |
|
|
|
|
| 69 |
def read_root():
|
| 70 |
return {"message": "Hello From CodeBuddyAI!"}
|
| 71 |
|
| 72 |
+
@app.get("/sentry-debug")
|
| 73 |
+
async def trigger_error():
|
| 74 |
+
division_by_zero = 1 / 0
|
| 75 |
+
return {"message": "This will never be reached"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
@app.api_route("/health", methods=["GET", "HEAD", "POST", "OPTIONS"])
|
| 78 |
def get_health():
|