mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-13 12:31:13 +00:00
Add basic fastembed server
This commit is contained in:
parent
a9be4907c0
commit
069ce4448c
1 changed files with 21 additions and 0 deletions
21
python/fastembed-server.py
Normal file
21
python/fastembed-server.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from fastembed import TextEmbedding
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
model = TextEmbedding("snowflake/snowflake-arctic-embed-xs")
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
class EmbeddingRequest(BaseModel):
|
||||
model: str
|
||||
prompt: str
|
||||
|
||||
@app.post("/api/embeddings")
|
||||
def embeddings(request: EmbeddingRequest):
|
||||
embeddings = next(model.embed(request.prompt)).tolist()
|
||||
return {"embedding": embeddings}
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=11345)
|
Loading…
Reference in a new issue