text-embedding / app /main.py
emilbm's picture
Added mypy rules and applied them.
c4d1eaa
from fastapi import FastAPI, HTTPException
from app.models import EmbedRequest, EmbedResponse
from app.embeddings import embed_text
from app.logger import logger
app = FastAPI(
title="Embedding API",
description="A simple API to generate text embeddings using Microsoft's `multilingual-e5-large` model.",
version="1.0.0",
)
@app.post("/embed", response_model=EmbedResponse)
async def embed(request: EmbedRequest) -> dict[str, list[list[float]]]:
"""Generate embeddings for a list of texts."""
logger.info("Generating embeddings...")
try:
vectors = embed_text(request.texts)
logger.info("Embeddings generated successfully!")
return {"embeddings": vectors}
except Exception as e:
logger.exception("Error generating embeddings")
raise HTTPException(status_code=500, detail=str(e))
@app.get("/health")
async def health_check() -> dict[str, str]:
"""Health check endpoint."""
return {"status": "ok"}