Rijgersberg commited on
Commit
31bf44d
1 Parent(s): 5946569

Fix chat template application

Browse files
Files changed (1) hide show
  1. app.py +1 -1
app.py CHANGED
@@ -40,7 +40,7 @@ def generate(
40
  conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
41
  conversation.append({"role": "user", "content": message})
42
 
43
- input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
44
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
45
  input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
46
  gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
 
40
  conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
41
  conversation.append({"role": "user", "content": message})
42
 
43
+ input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
44
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
45
  input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
46
  gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")