modprompt 0.0.13 → 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 +20 -0
- package/dist/cls.d.ts +1 -1
- package/dist/mod.es.mjs +45 -25
- package/dist/mod.min.js +1 -1
- package/package.json +7 -3
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
|
@@ -43,6 +43,14 @@ const templates = {
|
|
|
43
43
|
"user": 1
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
+
"amazon": {
|
|
47
|
+
"id": "amazon",
|
|
48
|
+
"name": "Amazon",
|
|
49
|
+
"user": "<|prompter|>{prompt}</s>",
|
|
50
|
+
"assistant": "<|assistant|>",
|
|
51
|
+
"afterShot": "\n",
|
|
52
|
+
"stop": ["</s>"],
|
|
53
|
+
},
|
|
46
54
|
"mistral": {
|
|
47
55
|
"id": "mistral",
|
|
48
56
|
"name": "Mistral",
|
|
@@ -84,6 +92,7 @@ const templates = {
|
|
|
84
92
|
"user": "USER: {prompt}",
|
|
85
93
|
"assistant": "### ASSISTANT:",
|
|
86
94
|
"linebreaks": {
|
|
95
|
+
"system": 2,
|
|
87
96
|
"user": 2
|
|
88
97
|
},
|
|
89
98
|
},
|
|
@@ -122,12 +131,34 @@ const templates = {
|
|
|
122
131
|
"stop": ["<|im_end|>"],
|
|
123
132
|
"afterShot": " <|im_end|>",
|
|
124
133
|
},
|
|
125
|
-
"
|
|
126
|
-
"id": "
|
|
127
|
-
"name": "
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
"zephyr": {
|
|
135
|
+
"id": "zephyr",
|
|
136
|
+
"name": "Zephyr",
|
|
137
|
+
"system": {
|
|
138
|
+
"schema": "<|system|>\n{system}</s>",
|
|
139
|
+
},
|
|
140
|
+
"user": "<|user|>\n{prompt}</s>",
|
|
141
|
+
"assistant": "<|assistant|>",
|
|
142
|
+
"linebreaks": {
|
|
143
|
+
"system": 1,
|
|
144
|
+
"user": 1,
|
|
145
|
+
"assistant": 1,
|
|
146
|
+
},
|
|
147
|
+
"afterShot": "\n",
|
|
148
|
+
},
|
|
149
|
+
"synthia-cot": {
|
|
150
|
+
"id": "synthia-cot",
|
|
151
|
+
"name": "Synthia CoT",
|
|
152
|
+
"system": {
|
|
153
|
+
"schema": "SYSTEM: {system}",
|
|
154
|
+
"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."
|
|
155
|
+
},
|
|
156
|
+
"user": "USER: {prompt}",
|
|
157
|
+
"assistant": "ASSISTANT:",
|
|
158
|
+
"linebreaks": {
|
|
159
|
+
"system": 1,
|
|
160
|
+
"user": 1,
|
|
161
|
+
},
|
|
131
162
|
},
|
|
132
163
|
"wizardlm": {
|
|
133
164
|
"id": "wizardlm",
|
|
@@ -151,21 +182,7 @@ const templates = {
|
|
|
151
182
|
"user": 2,
|
|
152
183
|
"assistant": 1
|
|
153
184
|
},
|
|
154
|
-
}
|
|
155
|
-
"coding_assistant": {
|
|
156
|
-
"id": "coding_assistant",
|
|
157
|
-
"name": "Coding assistant",
|
|
158
|
-
"system": {
|
|
159
|
-
"schema": "{system}",
|
|
160
|
-
"message": "You are a coding assistant that will help the user to resolve the following instruction:"
|
|
161
|
-
},
|
|
162
|
-
"user": "### Instruction: {prompt}",
|
|
163
|
-
"assistant": "### Solution:",
|
|
164
|
-
"linebreaks": {
|
|
165
|
-
"user": 2,
|
|
166
|
-
"system": 1,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
185
|
+
}
|
|
169
186
|
};
|
|
170
187
|
|
|
171
188
|
class PromptTemplate {
|
|
@@ -279,12 +296,12 @@ class PromptTemplate {
|
|
|
279
296
|
});
|
|
280
297
|
return this;
|
|
281
298
|
}
|
|
282
|
-
render() {
|
|
299
|
+
render(skip_empty_system = false) {
|
|
283
300
|
const buf = new Array();
|
|
284
301
|
if (this.prefix) {
|
|
285
302
|
buf.push(this.prefix);
|
|
286
303
|
}
|
|
287
|
-
const _systemBlock = this._buildSystemBlock();
|
|
304
|
+
const _systemBlock = this._buildSystemBlock(skip_empty_system);
|
|
288
305
|
if (_systemBlock.length > 0) {
|
|
289
306
|
buf.push(_systemBlock);
|
|
290
307
|
if (this?.linebreaks?.system) {
|
|
@@ -311,7 +328,7 @@ class PromptTemplate {
|
|
|
311
328
|
prompt(msg) {
|
|
312
329
|
return this.render().replace("{prompt}", msg);
|
|
313
330
|
}
|
|
314
|
-
_buildSystemBlock() {
|
|
331
|
+
_buildSystemBlock(skip_empty_system = false) {
|
|
315
332
|
let res = "";
|
|
316
333
|
if (!this?.system) {
|
|
317
334
|
return "";
|
|
@@ -325,6 +342,9 @@ class PromptTemplate {
|
|
|
325
342
|
res = res + this._extraSystem;
|
|
326
343
|
}
|
|
327
344
|
}
|
|
345
|
+
else if (!skip_empty_system) {
|
|
346
|
+
res = this.system.schema;
|
|
347
|
+
}
|
|
328
348
|
return res;
|
|
329
349
|
}
|
|
330
350
|
_buildUserBlock(msg) {
|
|
@@ -353,7 +373,7 @@ class PromptTemplate {
|
|
|
353
373
|
buf.push("\n".repeat(this.linebreaks.assistant));
|
|
354
374
|
}
|
|
355
375
|
if (msg) {
|
|
356
|
-
buf
|
|
376
|
+
buf.push(msg);
|
|
357
377
|
}
|
|
358
378
|
return buf.join("");
|
|
359
379
|
}
|
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}},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|>"},
|
|
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.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Prompt templates for language models",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -8,13 +8,17 @@
|
|
|
8
8
|
"test": "jest --coverage",
|
|
9
9
|
"docs": "typedoc --entryPointStrategy expand"
|
|
10
10
|
},
|
|
11
|
-
"dependencies": {},
|
|
12
11
|
"devDependencies": {
|
|
13
12
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
13
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
14
14
|
"@rollup/plugin-typescript": "^11.1.3",
|
|
15
|
+
"@types/expect": "^24.3.0",
|
|
16
|
+
"@types/jest": "^29.5.6",
|
|
15
17
|
"@types/node": "^20.6.0",
|
|
18
|
+
"jest": "^29.6.3",
|
|
16
19
|
"rollup": "^3.29.1",
|
|
17
|
-
"
|
|
20
|
+
"ts-jest": "^29.1.1",
|
|
21
|
+
"ts-node": "^10.9.1",
|
|
18
22
|
"tslib": "^2.6.2",
|
|
19
23
|
"typedoc": "^0.25.1",
|
|
20
24
|
"typedoc-plugin-markdown": "^3.15.4",
|