Skip to content

Commit db4ac96

Browse files
committed
fix json mode
Signed-off-by: Praneeth Bedapudi <[email protected]>
1 parent a95cf9a commit db4ac96

File tree

6 files changed

+9987
-25
lines changed

6 files changed

+9987
-25
lines changed

fastdeploy/_rest.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def on_post(self, req, resp):
136136

137137
if success is not True:
138138
resp.status = falcon.HTTP_400
139-
resp.data = failure_response
139+
if input_type == "json":
140+
resp.media = failure_response
141+
else:
142+
resp.data = failure_response
140143

141144
else:
142145
(
@@ -146,7 +149,10 @@ def on_post(self, req, resp):
146149
unique_id, is_compressed, input_type, client_timeout
147150
)
148151
resp.status = falcon.HTTP_200 if success else falcon.HTTP_400
149-
resp.data = response
152+
if input_type == "json":
153+
resp.media = response
154+
else:
155+
resp.data = response
150156

151157

152158
class PrometheusMetrics(object):

recipes/text_embeddings/example.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
example = [
2-
"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",
3-
"This is another test sentence",
4-
"This is a third test sentence"
5-
]
1+
# generate random sentence with words of size 1-10 characters and total 5-100 words
2+
3+
import random
4+
import string
5+
6+
words = open("words.txt", "r").read().split()
7+
8+
def generate_random_sentence():
9+
# Generate random number of words between 5-100
10+
num_words = random.randint(3, 100)
11+
12+
sentence = []
13+
for _ in range(num_words):
14+
word = random.choice(words)
15+
sentence.append(word)
16+
17+
return ' '.join(sentence)
18+
19+
20+
def example_function():
21+
return [generate_random_sentence() for _ in range(random.randint(1, 10))]
22+
23+
example = example_function()

recipes/text_embeddings/predictor.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

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

7-
from time import time
8-
97
def predictor(input_list, batch_size=16):
108
return model.encode(input_list, convert_to_numpy=True, normalize_embeddings=True, show_progress_bar=False, batch_size=batch_size)
119

0 commit comments

Comments
 (0)