Skip to content

Commit

Permalink
fix json mode
Browse files Browse the repository at this point in the history
Signed-off-by: Praneeth Bedapudi <[email protected]>
  • Loading branch information
bedapudi6788 committed Oct 29, 2024
1 parent a95cf9a commit db4ac96
Show file tree
Hide file tree
Showing 6 changed files with 9,987 additions and 25 deletions.
10 changes: 8 additions & 2 deletions fastdeploy/_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def on_post(self, req, resp):

if success is not True:
resp.status = falcon.HTTP_400
resp.data = failure_response
if input_type == "json":
resp.media = failure_response
else:
resp.data = failure_response

else:
(
Expand All @@ -146,7 +149,10 @@ def on_post(self, req, resp):
unique_id, is_compressed, input_type, client_timeout
)
resp.status = falcon.HTTP_200 if success else falcon.HTTP_400
resp.data = response
if input_type == "json":
resp.media = response
else:
resp.data = response


class PrometheusMetrics(object):
Expand Down
28 changes: 23 additions & 5 deletions recipes/text_embeddings/example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
example = [
"This is a test sentence which is a bit longer than the others and also very long than normal and some more words here and some more words here and some more there",
"This is another test sentence",
"This is a third test sentence"
]
# generate random sentence with words of size 1-10 characters and total 5-100 words

import random
import string

words = open("words.txt", "r").read().split()

def generate_random_sentence():
# Generate random number of words between 5-100
num_words = random.randint(3, 100)

sentence = []
for _ in range(num_words):
word = random.choice(words)
sentence.append(word)

return ' '.join(sentence)


def example_function():
return [generate_random_sentence() for _ in range(random.randint(1, 10))]

example = example_function()
2 changes: 0 additions & 2 deletions recipes/text_embeddings/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

model = SentenceTransformer('Alibaba-NLP/gte-base-en-v1.5', trust_remote_code=True, backend="onnx", model_kwargs={"file_name": "model.onnx", "provider": "CPUExecutionProvider"})

from time import time

def predictor(input_list, batch_size=16):
return model.encode(input_list, convert_to_numpy=True, normalize_embeddings=True, show_progress_bar=False, batch_size=batch_size)

Loading

0 comments on commit db4ac96

Please sign in to comment.