forked from focused-labs/ai-knowledge-base-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
83 lines (57 loc) · 2 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
import sys
from contextlib import asynccontextmanager
import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# from import_service import import_web_scrape_data, import_notion_data
# from models.imported_pages import ImportedPages
# from models.imported_urls import ImportedUrls
from models.question import Question
from models.session import Session
from query_service import QueryService
load_dotenv()
allowed_origins = [
"http://localhost:3000",
"https://fl-ai-knowledgehub-h27h6.ondigitalocean.app/",
"https://dev-kb-xxl7y.ondigitalocean.app/",
"https://chat.withfocus.com/",
"https://chat.focusedlabs.io/"
]
query_service = QueryService()
def init_logging():
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
@asynccontextmanager
async def lifespan(app: FastAPI):
init_logging()
yield
app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=allowed_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# @app.post("/load-notion-docs")
# def load_notion_documents(imported_pages: ImportedPages):
# print(f"Loading the following notion docs {imported_pages}")
# import_notion_data(imported_pages.page_ids)
# return {"status": "Notion Docs Loaded"}
# @app.post("/load-website-docs")
# def load_web_scrape_documents(website: ImportedUrls):
# print(f"Loading following web scraped docs {website.page_urls}")
# import_web_scrape_data(website.page_urls)
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/query/")
async def query(question: Question):
return query_service.query(question=question)
@app.post("/delete_session")
async def delete_session(session: Session):
query_service.delete_query_session(session)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)