File size: 740 Bytes
5a67683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from fastapi import APIRouter

from app.components.embedding.component import EmbeddingComponent
from app.server.embedding.schemas import EmbeddingsBody, EmbeddingsResponse
from app.server.embedding.service import EmbeddingsService

embedding_router = APIRouter()


@embedding_router.post("/embedding", tags=["Embeddings"])
def generate_embeddings(body: EmbeddingsBody) -> EmbeddingsResponse:
    embedding_component = EmbeddingComponent()
    service = EmbeddingsService(embedding_component)
    input_texts = body.input if isinstance(body.input, list) else [body.input]
    embeddings = service.embed_texts(input_texts)
    return EmbeddingsResponse(
        object="list", model=service.embedding_model.model_name, data=embeddings
    )