forked from QuivrHQ/quivr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(microservices): split into 4 quivr to better handle long services (
QuivrHQ#972) * feat(verbose): removed * feat(microservices): split quivr into micro services * test(main): fixed
- Loading branch information
1 parent
ad7ac15
commit 7281fd9
Showing
7 changed files
with
359 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
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 | ||
load_dotenv() | ||
import sentry_sdk | ||
from fastapi import FastAPI, HTTPException, Request, status | ||
from fastapi.exceptions import RequestValidationError | ||
from fastapi.responses import JSONResponse | ||
from logger import get_logger | ||
from middlewares.cors import add_cors_middleware | ||
from routes.misc_routes import misc_router | ||
from routes.chat_routes import chat_router | ||
|
||
logger = get_logger(__name__) | ||
|
||
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.include_router(chat_router) | ||
app.include_router(misc_router) | ||
|
||
|
||
|
||
@app.exception_handler(HTTPException) | ||
async def http_exception_handler(_, exc): | ||
return JSONResponse( | ||
status_code=exc.status_code, | ||
content={"detail": exc.detail}, | ||
) | ||
|
||
|
||
# log more details about validation errors (422) | ||
def handle_request_validation_error(app: FastAPI): | ||
@app.exception_handler(RequestValidationError) | ||
async def validation_exception_handler( | ||
request: Request, exc: RequestValidationError | ||
): | ||
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ") | ||
logger.error(request, exc_str) | ||
content = { | ||
"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
"message": exc_str, | ||
"data": None, | ||
} | ||
return JSONResponse( | ||
content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY | ||
) | ||
|
||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import os | ||
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 | ||
load_dotenv() | ||
import sentry_sdk | ||
from fastapi import FastAPI, HTTPException, Request, status | ||
from fastapi.exceptions import RequestValidationError | ||
from fastapi.responses import JSONResponse | ||
from logger import get_logger | ||
from middlewares.cors import add_cors_middleware | ||
from routes.misc_routes import misc_router | ||
from routes.crawl_routes import crawl_router | ||
|
||
logger = get_logger(__name__) | ||
|
||
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.include_router(crawl_router) | ||
app.include_router(misc_router) | ||
|
||
|
||
|
||
@app.exception_handler(HTTPException) | ||
async def http_exception_handler(_, exc): | ||
return JSONResponse( | ||
status_code=exc.status_code, | ||
content={"detail": exc.detail}, | ||
) | ||
|
||
|
||
# log more details about validation errors (422) | ||
def handle_request_validation_error(app: FastAPI): | ||
@app.exception_handler(RequestValidationError) | ||
async def validation_exception_handler( | ||
request: Request, exc: RequestValidationError | ||
): | ||
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ") | ||
logger.error(request, exc_str) | ||
content = { | ||
"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
"message": exc_str, | ||
"data": None, | ||
} | ||
return JSONResponse( | ||
content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY | ||
) | ||
|
||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
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 | ||
load_dotenv() | ||
import sentry_sdk | ||
import pypandoc | ||
from fastapi import FastAPI, HTTPException, Request, status | ||
from fastapi.exceptions import RequestValidationError | ||
from fastapi.responses import JSONResponse | ||
from logger import get_logger | ||
from middlewares.cors import add_cors_middleware | ||
from routes.misc_routes import misc_router | ||
from routes.upload_routes import upload_router | ||
|
||
logger = get_logger(__name__) | ||
|
||
sentry_dsn = os.getenv("SENTRY_DSN") | ||
if sentry_dsn: | ||
sentry_sdk.init( | ||
dsn=sentry_dsn, | ||
traces_sample_rate=1.0, | ||
) | ||
|
||
app = FastAPI() | ||
|
||
@app.on_event("startup") | ||
async def startup_event(): | ||
if not os.path.exists(pypandoc.get_pandoc_path()): | ||
pypandoc.download_pandoc() | ||
|
||
add_cors_middleware(app) | ||
|
||
|
||
|
||
app.include_router(upload_router) | ||
app.include_router(misc_router) | ||
|
||
|
||
|
||
@app.exception_handler(HTTPException) | ||
async def http_exception_handler(_, exc): | ||
return JSONResponse( | ||
status_code=exc.status_code, | ||
content={"detail": exc.detail}, | ||
) | ||
|
||
|
||
# log more details about validation errors (422) | ||
def handle_request_validation_error(app: FastAPI): | ||
@app.exception_handler(RequestValidationError) | ||
async def validation_exception_handler( | ||
request: Request, exc: RequestValidationError | ||
): | ||
exc_str = f"{exc}".replace("\n", " ").replace(" ", " ") | ||
logger.error(request, exc_str) | ||
content = { | ||
"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
"message": exc_str, | ||
"data": None, | ||
} | ||
return JSONResponse( | ||
content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY | ||
) | ||
|
||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.