Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,8 +92,10 @@ def generate(
|
|
| 92 |
for user, assistant in chat_history:
|
| 93 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 94 |
conversation.append({"role": "user", "content": make_prompt(message)})
|
| 95 |
-
enc = tokenizer(make_prompt(message), return_tensors="pt", padding=True, truncation=True)
|
| 96 |
-
input_ids = enc.input_ids.to(model.device)
|
|
|
|
|
|
|
| 97 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
| 98 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
| 99 |
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
|
|
|
|
| 92 |
for user, assistant in chat_history:
|
| 93 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 94 |
conversation.append({"role": "user", "content": make_prompt(message)})
|
| 95 |
+
# enc = tokenizer(make_prompt(message), return_tensors="pt", padding=True, truncation=True)
|
| 96 |
+
# input_ids = enc.input_ids.to(model.device)
|
| 97 |
+
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
|
| 98 |
+
|
| 99 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
| 100 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
| 101 |
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
|