Output cleanup
Browse filesIf the answer has context and reponse tags; only return the repsonse or a message that you can't help.
- handler.py +12 -1
handler.py
CHANGED
|
@@ -93,10 +93,21 @@ class EndpointHandler:
|
|
| 93 |
output_tokens[0]
|
| 94 |
)
|
| 95 |
|
|
|
|
|
|
|
|
|
|
| 96 |
answer = generated_text.split('>>END<<')[0].split('>>ANSWER<<:')[1].strip()
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
#prediction = {'generated_text': answer.replace('<|endoftext|>', ''), 'time': f"{(end-start):.2f} s"}
|
| 99 |
-
prediction = {'generated_text':
|
| 100 |
|
| 101 |
result = []
|
| 102 |
result.append(prediction)
|
|
|
|
| 93 |
output_tokens[0]
|
| 94 |
)
|
| 95 |
|
| 96 |
+
def substring_after(s, delim):
|
| 97 |
+
return s.partition(delim)[2]
|
| 98 |
+
|
| 99 |
answer = generated_text.split('>>END<<')[0].split('>>ANSWER<<:')[1].strip()
|
| 100 |
|
| 101 |
+
if "CONTEXT:" in answer:
|
| 102 |
+
if "RESPONSE:" in answer:
|
| 103 |
+
answerclean = answer.partition("RESPONSE:")[2]
|
| 104 |
+
else:
|
| 105 |
+
answerclean = "I'm sorry. I'm not able to help with this tender topic."
|
| 106 |
+
else:
|
| 107 |
+
answerclean = answer
|
| 108 |
+
|
| 109 |
#prediction = {'generated_text': answer.replace('<|endoftext|>', ''), 'time': f"{(end-start):.2f} s"}
|
| 110 |
+
prediction = {'generated_text': answerclean.replace('<|endoftext|>', ''), 'time': f"{(end-start):.2f} s", 'complete_ouput': generated_text}
|
| 111 |
|
| 112 |
result = []
|
| 113 |
result.append(prediction)
|