Skip to content

Commit

Permalink
clean ups; unnecessary function removed;
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjan-stha committed Sep 12, 2024
1 parent af8bf87 commit 980d2f2
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@


class EmbeddingModelType(Enum):
"""
Embedding model types
"""

SENTENCE_TRANSFORMERS = 1
OLLAMA = 2
OPENAI = 3
Expand All @@ -31,21 +35,17 @@ class RequestSchemaForEmbeddings(BaseModel):
base_url: Optional[str] = None


class RequestSchemaForModel(BaseModel):
"""Request Schema"""

type_model: EmbeddingModelType
name_model: str
base_url: Optional[str]


@app.get("/")
async def home():
return "Embedding handler using models for texts"
return "Embedding handler using models for texts", 200


@app.post("/get_embeddings")
async def generate_embeddings(item: RequestSchemaForEmbeddings):
"""
Generates the embedding vectors for the text/documents
based on different models
"""
type_model = item.type_model
name_model = item.name_model
base_url = item.base_url
Expand All @@ -69,20 +69,3 @@ def generate(em_model, texts):
elif type_model == EmbeddingModelType.OPENAI:
embedding_model = OpenAIEmbeddingModel(model=name_model)
return generate(em_model=embedding_model, texts=texts)


@app.get("/get_model")
async def get_model(item: RequestSchemaForModel):
type_model = item.type_model
name_model = item.name_model
base_url = item.base_url

if type_model == EmbeddingModelType.SENTENCE_TRANSFORMERS:
embedding_model = SentenceTransformerEmbeddingModel(model=name_model)
return embedding_model.get_model()
elif type_model == EmbeddingModelType.OLLAMA:
embedding_model = OllamaEmbeddingModel(model=name_model, base_url=base_url)
return embedding_model.get_model()
elif type_model == EmbeddingModelType.OPENAI:
embedding_model = OpenAIEmbeddingModel(model=name_model)
return embedding_model.get_model()

0 comments on commit 980d2f2

Please sign in to comment.