Skip to content

Commit

Permalink
fixed embedoc call
Browse files Browse the repository at this point in the history
Signed-off-by: sharanshirodkar7 <[email protected]>
  • Loading branch information
sharanshirodkar7 committed Sep 11, 2024
1 parent 008497e commit a4fccaa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions comps/embeddings/predictionguard/embedding_predictionguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from predictionguard import PredictionGuard

from comps import (
EmbedDoc512,
EmbedDoc,
ServiceType,
TextDoc,
opea_microservices,
Expand All @@ -28,15 +28,15 @@
host="0.0.0.0",
port=6000,
input_datatype=TextDoc,
output_datatype=EmbedDoc512,
output_datatype=EmbedDoc,
)
@register_statistics(names=["opea_service@embedding_predictionguard"])
def embedding(input: TextDoc) -> EmbedDoc512:
def embedding(input: TextDoc) -> EmbedDoc:
start = time.time()
response = client.embeddings.create(model=pg_embedding_model_name, input=[{"text": input.text}])
embed_vector = response["data"][0]["embedding"]
embed_vector = embed_vector[:512] # Keep only the first 512 elements
res = EmbedDoc512(text=input.text, embedding=embed_vector)
res = EmbedDoc(text=input.text, embedding=embed_vector)
statistics_dict["opea_service@embedding_predictionguard"].append_latency(time.time() - start, None)
return res

Expand Down

0 comments on commit a4fccaa

Please sign in to comment.