var modelFormatter = Class.create();
modelFormatter.prototype = {
initialize: function() {},
tinydolphin: function(messages) {
* This builds the prompt for the tinydolphin model, this uses ecma5 syntax
* <|im_start|>{messages[*].role}
* <|im_start|>{messages[*].role}
* @param {Array of objects} messages {role: 'user', text: 'message'}
* @returns {string} response
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "<|im_start|>system\n" + systemMessage + "\n<|im_end|>\n";
messages.forEach(function(message) {
response += "<|im_start|>" + message.role + "\n" + message.text + "\n<|im_end|>\n";
response += "<|im_start|>assistant\n";
mistral: function(messages) {
* This builds the prompt for the mistral model, this uses ecma5 syntax
<s>[INST] You are a helpful code assistant. Your task is to generate a valid JSON object based on the given information. So for instance the following:
would be converted to:[/INST]
"address": "#1 Samuel St.",
//this model has no role, it's just a system, and then different INST tags for each message
* @param {Array of objects} messages {role: 'user', text: 'message'}
* @returns {string} response
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "<s>[INST]" + systemMessage + "\n";
var lastMessage = messages.pop();
// this will build out the most in the <s>[INST]</s>, then add in the last message
messages.forEach(function(message) {
response += message.text + "\n";
response += "[/INST]\n[INST]\n";
response += lastMessage.text + "\n[/INST]";
phiQA: function(messages) {
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "Instruct: " + systemMessage + "\n";
messages.forEach(function(message) {
response += message.text + "\n";
phi2chat: function(messages) {
* Human: Hello, who are you?
* AI: Greetings! I am an AI research assistant. How can I help you today?
* Human: Can you tell me about the creation of black holes?
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "AI: " + systemMessage + "\n";
messages.forEach(function(message) {
// if message.role == assistant, AI
// if message.role == user, Human
var who = message.role == 'assistant' ? 'AI' : 'Human';
response += who + ": " + message.text + "\n";
tinyLlama: function(messages){
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "<|system|>\n" + systemMessage + "</s>\n";
messages.forEach(function(message) {
response += "<|" + message.role + "|>\n" + message.text + "</s>\n";
llama2: function(messages){
/*[INST] <<SYS>>{{ .System }}<</SYS>>
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "[INST] <<SYS>>" + systemMessage + "<</SYS>>\n";
messages.forEach(function(message) {
response += message.text + "\n";
mistrallite: function(messages){
/**<|prompter|>{{ .System }} {{ .Prompt }}</s><|assistant|>
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "<|prompter|>" + systemMessage + " {{ .Prompt }}</s>\n";
messages.forEach(function(message) {
response += "<|" + message.role + "|>\n" + message.text + "</s>\n";
notus: function(messages){
// if first message is system, then it's the system message
var systemMessage = messages[0].role == 'system' ? messages.shift().text : '';
// if there is no then skip it
response = "<|system|>\n" + systemMessage + "\n</s>\n";
messages.forEach(function(message) {
response += "<|" + message.role + "|>\n" + message.text + "\n</s>\n";
starcoder: function(prefix, suffix){
//"prompt": "<PRE>" + prefix + "<SUF>" + suffix + "<MID>",
return "<PRE>" + prefix + "<SUF>" + suffix + "<MID>";