summaryrefslogtreecommitdiff
path: root/supplemental/search/fastembed-api/fastembed-server.py
diff options
context:
space:
mode:
authormarcin mikołajczak <git@mkljczk.pl>2024-07-28 13:41:58 +0200
committermarcin mikołajczak <git@mkljczk.pl>2024-07-28 13:41:58 +0200
commitad8c26f6c285412be041b7dcaeefa8741d3a6e57 (patch)
tree041e9af5f9b64215f12d195d6c98b548b0c1b622 /supplemental/search/fastembed-api/fastembed-server.py
parent7620b520c13a1c204810cf0cfe6a7b70b9a1c59d (diff)
parent6876761837bad399758cd6a93be5bf5cc8a81cef (diff)
downloadpleroma-ad8c26f6c285412be041b7dcaeefa8741d3a6e57.tar.gz
pleroma-ad8c26f6c285412be041b7dcaeefa8741d3a6e57.zip
Merge remote-tracking branch 'origin/develop' into post-languages
Diffstat (limited to 'supplemental/search/fastembed-api/fastembed-server.py')
-rw-r--r--supplemental/search/fastembed-api/fastembed-server.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/supplemental/search/fastembed-api/fastembed-server.py b/supplemental/search/fastembed-api/fastembed-server.py
new file mode 100644
index 000000000..02da69db2
--- /dev/null
+++ b/supplemental/search/fastembed-api/fastembed-server.py
@@ -0,0 +1,27 @@
+from fastembed import TextEmbedding
+from fastapi import FastAPI
+from pydantic import BaseModel
+
+models = {}
+
+app = FastAPI()
+
+class EmbeddingRequest(BaseModel):
+ model: str
+ input: str
+
+@app.post("/v1/embeddings")
+def embeddings(request: EmbeddingRequest):
+ model = models.get(request.model) or TextEmbedding(request.model)
+ models[request.model] = model
+ embeddings = next(model.embed(request.input)).tolist()
+ return {"data": [{"embedding": embeddings}]}
+
+@app.get("/health")
+def health():
+ return {"status": "ok"}
+
+if __name__ == "__main__":
+ import uvicorn
+
+ uvicorn.run(app, host="0.0.0.0", port=11345)