-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (38 loc) · 1.43 KB
/
main.py
File metadata and controls
51 lines (38 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fastapi import FastAPI, Header, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from typing import Optional
from app.schemas import QueryRequest
from app.auth import verify_api_key
from core.logic_evaluator import evaluate_logic
import time
import logging
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # allow requests from any origin (dev only)
allow_credentials=True,
allow_methods=["*"], # allow POST, OPTIONS, GET, etc.
allow_headers=["*"], # allow Authorization header
)
@app.get("/")
async def root():
return {"massage" : "connected succesdsfully"}
async def remove_ngrok_warning(request, call_next):
response = await call_next(request)
response.headers["ngrok-skip-browser-warning"] = "true"
return response
@app.post("/hackrx/run")
async def run_hackrx(
data:QueryRequest ,
authorization: Optional[str] = Header(None)):
start = time.perf_counter()
if not authorization or not authorization.startswith("Bearer "):
raise HTTPException(status_code=401, detail="Invalid or missing token")
token = authorization.split(" ")[1]
if not verify_api_key(token):
return {"status": "API KEY WRONG"}
output = evaluate_logic(data.documents,data.questions)
end = time.perf_counter()
execution_time = end - start
logging.info(f"Execution time: {execution_time:.2f} seconds")
return output