modprompt 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cls.d.ts +1 -1
- package/dist/main.js +16 -56
- package/dist/main.min.js +1 -1
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ declare class PromptTemplate {
|
|
|
155
155
|
* const prompted = tpl.prompt("list the planets in the solar system");
|
|
156
156
|
* console.log(prompted);
|
|
157
157
|
*/
|
|
158
|
-
prompt(msg: string): string;
|
|
158
|
+
prompt(msg: string, skip_empty_system?: boolean): string;
|
|
159
159
|
/**
|
|
160
160
|
* Push a turn into history
|
|
161
161
|
*
|
package/dist/main.js
CHANGED
|
@@ -14,23 +14,6 @@ const templates = {
|
|
|
14
14
|
},
|
|
15
15
|
"user": "### Instruction:\n{prompt}"
|
|
16
16
|
},
|
|
17
|
-
"cerebrum": {
|
|
18
|
-
"assistant": "Ai:",
|
|
19
|
-
"id": "cerebrum",
|
|
20
|
-
"linebreaks": {
|
|
21
|
-
"user": 1
|
|
22
|
-
},
|
|
23
|
-
"name": "Cerebrum",
|
|
24
|
-
"prefix": "<s>",
|
|
25
|
-
"stop": [
|
|
26
|
-
"</s>"
|
|
27
|
-
],
|
|
28
|
-
"system": {
|
|
29
|
-
"message": "A chat between a user and a thinking artificial intelligence assistant. The assistant describes its thought process and gives helpful and detailed answers to the user's questions.",
|
|
30
|
-
"schema": "{system}"
|
|
31
|
-
},
|
|
32
|
-
"user": "User: {prompt}"
|
|
33
|
-
},
|
|
34
17
|
"chatml": {
|
|
35
18
|
"afterShot": " <|im_end|>\n",
|
|
36
19
|
"assistant": "<|im_start|>assistant",
|
|
@@ -145,15 +128,6 @@ const templates = {
|
|
|
145
128
|
],
|
|
146
129
|
"user": "<start_of_turn>user\n{prompt}"
|
|
147
130
|
},
|
|
148
|
-
"guanaco": {
|
|
149
|
-
"assistant": "### Assistant:",
|
|
150
|
-
"id": "guanaco",
|
|
151
|
-
"linebreaks": {
|
|
152
|
-
"user": 1
|
|
153
|
-
},
|
|
154
|
-
"name": "Guanaco",
|
|
155
|
-
"user": "### Human: {prompt}"
|
|
156
|
-
},
|
|
157
131
|
"human_response": {
|
|
158
132
|
"assistant": "### RESPONSE:",
|
|
159
133
|
"id": "human_response",
|
|
@@ -227,6 +201,19 @@ const templates = {
|
|
|
227
201
|
],
|
|
228
202
|
"user": "[INST] {prompt}"
|
|
229
203
|
},
|
|
204
|
+
"mistral-system": {
|
|
205
|
+
"afterShot": "\n",
|
|
206
|
+
"assistant": "[/INST]",
|
|
207
|
+
"id": "mistral-system",
|
|
208
|
+
"name": "Mistral system",
|
|
209
|
+
"stop": [
|
|
210
|
+
"</s>"
|
|
211
|
+
],
|
|
212
|
+
"system": {
|
|
213
|
+
"schema": "[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"
|
|
214
|
+
},
|
|
215
|
+
"user": "[INST]{prompt}"
|
|
216
|
+
},
|
|
230
217
|
"nemotron": {
|
|
231
218
|
"afterShot": "\n\n",
|
|
232
219
|
"assistant": "<extra_id_1>Assistant",
|
|
@@ -306,19 +293,6 @@ const templates = {
|
|
|
306
293
|
},
|
|
307
294
|
"user": "### User:\n{prompt}"
|
|
308
295
|
},
|
|
309
|
-
"phi": {
|
|
310
|
-
"assistant": "Output:",
|
|
311
|
-
"id": "phi",
|
|
312
|
-
"linebreaks": {
|
|
313
|
-
"user": 1
|
|
314
|
-
},
|
|
315
|
-
"name": "Phi",
|
|
316
|
-
"stop": [
|
|
317
|
-
"</s>",
|
|
318
|
-
"Instruct:"
|
|
319
|
-
],
|
|
320
|
-
"user": "Instruct: {prompt}"
|
|
321
|
-
},
|
|
322
296
|
"phi3": {
|
|
323
297
|
"afterShot": "<|end|>\n",
|
|
324
298
|
"assistant": "<|assistant|>",
|
|
@@ -347,20 +321,6 @@ const templates = {
|
|
|
347
321
|
},
|
|
348
322
|
"user": "<|im_start|>user<|im_sep|>{prompt}<|im_end|>"
|
|
349
323
|
},
|
|
350
|
-
"synthia-cot": {
|
|
351
|
-
"assistant": "ASSISTANT:",
|
|
352
|
-
"id": "synthia-cot",
|
|
353
|
-
"linebreaks": {
|
|
354
|
-
"system": 1,
|
|
355
|
-
"user": 1
|
|
356
|
-
},
|
|
357
|
-
"name": "Synthia CoT",
|
|
358
|
-
"system": {
|
|
359
|
-
"message": "Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.",
|
|
360
|
-
"schema": "SYSTEM: {system}"
|
|
361
|
-
},
|
|
362
|
-
"user": "USER: {prompt}"
|
|
363
|
-
},
|
|
364
324
|
"vicuna": {
|
|
365
325
|
"assistant": "### ASSISTANT:",
|
|
366
326
|
"id": "vicuna",
|
|
@@ -684,7 +644,7 @@ class PromptTemplate {
|
|
|
684
644
|
* const rendered = tpl.render();
|
|
685
645
|
* console.log(rendered);
|
|
686
646
|
*/
|
|
687
|
-
render(skip_empty_system =
|
|
647
|
+
render(skip_empty_system = true) {
|
|
688
648
|
const buf = new Array();
|
|
689
649
|
// prefix
|
|
690
650
|
if (this.prefix) {
|
|
@@ -725,8 +685,8 @@ class PromptTemplate {
|
|
|
725
685
|
* const prompted = tpl.prompt("list the planets in the solar system");
|
|
726
686
|
* console.log(prompted);
|
|
727
687
|
*/
|
|
728
|
-
prompt(msg) {
|
|
729
|
-
return this.render().replace("{prompt}", msg);
|
|
688
|
+
prompt(msg, skip_empty_system = true) {
|
|
689
|
+
return this.render(skip_empty_system).replace("{prompt}", msg);
|
|
730
690
|
}
|
|
731
691
|
/**
|
|
732
692
|
* Push a turn into history
|
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},cerebrum:{assistant:"Ai:",id:"cerebrum",linebreaks:{user:1},name:"Cerebrum",prefix:"<s>",stop:["</s>"],system:{message:"A chat between a user and a thinking artificial intelligence assistant. The assistant describes its thought process and gives helpful and detailed answers to the user's questions.",schema:"{system}"},user:"User: {prompt}"},chatml:{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},codestral:{afterShot:"\n",assistant:" [/INST]",id:"codestral",linebreaks:{system:2},name:"Codestral",stop:["</s>"],system:{schema:"<<SYS>>\n{system}\n<</SYS>>"},user:"[INST] {prompt}"},"command-r":{assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",linebreaks:{user:1},name:"Command-R",prefix:"<BOS_TOKEN>",stop:["<|END_OF_TURN_TOKEN|>"],system:{schema:"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{system}<|END_OF_TURN_TOKEN|>"},user:"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"},deepseek:{afterShot:"\n",assistant:"### Response:",id:"deepseek",linebreaks:{system:1,user:1},name:"Deepseek",stop:["<|EOT|>","### Instruction:"],system:{message:"You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.",schema:"{system}"},user:"### Instruction:\n{prompt}"},deepseek2:{assistant:"Assistant:",id:"deepseek2",linebreaks:{system:2,user:2},name:"Deepseek 2",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"User: {prompt}"},deepseek3:{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3",linebreaks:{system:2,user:2},name:"Deepseek 3",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"<|User|>{prompt}"},gemma:{afterShot:"\n",assistant:"<end_of_turn>\n<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}"},guanaco:{assistant:"### Assistant:",id:"guanaco",linebreaks:{user:1},name:"Guanaco",user:"### Human: {prompt}"},human_response:{assistant:"### RESPONSE:",id:"human_response",linebreaks:{assistant:1,user:2},name:"Human response",user:"### HUMAN:\n{prompt}"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{message:"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},octopus:{afterShot:"\n",assistant:"<|assistant|>",id:"octopus",name:"Octopus",stop:["<|end|>"],system:{message:"You are a router. Below is the query from the users, please call the correct function and generate the parameters to call the function.",schema:"<|system|>{system}<|end|>"},user:"<|user|>{prompt}<|end|>"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},opencodeinterpreter:{assistant:"<|Assistant|>",id:"opencodeinterpreter",linebreaks:{user:2},name:"Open code interpreter",stop:["<|EOT|>","<|User|>"],user:"<|User|>\n{prompt}"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi:{assistant:"Output:",id:"phi",linebreaks:{user:1},name:"Phi",stop:["</s>","Instruct:"],user:"Instruct: {prompt}"},phi3:{afterShot:"<|end|>\n",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},"synthia-cot":{assistant:"ASSISTANT:",id:"synthia-cot",linebreaks:{system:1,user:1},name:"Synthia CoT",system:{message:"Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.",schema:"SYSTEM: {system}"},user:"USER: {prompt}"},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let e;e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix}cloneTo(s,e=!0){const a=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{a.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&a.afterSystem(this._extraSystem),this._replaceSystem.length>0&&a.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&a.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&a.replacePrompt(this._replacePrompt),a}toJson(){const s={id:this.id,name:this.name,user:this.user,assistant:this.assistant};return this?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.linebreaks=this.linebreaks),s}replaceSystem(s){return this.system?(this._replaceSystem=s,this):this}afterSystem(s){return this.system?(this._extraSystem=s,this):this}afterAssistant(s){return this._extraAssistant=s,this}replacePrompt(s){return this._replacePrompt=s,this}addShot(s,e){this?.shots||(this.shots=[]);let t=e;return this.shots.push({user:s,assistant:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),e.join("")}render(s=!1){const e=new Array;this.prefix&&e.push(this.prefix);const t=this._buildSystemBlock(s);if(t.length>0&&(e.push(t),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this?.shots)for(const s of this.shots)e.push(this.renderShot(s));for(const s of this.history)e.push(this.renderShot(s));return e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s){return this.render().replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s){let e="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(e=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(e+=this._extraSystem)):s||(e=this.system.schema),e):""}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}}return s.PromptTemplate=t,s.templates=e,s}({});
|
|
1
|
+
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},chatml:{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},codestral:{afterShot:"\n",assistant:" [/INST]",id:"codestral",linebreaks:{system:2},name:"Codestral",stop:["</s>"],system:{schema:"<<SYS>>\n{system}\n<</SYS>>"},user:"[INST] {prompt}"},"command-r":{assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",linebreaks:{user:1},name:"Command-R",prefix:"<BOS_TOKEN>",stop:["<|END_OF_TURN_TOKEN|>"],system:{schema:"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{system}<|END_OF_TURN_TOKEN|>"},user:"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"},deepseek:{afterShot:"\n",assistant:"### Response:",id:"deepseek",linebreaks:{system:1,user:1},name:"Deepseek",stop:["<|EOT|>","### Instruction:"],system:{message:"You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.",schema:"{system}"},user:"### Instruction:\n{prompt}"},deepseek2:{assistant:"Assistant:",id:"deepseek2",linebreaks:{system:2,user:2},name:"Deepseek 2",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"User: {prompt}"},deepseek3:{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3",linebreaks:{system:2,user:2},name:"Deepseek 3",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"<|User|>{prompt}"},gemma:{afterShot:"\n",assistant:"<end_of_turn>\n<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}"},human_response:{assistant:"### RESPONSE:",id:"human_response",linebreaks:{assistant:1,user:2},name:"Human response",user:"### HUMAN:\n{prompt}"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{message:"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},"mistral-system":{afterShot:"\n",assistant:"[/INST]",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},user:"[INST]{prompt}"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},octopus:{afterShot:"\n",assistant:"<|assistant|>",id:"octopus",name:"Octopus",stop:["<|end|>"],system:{message:"You are a router. Below is the query from the users, please call the correct function and generate the parameters to call the function.",schema:"<|system|>{system}<|end|>"},user:"<|user|>{prompt}<|end|>"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},opencodeinterpreter:{assistant:"<|Assistant|>",id:"opencodeinterpreter",linebreaks:{user:2},name:"Open code interpreter",stop:["<|EOT|>","<|User|>"],user:"<|User|>\n{prompt}"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi3:{afterShot:"<|end|>\n",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let e;e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix}cloneTo(s,e=!0){const a=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{a.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&a.afterSystem(this._extraSystem),this._replaceSystem.length>0&&a.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&a.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&a.replacePrompt(this._replacePrompt),a}toJson(){const s={id:this.id,name:this.name,user:this.user,assistant:this.assistant};return this?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.linebreaks=this.linebreaks),s}replaceSystem(s){return this.system?(this._replaceSystem=s,this):this}afterSystem(s){return this.system?(this._extraSystem=s,this):this}afterAssistant(s){return this._extraAssistant=s,this}replacePrompt(s){return this._replacePrompt=s,this}addShot(s,e){this?.shots||(this.shots=[]);let t=e;return this.shots.push({user:s,assistant:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t=this._buildSystemBlock(s);if(t.length>0&&(e.push(t),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this?.shots)for(const s of this.shots)e.push(this.renderShot(s));for(const s of this.history)e.push(this.renderShot(s));return e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s,e=!0){return this.render(e).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s){let e="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(e=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(e+=this._extraSystem)):s||(e=this.system.schema),e):""}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}}return s.PromptTemplate=t,s.templates=e,s}({});
|