remove trailing sentences if endoftext tag not present.
Browse files- handler.py +10 -3
handler.py
CHANGED
|
@@ -102,12 +102,19 @@ class EndpointHandler:
|
|
| 102 |
if "RESPONSE:" in answer:
|
| 103 |
answerclean = answer.partition("RESPONSE:")[2]
|
| 104 |
else:
|
| 105 |
-
answerclean = "I'm sorry
|
| 106 |
else:
|
| 107 |
answerclean = answer
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
result = []
|
| 113 |
result.append(prediction)
|
|
|
|
| 102 |
if "RESPONSE:" in answer:
|
| 103 |
answerclean = answer.partition("RESPONSE:")[2]
|
| 104 |
else:
|
| 105 |
+
answerclean = "I'm sorry, but I'm not able to help with your tender topic."
|
| 106 |
else:
|
| 107 |
answerclean = answer
|
| 108 |
|
| 109 |
+
if "<|endoftext|>:" in answerclean:
|
| 110 |
+
answerclean = answerclean.replace('<|endoftext|>', '')
|
| 111 |
+
else:
|
| 112 |
+
first_full_stop = answerclean.index('.')
|
| 113 |
+
last_full_stop = answerclean.rindex('.')
|
| 114 |
+
answerclean = answerclean[0:last_full_stop+1]
|
| 115 |
+
|
| 116 |
+
prediction = {'generated_text': answerclean, 'time': f"{(end-start):.2f} s"}
|
| 117 |
+
#prediction = {'generated_text': answerclean, 'time': f"{(end-start):.2f} s", 'complete_ouput': generated_text}
|
| 118 |
|
| 119 |
result = []
|
| 120 |
result.append(prediction)
|