Questions about chat template format (whether to escape newline characters and special characters or not)

#67
by king-crab - opened

I am writing a script to test out the chat capability of the model with the onnxruntime_genai package. My question is: for both the model generated content and the user input content, should I add them as "raw strings" into the prompt or should I escape newline characters and also other special characters before adding the contents into the prompt? In other words, which of the following prompts (note that this is not the few-shot prompt, but rather the conversation prompt that's being constantly updated in each turn) would result in better model generated outputs? Thank you for your time and help in advance!

Prompt containing the "raw strings":

<|user|>
What is 1 + 2?<|end|>
<|assistant|>
1 + 2 equals 3. This is a basic arithmetic addition problem where you add the two numbers together to get the sum.

Here's a simple step-by-step explanation:

1. Start with the number 1.

2. Add 2 to it.

3. The sum of 1 and 2 is 3.

So, the answer to 1 + 2 is 3.<|end|>
<|user|>
What is 3 + 5?<|end|>
<|assistant|>

Prompt with special characters (e.g. newline characters) escaped:

<|user|>
What is 1 + 2?<|end|>
<|assistant|>
1 + 2 equals 3. This is a basic arithmetic addition problem where you add the two numbers together to get the sum.\n\nHere's a simple step-by-step explanation:\n\n1. Start with the number 1.\n\n2. Add 2 to it.\n\n3. The sum of 1 and 2 is 3.\n\nSo, the answer to 1 + 2 is 3.<|end|>
<|user|>
What is 3 + 5?<|end|>
<|assistant|>

Sign up or log in to comment