arcsu1 commited on
Commit
b02a875
·
1 Parent(s): 4d0e37d

Fix response cleaning to remove special tokens

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -97,8 +97,22 @@ def chat():
97
  )
98
 
99
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
100
- # Extract only the new response
101
- response = response.replace(combined_prompt, "").split(".")[0].strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  return jsonify({
104
  "response": response,
 
97
  )
98
 
99
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
100
+
101
+ # Extract only the new AI response
102
+ # Split by <AI> and get the last response
103
+ if "<AI>" in response:
104
+ response = response.split("<AI>")[-1].strip()
105
+
106
+ # Remove any <user> tags if they appear (model might generate them)
107
+ if "<user>" in response:
108
+ response = response.split("<user>")[0].strip()
109
+
110
+ # Clean up any remaining special tokens
111
+ response = response.replace("<AI>", "").replace("<user>", "").strip()
112
+
113
+ # If empty response, provide a default
114
+ if not response:
115
+ response = "I'm not sure how to respond to that."
116
 
117
  return jsonify({
118
  "response": response,