pvduy commited on
Commit
adf28c0
1 Parent(s): 2678de3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -30,7 +30,7 @@ def predict(message, history, system_prompt, temperature, max_tokens):
30
  messages.append({'role': 'user', 'content': message})
31
  problem = [tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)]
32
  stop_tokens = ["<|endoftext|>", "<|im_end|>"]
33
- streamer = TextIteratorStreamer(tokenizer, timeout=100.0, skip_prompt=True, skip_special_tokens=False)
34
  enc = tokenizer(problem, return_tensors="pt", padding=True, truncation=True)
35
  input_ids = enc.input_ids
36
  attention_mask = enc.attention_mask
@@ -54,7 +54,12 @@ def predict(message, history, system_prompt, temperature, max_tokens):
54
  outputs = []
55
  for text in streamer:
56
  outputs.append(text)
57
- if text in stop_tokens:
 
 
 
 
 
58
  break
59
  print(text)
60
  yield "".join(outputs)
 
30
  messages.append({'role': 'user', 'content': message})
31
  problem = [tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)]
32
  stop_tokens = ["<|endoftext|>", "<|im_end|>"]
33
+ streamer = TextIteratorStreamer(tokenizer, timeout=100.0, skip_prompt=True, skip_special_tokens=True)
34
  enc = tokenizer(problem, return_tensors="pt", padding=True, truncation=True)
35
  input_ids = enc.input_ids
36
  attention_mask = enc.attention_mask
 
54
  outputs = []
55
  for text in streamer:
56
  outputs.append(text)
57
+ stop = False
58
+ for tok in stop_tokens:
59
+ if tok in text:
60
+ stop = True
61
+ break
62
+ if stop:
63
  break
64
  print(text)
65
  yield "".join(outputs)