Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
added support for string in embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
filopedraz committed Aug 24, 2023
1 parent 8e4e2a3 commit 56fa3bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ebd-all-minilm/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
export VERSION=1.0.2
export VERSION=1.0.3
source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh"

build_cpu ghcr.io/premai-io/embeddings-all-minilm-l6-v2-cpu all-MiniLM-L6-v2 ${@:1}
Expand Down
10 changes: 7 additions & 3 deletions ebd-all-minilm/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import tiktoken
from fastapi import APIRouter
from models import SentenceTransformerBasedModel as model
from pydantic import BaseModel

from models import SentenceTransformerBasedModel as model


class EmbeddingsInput(BaseModel):
model: str = None
input: Union[List[str], List[List[int]]]
input: Union[List[str], List[List[int]], str]
user: str = ""


Expand Down Expand Up @@ -44,7 +45,10 @@ async def health():

@router.post("/embeddings", response_model=EmbeddingsResponse)
async def embeddings(body: EmbeddingsInput):
values = model.embeddings(texts=body.input)
if isinstance(body.input, str):
values = model.embeddings(texts=[body.input])
else:
values = model.embeddings(texts=body.input)
return EmbeddingsResponse(
object="list",
data=[EmbeddingObject(embedding=value) for value in values],
Expand Down

0 comments on commit 56fa3bb

Please sign in to comment.