43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""FastAPI app factory. Composes all domain routers and middleware."""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from src.core.exceptions import (
|
|
ChunkingError,
|
|
BenchmarkError,
|
|
chunking_exception_handler,
|
|
benchmark_exception_handler,
|
|
)
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""Create and configure the FastAPI application.
|
|
|
|
Mounts domain routers and registers exception handlers.
|
|
Routers are imported lazily — domains are added in later phases.
|
|
"""
|
|
app = FastAPI(
|
|
title="RAG Chunking Benchmarker",
|
|
description="Benchmark five chunking strategies on regulatory documents. "
|
|
"Compare retrieval quality, answer faithfulness, and cost.",
|
|
version="0.1.0",
|
|
)
|
|
|
|
# CORS — allow all origins for development
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Register exception handlers
|
|
app.add_exception_handler(ChunkingError, chunking_exception_handler)
|
|
app.add_exception_handler(BenchmarkError, benchmark_exception_handler)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app() |