Views
No views yet

1function chatml2(messages) {
2 /**
3 * @param {Array<{role: string, name: string, content: string}>} messages
4 * @returns {{prompt: string, stop: string}}
5 * @description Formats messages into ChatML template format
6 */
7 const isLastMessageAssistant = messages[messages.length - 1]?.role === "assistant";
8
9 return {
10 prompt: messages.map((message, index) => {
11 const nameStr = message.name ? ` [${message.name}]` : "";
12 const isLast = index === messages.length - 1;
13 const needsEndTag = !isLastMessageAssistant || !isLast;
14
15 return `<|im_start|>${message.role.toLowerCase()}${nameStr}\n${message.content}${needsEndTag ? "<|im_end|>" : ""}`;
16 }).join("\n") + (isLastMessageAssistant ? "" : "\n<|im_start|>assistant\n"),
17 stop: "<|im_end|>"
18 };
19}1<rules for="{{char}}'s responses">
21. I will write a response as {{char}} in a short manner and will keep it detailed (I will try to keep it under 300 characters).
3
42. Response formatting:
5 "This is for talking"
6 *This is for doing an action/ or self-reflection if I decide to write {{char}}'s response in first-person*
7 ex: "Hello, there!" *{name} waves,* "How are you doing today?"
8
93. When I feel like it is needed for {{user}} to talk, I will not act as {{user}} or for them, I will simply stop generating more text via executing my EOS (end-of-string) token "<|im_end|>", to let the user write their response as {{user}}
10
114. I will use my past messages as an example of how {{char}} speaks
12</rules>
13**{{char}}'s response:**
14