mentorme / main.py
Doanh Van Vu
Initial commit of the MentorMe AI Recommendation Server, including core application structure, environment configuration, Docker setup, and essential services for mentor recommendations and health checks.
1904012
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from contextlib import asynccontextmanager
from config.settings import get_settings
from routers import mentors, recommend, health
from services.embedding_service import EmbeddingService
settings = get_settings()
@asynccontextmanager
async def lifespan(app: FastAPI):
embedding_service = EmbeddingService()
app.state.embedding_service = embedding_service
yield
if hasattr(app.state, 'embedding_service'):
del app.state.embedding_service
app = FastAPI(
title="MentorMe AI Recommendation Server",
description="AI-powered mentor-mentee recommendation using Vietnamese_Embedding and Pinecone",
version="1.0.0",
lifespan=lifespan
)
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(health.router, prefix="/api/v1", tags=["Health"])
app.include_router(mentors.router, prefix="/api/v1", tags=["Mentors"])
app.include_router(recommend.router, prefix="/api/v1", tags=["Recommendations"])
@app.get("/")
async def root():
return {
"message": "MentorMe AI Recommendation Server",
"version": "1.0.0",
"status": "running"
}
if __name__ == "__main__":
uvicorn.run(
"main:app",
host=settings.HOST,
port=settings.PORT,
reload=settings.DEBUG,
log_level="info"
)