Benoit Chesneau 0e05c824e9 feat(examples): add FastAPI embedding service with Docker testing
Add a complete example demonstrating dirty workers with sentence-transformers
for text embeddings via FastAPI:

- EmbeddingApp DirtyApp that loads and manages the ML model
- FastAPI endpoints for /embed and /health
- Docker and docker-compose configuration
- Integration tests with numpy similarity checks
- GitHub Actions CI workflow
2026-01-25 10:23:25 +01:00

30 lines
617 B
Python

from fastapi import FastAPI
from pydantic import BaseModel
from gunicorn.dirty.client import get_dirty_client
app = FastAPI()
class EmbedRequest(BaseModel):
texts: list[str]
class EmbedResponse(BaseModel):
embeddings: list[list[float]]
@app.post("/embed", response_model=EmbedResponse)
async def embed(request: EmbedRequest):
client = get_dirty_client()
result = client.execute(
"embedding_service.embedding_app:EmbeddingApp",
"embed",
request.texts
)
return EmbedResponse(embeddings=result)
@app.get("/health")
async def health():
return {"status": "ok"}