| """FastAPI lietojumprogramma — galvenais ieejas punkts priekš Rust backend.""" |
|
|
| from contextlib import asynccontextmanager |
|
|
| import uvicorn |
| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from fastapi.responses import JSONResponse |
|
|
| from maris_core.runtime import ( |
| configure_huggingface_environment, |
| is_reload_enabled, |
| resolve_host, |
| resolve_port, |
| ) |
|
|
| configure_huggingface_environment() |
|
|
| from maris_core.api import router |
| from maris_core.text.generate import get_text_model_readiness, warm_text_model_runtime |
|
|
|
|
| @asynccontextmanager |
| async def lifespan(_: FastAPI): |
| warm_text_model_runtime() |
| yield |
|
|
|
|
| app = FastAPI( |
| title="Maris AI Core Python", |
| description="MI kodols: teksts, attēli, audio, video, kods, aģents", |
| version="0.1.0", |
| lifespan=lifespan, |
| ) |
|
|
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| app.include_router(router, prefix="/v1") |
|
|
|
|
| @app.get("/health") |
| async def health() -> dict: |
| return {"status": "ok", "service": "maris-core-python"} |
|
|
|
|
| @app.get("/ready") |
| async def ready() -> JSONResponse: |
| text_model = get_text_model_readiness(start_loading=True) |
| payload = { |
| "status": "ok" if text_model["ready"] else "not_ready", |
| "service": "maris-core-python", |
| "ready": text_model["ready"], |
| "text_model": text_model, |
| } |
| return JSONResponse(status_code=200 if text_model["ready"] else 503, content=payload) |
|
|
|
|
| if __name__ == "__main__": |
| uvicorn.run( |
| "maris_core.__main__:app", |
| host=resolve_host(), |
| port=resolve_port(), |
| reload=is_reload_enabled(), |
| ) |
|
|