mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-27 13:22:44 +03:00
82bcf38b16
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
import os
|
|
|
|
from utils import handle_request_validation_error
|
|
|
|
if __name__ == "__main__":
|
|
# import needed here when running main.py to debug backend
|
|
# you will need to run pip install python-dotenv
|
|
from dotenv import load_dotenv # type: ignore
|
|
|
|
load_dotenv()
|
|
import pypandoc
|
|
import sentry_sdk
|
|
from fastapi import FastAPI, HTTPException
|
|
from fastapi.responses import JSONResponse
|
|
from logger import get_logger
|
|
from middlewares.cors import add_cors_middleware
|
|
from routes.api_key_routes import api_key_router
|
|
from routes.brain_routes import brain_router
|
|
from routes.chat_routes import chat_router
|
|
from routes.crawl_routes import crawl_router
|
|
from routes.explore_routes import explore_router
|
|
from routes.knowledge_routes import knowledge_router
|
|
from routes.misc_routes import misc_router
|
|
from routes.notification_routes import notification_router
|
|
from routes.onboarding_routes import onboarding_router
|
|
from routes.prompt_routes import prompt_router
|
|
from routes.subscription_routes import subscription_router
|
|
from routes.upload_routes import upload_router
|
|
from routes.user_routes import user_router
|
|
from routes.contact_routes import router as contact_router
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
if os.getenv("DEV_MODE") == "true":
|
|
import debugpy
|
|
|
|
logger.debug("👨💻 Running in dev mode")
|
|
debugpy.listen(("0.0.0.0", 5678))
|
|
|
|
|
|
sentry_dsn = os.getenv("SENTRY_DSN")
|
|
if sentry_dsn:
|
|
sentry_sdk.init(
|
|
dsn=sentry_dsn,
|
|
traces_sample_rate=1.0,
|
|
)
|
|
|
|
app = FastAPI()
|
|
|
|
add_cors_middleware(app)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
if not os.path.exists(pypandoc.get_pandoc_path()):
|
|
pypandoc.download_pandoc()
|
|
|
|
|
|
app.include_router(brain_router)
|
|
app.include_router(chat_router)
|
|
app.include_router(crawl_router)
|
|
app.include_router(onboarding_router)
|
|
app.include_router(explore_router)
|
|
app.include_router(misc_router)
|
|
|
|
app.include_router(upload_router)
|
|
app.include_router(user_router)
|
|
app.include_router(api_key_router)
|
|
app.include_router(subscription_router)
|
|
app.include_router(prompt_router)
|
|
app.include_router(notification_router)
|
|
app.include_router(knowledge_router)
|
|
app.include_router(contact_router)
|
|
|
|
|
|
@app.exception_handler(HTTPException)
|
|
async def http_exception_handler(_, exc):
|
|
return JSONResponse(
|
|
status_code=exc.status_code,
|
|
content={"detail": exc.detail},
|
|
)
|
|
|
|
|
|
handle_request_validation_error(app)
|
|
|
|
if __name__ == "__main__":
|
|
# run main.py to debug backend
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=5050)
|