Handler improvements
Browse files- handler.py +22 -2
handler.py
CHANGED
@@ -15,11 +15,31 @@ class EndpointHandler():
|
|
15 |
"""
|
16 |
# get inputs
|
17 |
inputs = data.pop("inputs", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
#image = data.pop("image", None)
|
19 |
|
20 |
-
res = self.model(inputs, temperature=
|
21 |
|
22 |
-
return res
|
23 |
|
24 |
#inputs = self.processor(inputs, image, return_tensors="pt")
|
25 |
#res = self.model.generate(**inputs, do_sample=False, max_new_tokens=4096)
|
|
|
15 |
"""
|
16 |
# get inputs
|
17 |
inputs = data.pop("inputs", "")
|
18 |
+
temperature = data.pop("temperature", None)
|
19 |
+
if not temperature:
|
20 |
+
temperature = data.pop("temp", 0.33)
|
21 |
+
if temperature > 3 or temperature < 0:
|
22 |
+
return json.dumps({
|
23 |
+
"status": "error",
|
24 |
+
"reason": "invalid temperature ( 0.01 - 1.00 )"
|
25 |
+
})
|
26 |
+
top_p = data.pop("top-p", 0.85)
|
27 |
+
if top_p > 3 or top_p < 0:
|
28 |
+
return json.dumps({
|
29 |
+
"status": "error",
|
30 |
+
"reason": "invalid top percentage ( 0.01 - 1.00 )"
|
31 |
+
})
|
32 |
+
top_k = data.pop("top-k", 42)
|
33 |
+
if top_k > 100 or top_k < 0:
|
34 |
+
return json.dumps({
|
35 |
+
"status": "error",
|
36 |
+
"reason": "invalid top k ( 1 - 99 )"
|
37 |
+
})
|
38 |
#image = data.pop("image", None)
|
39 |
|
40 |
+
res = self.model(inputs, temperature=temperature, top_p=top_p, top_k=42)
|
41 |
|
42 |
+
return res
|
43 |
|
44 |
#inputs = self.processor(inputs, image, return_tensors="pt")
|
45 |
#res = self.model.generate(**inputs, do_sample=False, max_new_tokens=4096)
|