diff options
author | Lain Soykaf <lain@lain.com> | 2024-05-19 12:33:49 +0400 |
---|---|---|
committer | Lain Soykaf <lain@lain.com> | 2024-05-19 12:33:49 +0400 |
commit | b9af017a4cf1025c7d8245fa4f1dbcb678ddd4b9 (patch) | |
tree | 07ba6a560c592c4a51eca2435319fd887f12a588 /python/fastembed-server.py | |
parent | 72ec261a69a7dda7ab95667e425824ab7758b636 (diff) | |
download | pleroma-b9af017a4cf1025c7d8245fa4f1dbcb678ddd4b9.tar.gz pleroma-b9af017a4cf1025c7d8245fa4f1dbcb678ddd4b9.zip |
B FastembedServer: Switch to OpenAI api, support changing models
Diffstat (limited to 'python/fastembed-server.py')
-rw-r--r-- | python/fastembed-server.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/python/fastembed-server.py b/python/fastembed-server.py index fa3f7c82b..dd4a7a9c8 100644 --- a/python/fastembed-server.py +++ b/python/fastembed-server.py @@ -2,18 +2,20 @@ from fastembed import TextEmbedding from fastapi import FastAPI from pydantic import BaseModel -model = TextEmbedding("snowflake/snowflake-arctic-embed-xs") +models = {} app = FastAPI() class EmbeddingRequest(BaseModel): model: str - prompt: str + input: str -@app.post("/api/embeddings") +@app.post("/v1/embeddings") def embeddings(request: EmbeddingRequest): - embeddings = next(model.embed(request.prompt)).tolist() - return {"embedding": embeddings} + model = models.get(request.model) or TextEmbedding(request.model) + models[request.model] = model + embeddings = next(model.embed(request.input)).tolist() + return {"data": [{"embedding": embeddings}]} if __name__ == "__main__": import uvicorn |