Files
R2R/py/core/main/app.py
T
emrgnt-cmplxty 3e0938b5d5 Feature/typing with pagination (#1219) (#1230)
* Feature/typing with pagination (#1219)

* fix imports

* bump pkg

* Improve pagination in responses

* Add js

* Fix collections

* fixing typing issues

* checkin work

* more

* fix all typing issues

* fix type errors

* flake8 and type

* flake8 and type

* up (#1221)

* up

* add mypy

* add mypy to pre-commit

* Feature/share abstractions (#1223)

* no verify

* fix shared

* finish share

* Fix: Docker compose bind mount issue (#1222)

* bind mount updated

* Update compose.yaml

* Update compose.yaml

* yaml formatted

* Update compose.yaml

* missing files (#1225)

* Yc (#1224)

* up

* frontend

* update search types

* modify default queries

* up

* fix formatting

* fix docs

* up

* up

* modify dockerfile

* revert middleware change

* Improve UI (#1227)

* up

* minor fix

* Improve messaging (#1228)

* up

* up

* rm print statements

---------

Co-authored-by: Nolan Tremelling <34580718+NolanTrem@users.noreply.github.com>

* fixes breaks (#1226)

* fixes breaks

* fixes breaks

* rm prints

* add back regression tests

* fix llm content (#1229)

---------

Co-authored-by: NolanTrem <34580718+NolanTrem@users.noreply.github.com>
Co-authored-by: Rajan Goswami <148398808+rajangoswamiTWS@users.noreply.github.com>
Co-authored-by: Shreyas Pimpalgaonkar <shreyas.gp.7@gmail.com>

* bump version

---------

Co-authored-by: NolanTrem <34580718+NolanTrem@users.noreply.github.com>
Co-authored-by: Rajan Goswami <148398808+rajangoswamiTWS@users.noreply.github.com>
Co-authored-by: Shreyas Pimpalgaonkar <shreyas.gp.7@gmail.com>
2024-09-20 17:21:32 -07:00

70 lines
2.4 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from core.base.providers import OrchestrationProvider
from .api.auth_router import AuthRouter
from .api.ingestion_router import IngestionRouter
from .api.management_router import ManagementRouter
from .api.restructure_router import RestructureRouter
from .api.retrieval_router import RetrievalRouter
from .config import R2RConfig
class R2RApp:
def __init__(
self,
config: R2RConfig,
orchestration_provider: OrchestrationProvider,
auth_router: AuthRouter,
ingestion_router: IngestionRouter,
management_router: ManagementRouter,
retrieval_router: RestructureRouter,
restructure_router: RetrievalRouter,
):
self.config = config
self.ingestion_router = ingestion_router
self.management_router = management_router
self.retrieval_router = retrieval_router
self.auth_router = auth_router
self.restructure_router = restructure_router
self.orchestration_provider = orchestration_provider
self.app = FastAPI()
self._setup_routes()
self._apply_cors()
def _setup_routes(self):
# Include routers in the app
self.app.include_router(self.ingestion_router, prefix="/v2")
self.app.include_router(self.management_router, prefix="/v2")
self.app.include_router(self.retrieval_router, prefix="/v2")
self.app.include_router(self.auth_router, prefix="/v2")
self.app.include_router(self.restructure_router, prefix="/v2")
@self.app.get("/v2/openapi_spec")
async def openapi_spec():
return get_openapi(
title="R2R Application API",
version="1.0.0",
routes=self.app.routes,
)
def _apply_cors(self):
origins = ["*", "http://localhost:3000", "http://localhost:7272"]
self.app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def serve(self, host: str = "0.0.0.0", port: int = 7272):
# Start the Hatchet worker in a separate thread
import uvicorn
# Run the FastAPI app
uvicorn.run(self.app, host=host, port=port)