Max5ive commited on
Commit
f073753
·
1 Parent(s): b76a135

remove trailing sentences if endoftext tag not present.

Browse files
Files changed (1) hide show
  1. 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. 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)
 
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)