modprompt 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -97,6 +97,26 @@ To append to a system message:
97
97
  tpl.afterSystem("You are a javascript specialist");
98
98
  ```
99
99
 
100
+ Note: some templates does have a system schema but no default system message. Some templates
101
+ don't even have a system block. The default `render` will show the system schema: exemple for the Vicuna system template:
102
+
103
+ ```
104
+ SYSTEM: {system}
105
+
106
+ USER: {prompt}
107
+
108
+ ### ASSISTANT:
109
+ ```
110
+
111
+ In case of empty system message it is possible to skip it using the
112
+ `skip_empty_system` option: outptut of `tpl.render(true)`:
113
+
114
+ ```
115
+ USER: {prompt}
116
+
117
+ ### ASSISTANT:
118
+ ```
119
+
100
120
  ### Example shots
101
121
 
102
122
  The templates have support for example shots. Add one shot:
package/dist/cls.d.ts CHANGED
@@ -22,7 +22,7 @@ declare class PromptTemplate {
22
22
  afterAssistant(msg: string): PromptTemplate;
23
23
  replacePrompt(msg: string): PromptTemplate;
24
24
  addShot(user: string, assistant: string): PromptTemplate;
25
- render(): string;
25
+ render(skip_empty_system?: boolean): string;
26
26
  prompt(msg: string): string;
27
27
  private _buildSystemBlock;
28
28
  private _buildUserBlock;
package/dist/mod.es.mjs CHANGED
@@ -92,6 +92,7 @@ const templates = {
92
92
  "user": "USER: {prompt}",
93
93
  "assistant": "### ASSISTANT:",
94
94
  "linebreaks": {
95
+ "system": 2,
95
96
  "user": 2
96
97
  },
97
98
  },
@@ -154,6 +155,10 @@ const templates = {
154
155
  },
155
156
  "user": "USER: {prompt}",
156
157
  "assistant": "ASSISTANT:",
158
+ "linebreaks": {
159
+ "system": 1,
160
+ "user": 1,
161
+ },
157
162
  },
158
163
  "wizardlm": {
159
164
  "id": "wizardlm",
@@ -177,21 +182,7 @@ const templates = {
177
182
  "user": 2,
178
183
  "assistant": 1
179
184
  },
180
- },
181
- "coding_assistant": {
182
- "id": "coding_assistant",
183
- "name": "Coding assistant",
184
- "system": {
185
- "schema": "{system}",
186
- "message": "You are a coding assistant that will help the user to resolve the following instruction:"
187
- },
188
- "user": "### Instruction: {prompt}",
189
- "assistant": "### Solution:",
190
- "linebreaks": {
191
- "user": 2,
192
- "system": 1,
193
- },
194
- },
185
+ }
195
186
  };
196
187
 
197
188
  class PromptTemplate {
@@ -305,12 +296,12 @@ class PromptTemplate {
305
296
  });
306
297
  return this;
307
298
  }
308
- render() {
299
+ render(skip_empty_system = false) {
309
300
  const buf = new Array();
310
301
  if (this.prefix) {
311
302
  buf.push(this.prefix);
312
303
  }
313
- const _systemBlock = this._buildSystemBlock();
304
+ const _systemBlock = this._buildSystemBlock(skip_empty_system);
314
305
  if (_systemBlock.length > 0) {
315
306
  buf.push(_systemBlock);
316
307
  if (this?.linebreaks?.system) {
@@ -337,7 +328,7 @@ class PromptTemplate {
337
328
  prompt(msg) {
338
329
  return this.render().replace("{prompt}", msg);
339
330
  }
340
- _buildSystemBlock() {
331
+ _buildSystemBlock(skip_empty_system = false) {
341
332
  let res = "";
342
333
  if (!this?.system) {
343
334
  return "";
@@ -351,6 +342,9 @@ class PromptTemplate {
351
342
  res = res + this._extraSystem;
352
343
  }
353
344
  }
345
+ else if (!skip_empty_system) {
346
+ res = this.system.schema;
347
+ }
354
348
  return res;
355
349
  }
356
350
  _buildUserBlock(msg) {
package/dist/mod.min.js CHANGED
@@ -1 +1 @@
1
- var $tpl=function(s){"use strict";const t={none:{id:"none",name:"No template",user:"{prompt}",assistant:""},alpaca:{id:"alpaca",name:"Alpaca",system:{schema:"{system}",message:"Below is an instruction that describes a task. Write a response that appropriately completes the request."},user:"### Instruction:\n{prompt}",assistant:"### Response:",linebreaks:{system:2,user:2}},llama:{id:"llama",name:"Llama",system:{schema:"[INST] <<SYS>>\n{system}\n<</SYS>>",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."},user:"{prompt}",assistant:" [/INST] ",linebreaks:{system:2,user:0},prefix:"<s>"},llama_instruct:{id:"llama_instruct",name:"Llama instruct",user:"[INST] {prompt}",assistant:" [/INST]",linebreaks:{user:1}},amazon:{id:"amazon",name:"Amazon",user:"<|prompter|>{prompt}</s>",assistant:"<|assistant|>",afterShot:"\n",stop:["</s>"]},mistral:{id:"mistral",name:"Mistral",user:"[INST] {prompt}",assistant:" [/INST]",stop:["</s>"],afterShot:"\n",prefix:"<s>"},orca:{id:"orca",name:"Orca",system:{schema:"### System:\n{system}",message:"You are an AI assistant that follows instruction extremely well. Help as much as you can."},user:"### User:\n{prompt}",assistant:"### Response:",linebreaks:{system:2,user:2}},vicuna:{id:"vicuna",name:"Vicuna",user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2}},vicuna_system:{id:"vicuna_system",name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2}},wizard_vicuna:{id:"wizard_vicuna",name:"Wizard Vicuna",user:"### Human:\n{prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2},stop:["<|endoftext|>"]},guanaco:{id:"guanaco",name:"Guanaco",user:"### Human: {prompt}",assistant:"### Assistant:",linebreaks:{user:1}},chatml:{id:"chatml",name:"ChatMl",system:{schema:"<|im_start|>system\n{system}\n<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>",assistant:"<|im_start|>assistant",linebreaks:{system:1,user:1,assistant:1},stop:["<|im_end|>"],afterShot:" <|im_end|>"},zephyr:{id:"zephyr",name:"Zephyr",system:{schema:"<|system|>\n{system}</s>"},user:"<|user|>\n{prompt}</s>",assistant:"<|assistant|>",linebreaks:{system:1,user:1,assistant:1},afterShot:"\n"},"synthia-cot":{id:"synthia-cot",name:"Synthia CoT",system:{schema:"SYSTEM: {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."},user:"USER: {prompt}",assistant:"ASSISTANT:"},wizardlm:{id:"wizardlm",name:"WizardLM",system:{schema:"{system}",message:"You are a helpful AI assistant."},user:"USER: {prompt}",assistant:"ASSISTANT:",linebreaks:{user:1}},human_response:{id:"human_response",name:"Human response",user:"### HUMAN:\n{prompt}",assistant:"### RESPONSE:",linebreaks:{user:2,assistant:1}},coding_assistant:{id:"coding_assistant",name:"Coding assistant",system:{schema:"{system}",message:"You are a coding assistant that will help the user to resolve the following instruction:"},user:"### Instruction: {prompt}",assistant:"### Solution:",linebreaks:{user:2,system:1}}};class e{id;name;user;assistant;system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let t;t="string"==typeof s?this._load(s):s,this.id=t.id,this.name=t.name,this.user=t.user,this.assistant=t.assistant,this.system=t.system,this.shots=t.shots,this.stop=t.stop,this.linebreaks=t.linebreaks,this.afterShot=t.afterShot,this.prefix=t.prefix}cloneTo(s,t=!0){const a=new e(s);return t&&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?.system&&(this.system=this.system),this?.shots&&(this.shots=this.shots),this?.stop&&(this.stop=this.stop),this?.linebreaks&&(this.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,t){this?.shots||(this.shots=[]);let e=t;return this.shots.push({user:s,assistant:e}),this}render(){const s=new Array;this.prefix&&s.push(this.prefix);const t=this._buildSystemBlock();if(t.length>0&&(s.push(t),this?.linebreaks?.system&&s.push("\n".repeat(this.linebreaks.system))),this?.shots)for(const t of this.shots){s.push(this._buildUserBlock(t.user));let e=t.assistant;this.afterShot?e+=this.afterShot:e+="\n\n",s.push(this._buildAssistantBlock(e))}return s.push(this._buildUserBlock()),s.push(this._buildAssistantBlock()),s.join("")}prompt(s){return this.render().replace("{prompt}",s)}_buildSystemBlock(){let s="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message&&(s=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(s+=this._extraSystem)),s):""}_buildUserBlock(s){let t=[],e=this.user;return this._replacePrompt.length>0&&(e=e.replace("{prompt}",this._replacePrompt)),t.push(e),this?.linebreaks?.user&&t.push("\n".repeat(this.linebreaks.user)),s&&(t[0]=e.replace("{prompt}",s)),t.join("")}_buildAssistantBlock(s){let t=[],e=this.assistant;return this._extraAssistant.length>0&&(e+=this._extraAssistant),t.push(e),this?.linebreaks?.assistant&&t.push("\n".repeat(this.linebreaks.assistant)),s&&t.push(s),t.join("")}_load(s){try{if(s in t)return t[s];throw new Error(`Template ${s} not found`)}catch(t){throw new Error(`Error loading template ${s}: ${t}`)}}}return s.PromptTemplate=e,s.templates=t,s}({});
1
+ var $tpl=function(s){"use strict";const t={none:{id:"none",name:"No template",user:"{prompt}",assistant:""},alpaca:{id:"alpaca",name:"Alpaca",system:{schema:"{system}",message:"Below is an instruction that describes a task. Write a response that appropriately completes the request."},user:"### Instruction:\n{prompt}",assistant:"### Response:",linebreaks:{system:2,user:2}},llama:{id:"llama",name:"Llama",system:{schema:"[INST] <<SYS>>\n{system}\n<</SYS>>",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."},user:"{prompt}",assistant:" [/INST] ",linebreaks:{system:2,user:0},prefix:"<s>"},llama_instruct:{id:"llama_instruct",name:"Llama instruct",user:"[INST] {prompt}",assistant:" [/INST]",linebreaks:{user:1}},amazon:{id:"amazon",name:"Amazon",user:"<|prompter|>{prompt}</s>",assistant:"<|assistant|>",afterShot:"\n",stop:["</s>"]},mistral:{id:"mistral",name:"Mistral",user:"[INST] {prompt}",assistant:" [/INST]",stop:["</s>"],afterShot:"\n",prefix:"<s>"},orca:{id:"orca",name:"Orca",system:{schema:"### System:\n{system}",message:"You are an AI assistant that follows instruction extremely well. Help as much as you can."},user:"### User:\n{prompt}",assistant:"### Response:",linebreaks:{system:2,user:2}},vicuna:{id:"vicuna",name:"Vicuna",user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2}},vicuna_system:{id:"vicuna_system",name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{system:2,user:2}},wizard_vicuna:{id:"wizard_vicuna",name:"Wizard Vicuna",user:"### Human:\n{prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2},stop:["<|endoftext|>"]},guanaco:{id:"guanaco",name:"Guanaco",user:"### Human: {prompt}",assistant:"### Assistant:",linebreaks:{user:1}},chatml:{id:"chatml",name:"ChatMl",system:{schema:"<|im_start|>system\n{system}\n<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>",assistant:"<|im_start|>assistant",linebreaks:{system:1,user:1,assistant:1},stop:["<|im_end|>"],afterShot:" <|im_end|>"},zephyr:{id:"zephyr",name:"Zephyr",system:{schema:"<|system|>\n{system}</s>"},user:"<|user|>\n{prompt}</s>",assistant:"<|assistant|>",linebreaks:{system:1,user:1,assistant:1},afterShot:"\n"},"synthia-cot":{id:"synthia-cot",name:"Synthia CoT",system:{schema:"SYSTEM: {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."},user:"USER: {prompt}",assistant:"ASSISTANT:",linebreaks:{system:1,user:1}},wizardlm:{id:"wizardlm",name:"WizardLM",system:{schema:"{system}",message:"You are a helpful AI assistant."},user:"USER: {prompt}",assistant:"ASSISTANT:",linebreaks:{user:1}},human_response:{id:"human_response",name:"Human response",user:"### HUMAN:\n{prompt}",assistant:"### RESPONSE:",linebreaks:{user:2,assistant:1}}};class e{id;name;user;assistant;system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let t;t="string"==typeof s?this._load(s):s,this.id=t.id,this.name=t.name,this.user=t.user,this.assistant=t.assistant,this.system=t.system,this.shots=t.shots,this.stop=t.stop,this.linebreaks=t.linebreaks,this.afterShot=t.afterShot,this.prefix=t.prefix}cloneTo(s,t=!0){const a=new e(s);return t&&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?.system&&(this.system=this.system),this?.shots&&(this.shots=this.shots),this?.stop&&(this.stop=this.stop),this?.linebreaks&&(this.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,t){this?.shots||(this.shots=[]);let e=t;return this.shots.push({user:s,assistant:e}),this}render(s=!1){const t=new Array;this.prefix&&t.push(this.prefix);const e=this._buildSystemBlock(s);if(e.length>0&&(t.push(e),this?.linebreaks?.system&&t.push("\n".repeat(this.linebreaks.system))),this?.shots)for(const s of this.shots){t.push(this._buildUserBlock(s.user));let e=s.assistant;this.afterShot?e+=this.afterShot:e+="\n\n",t.push(this._buildAssistantBlock(e))}return t.push(this._buildUserBlock()),t.push(this._buildAssistantBlock()),t.join("")}prompt(s){return this.render().replace("{prompt}",s)}_buildSystemBlock(s=!1){let t="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(t=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(t+=this._extraSystem)):s||(t=this.system.schema),t):""}_buildUserBlock(s){let t=[],e=this.user;return this._replacePrompt.length>0&&(e=e.replace("{prompt}",this._replacePrompt)),t.push(e),this?.linebreaks?.user&&t.push("\n".repeat(this.linebreaks.user)),s&&(t[0]=e.replace("{prompt}",s)),t.join("")}_buildAssistantBlock(s){let t=[],e=this.assistant;return this._extraAssistant.length>0&&(e+=this._extraAssistant),t.push(e),this?.linebreaks?.assistant&&t.push("\n".repeat(this.linebreaks.assistant)),s&&t.push(s),t.join("")}_load(s){try{if(s in t)return t[s];throw new Error(`Template ${s} not found`)}catch(t){throw new Error(`Error loading template ${s}: ${t}`)}}}return s.PromptTemplate=e,s.templates=t,s}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modprompt",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Prompt templates for language models",
5
5
  "license": "MIT",
6
6
  "scripts": {