Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,12 @@ from fastapi import FastAPI, HTTPException
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import uvicorn
|
| 4 |
import importlib.util
|
|
|
|
| 5 |
import sys
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
|
|
|
| 8 |
from core.pipeline_1.logic import PipelineLLMOnly
|
| 9 |
from core.pipeline_2.logic import PipelineRAG
|
| 10 |
from core.pipeline_3.logic import PipelineGraphRAG
|
|
@@ -28,6 +31,50 @@ pipeline_graph = PipelineGraphRAG(vector_top_k=50, rerank_top_n=10, max_full_tex
|
|
| 28 |
async def root():
|
| 29 |
return {"message": "Welcome to the SEC Dataset API", "status": "running"}
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
@app.post("/query/baseline")
|
| 32 |
async def query_baseline(request: QueryRequest):
|
| 33 |
"""
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import uvicorn
|
| 4 |
import importlib.util
|
| 5 |
+
import os
|
| 6 |
import sys
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
+
import requests as _requests
|
| 10 |
+
|
| 11 |
from core.pipeline_1.logic import PipelineLLMOnly
|
| 12 |
from core.pipeline_2.logic import PipelineRAG
|
| 13 |
from core.pipeline_3.logic import PipelineGraphRAG
|
|
|
|
| 31 |
async def root():
|
| 32 |
return {"message": "Welcome to the SEC Dataset API", "status": "running"}
|
| 33 |
|
| 34 |
+
|
| 35 |
+
@app.get("/health")
|
| 36 |
+
async def health():
|
| 37 |
+
tg_host = os.environ.get("TG_HOST", "")
|
| 38 |
+
tg_secret = os.environ.get("TG_SECRET", "")
|
| 39 |
+
tg_status = "skipped"
|
| 40 |
+
tg_paper_count = None
|
| 41 |
+
|
| 42 |
+
if tg_host and tg_secret:
|
| 43 |
+
try:
|
| 44 |
+
import pyTigerGraph as tg
|
| 45 |
+
conn = tg.TigerGraphConnection(
|
| 46 |
+
host=tg_host, graphname="PaperGraph",
|
| 47 |
+
gsqlSecret=tg_secret,
|
| 48 |
+
restppPort=os.environ.get("TG_PORT", "443"),
|
| 49 |
+
gsPort=os.environ.get("TG_PORT", "443"),
|
| 50 |
+
)
|
| 51 |
+
token = conn.getToken(tg_secret)[0]
|
| 52 |
+
resp = _requests.get(
|
| 53 |
+
f"{tg_host}/restpp/graph/PaperGraph/vertices/Paper",
|
| 54 |
+
params={"count_only": True},
|
| 55 |
+
headers={"Authorization": f"Bearer {token}"},
|
| 56 |
+
timeout=10,
|
| 57 |
+
)
|
| 58 |
+
data = resp.json()
|
| 59 |
+
tg_paper_count = data["results"][0]["count"]
|
| 60 |
+
tg_status = "ok"
|
| 61 |
+
except Exception as e:
|
| 62 |
+
tg_status = f"error: {e}"
|
| 63 |
+
|
| 64 |
+
qdrant_status = "skipped"
|
| 65 |
+
try:
|
| 66 |
+
cols = pipeline_rag.retriever.client.get_collections().collections
|
| 67 |
+
qdrant_status = f"ok ({len(cols)} collection(s))"
|
| 68 |
+
except Exception as e:
|
| 69 |
+
qdrant_status = f"error: {e}"
|
| 70 |
+
|
| 71 |
+
return {
|
| 72 |
+
"app": "ok",
|
| 73 |
+
"tigergraph": tg_status,
|
| 74 |
+
"tigergraph_paper_count": tg_paper_count,
|
| 75 |
+
"qdrant": qdrant_status,
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
@app.post("/query/baseline")
|
| 79 |
async def query_baseline(request: QueryRequest):
|
| 80 |
"""
|