david-thrower commited on
Commit
20ff6a1
·
verified ·
1 Parent(s): 50a8e40

Update app.py

Browse files

Added a sanitization for the <think> tags

Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -62,6 +62,12 @@ def chat_fn(history, enable_thinking, temperature, top_p, top_k, repetition_pena
62
  )
63
  output_ids = streamer[0][len(inputs.input_ids[0]):]
64
  response = tokenizer.decode(output_ids, skip_special_tokens=True)
 
 
 
 
 
 
65
 
66
  # streaming char-by-char
67
  history.append({"role": "assistant", "content": ""})
 
62
  )
63
  output_ids = streamer[0][len(inputs.input_ids[0]):]
64
  response = tokenizer.decode(output_ids, skip_special_tokens=True)
65
+ if isinstance(response, str):
66
+ response = response.replace('<think>',"# &lt;think&gt;").replace('</think>',"&lt;/think&gt;")
67
+ elif isinstance(response,list):
68
+ response = [paper.replace('<think>',"# &lt;think&gt;").replace('</think>',"&lt;/think&gt;") for paper in response]
69
+ else:
70
+ raise ValueError("Tokenizer response seems malformed; Not a string, nor a list?!?!")
71
 
72
  # streaming char-by-char
73
  history.append({"role": "assistant", "content": ""})