logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

fastembed-server.py (635B)


  1. from fastembed import TextEmbedding
  2. from fastapi import FastAPI
  3. from pydantic import BaseModel
  4. models = {}
  5. app = FastAPI()
  6. class EmbeddingRequest(BaseModel):
  7. model: str
  8. input: str
  9. @app.post("/v1/embeddings")
  10. def embeddings(request: EmbeddingRequest):
  11. model = models.get(request.model) or TextEmbedding(request.model)
  12. models[request.model] = model
  13. embeddings = next(model.embed(request.input)).tolist()
  14. return {"data": [{"embedding": embeddings}]}
  15. @app.get("/health")
  16. def health():
  17. return {"status": "ok"}
  18. if __name__ == "__main__":
  19. import uvicorn
  20. uvicorn.run(app, host="0.0.0.0", port=11345)