1
0
Fork 0
mirror of https://git.pleroma.social/pleroma/pleroma.git synced 2026-02-15 17:16:57 +00:00

B FastembedAPI: Move to more appropriate folder

This commit is contained in:
Lain Soykaf 2024-05-19 12:47:08 +04:00
parent e142ea400a
commit dd48810186
3 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,8 @@
FROM python:3.9
WORKDIR /code
COPY fastembed-server.py /workdir/fastembed-server.py
RUN pip install --no-cache-dir --upgrade fastembed fastapi uvicorn
CMD ["python", "/workdir/fastembed-server.py"]

View file

@ -0,0 +1,5 @@
services:
web:
build: .
ports:
- "11345:11345"

View file

@ -0,0 +1,23 @@
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}]}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=11345)