SEE7 commited on
Commit
effa79e
·
verified ·
1 Parent(s): 434757e

Stream Thinking content as a stable prefix and strip Harmony role transitions

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -32,10 +32,10 @@ def generate(inputs,max_tokens,temperature,mode):
32
  raw+=chunk
33
  if final_marker in raw:
34
  before,answer=raw.split(final_marker,1);answer=clean(answer)
35
- thought=clean(before.split(analysis_marker,1)[-1])
36
  visible=("<think>"+thought+"</think>\n\n" if mode=="Thinking" and thought.strip() else "")+answer
37
  elif mode=="Thinking" and analysis_marker in raw:
38
- visible="<think>"+clean(raw.split(analysis_marker,1)[-1])+"</think>"
39
  if visible:yield visible
40
  thread.join(timeout=2)
41
  if errors:raise gr.Error("Generation failed. Please retry with a shorter conversation.")
 
32
  raw+=chunk
33
  if final_marker in raw:
34
  before,answer=raw.split(final_marker,1);answer=clean(answer)
35
+ thought=clean(re.sub(r"<\|end\|>.*$","",before.split(analysis_marker,1)[-1],flags=re.S))
36
  visible=("<think>"+thought+"</think>\n\n" if mode=="Thinking" and thought.strip() else "")+answer
37
  elif mode=="Thinking" and analysis_marker in raw:
38
+ visible="<think>"+clean(re.sub(r"<\|end\|>.*$","",raw.split(analysis_marker,1)[-1],flags=re.S))
39
  if visible:yield visible
40
  thread.join(timeout=2)
41
  if errors:raise gr.Error("Generation failed. Please retry with a shorter conversation.")