-
Notifications
You must be signed in to change notification settings - Fork 4
/
heroku.py
59 lines (41 loc) · 1.34 KB
/
heroku.py
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
52
53
54
55
56
57
58
59
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from dotenv import load_dotenv
import os
import logging
import sys
import json
import requests
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from main import handle_webhook
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger("Docu Mentor")
load_dotenv()
load_dotenv()
ANYSCALE_TOKEN = os.environ.get("ANYSCALE_TOKEN")
ANYSCALE_SERVICE_URL = os.environ.get("BASE_URL")
app = FastAPI()
app.add_middleware(
CORSMiddleware,
# Restrict this to the domains you want to allow
# access to your service.
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/query")
async def handle_query(request: Request):
data = await request.json()
headers = {"Authorization": f"Bearer {ANYSCALE_TOKEN}"}
res = requests.post(f"{ANYSCALE_SERVICE_URL}/webhook/", headers=headers, json=data)
content = json.loads(res.content)
return JSONResponse(content=content, status_code=200)
@app.get("/")
async def root():
return {"message": "Docu Mentor reporting for duty!"}
@app.post("/webhook/")
async def handle_webhook_route(request: Request):
return await handle_webhook(request)