Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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=
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|