modprompt 0.0.11 → 0.0.13
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 +2 -0
- package/dist/interfaces.d.ts +2 -0
- package/dist/mod.es.mjs +38 -30
- package/dist/mod.min.js +1 -1
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
package/dist/interfaces.d.ts
CHANGED
package/dist/mod.es.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const templates = {
|
|
2
|
+
"none": {
|
|
3
|
+
"id": "none",
|
|
4
|
+
"name": "No template",
|
|
5
|
+
"user": "{prompt}",
|
|
6
|
+
"assistant": "",
|
|
7
|
+
},
|
|
2
8
|
"alpaca": {
|
|
3
9
|
"id": "alpaca",
|
|
4
10
|
"name": "Alpaca",
|
|
@@ -17,7 +23,7 @@ const templates = {
|
|
|
17
23
|
"id": "llama",
|
|
18
24
|
"name": "Llama",
|
|
19
25
|
"system": {
|
|
20
|
-
"schema": "
|
|
26
|
+
"schema": "[INST] <<SYS>>\n{system}\n<</SYS>>",
|
|
21
27
|
"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."
|
|
22
28
|
},
|
|
23
29
|
"user": "{prompt}",
|
|
@@ -25,7 +31,8 @@ const templates = {
|
|
|
25
31
|
"linebreaks": {
|
|
26
32
|
"system": 2,
|
|
27
33
|
"user": 0
|
|
28
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"prefix": "<s>",
|
|
29
36
|
},
|
|
30
37
|
"llama_instruct": {
|
|
31
38
|
"id": "llama_instruct",
|
|
@@ -39,9 +46,11 @@ const templates = {
|
|
|
39
46
|
"mistral": {
|
|
40
47
|
"id": "mistral",
|
|
41
48
|
"name": "Mistral",
|
|
42
|
-
"user": "
|
|
49
|
+
"user": "[INST] {prompt}",
|
|
43
50
|
"assistant": " [/INST]",
|
|
44
|
-
"stop": ["</s>"]
|
|
51
|
+
"stop": ["</s>"],
|
|
52
|
+
"afterShot": "\n",
|
|
53
|
+
"prefix": "<s>",
|
|
45
54
|
},
|
|
46
55
|
"orca": {
|
|
47
56
|
"id": "orca",
|
|
@@ -55,7 +64,7 @@ const templates = {
|
|
|
55
64
|
"linebreaks": {
|
|
56
65
|
"system": 2,
|
|
57
66
|
"user": 2
|
|
58
|
-
}
|
|
67
|
+
},
|
|
59
68
|
},
|
|
60
69
|
"vicuna": {
|
|
61
70
|
"id": "vicuna",
|
|
@@ -110,7 +119,8 @@ const templates = {
|
|
|
110
119
|
"user": 1,
|
|
111
120
|
"assistant": 1,
|
|
112
121
|
},
|
|
113
|
-
"stop": ["<|im_end|>"]
|
|
122
|
+
"stop": ["<|im_end|>"],
|
|
123
|
+
"afterShot": " <|im_end|>",
|
|
114
124
|
},
|
|
115
125
|
"mamba": {
|
|
116
126
|
"id": "mamba",
|
|
@@ -167,6 +177,8 @@ class PromptTemplate {
|
|
|
167
177
|
shots;
|
|
168
178
|
stop;
|
|
169
179
|
linebreaks;
|
|
180
|
+
afterShot;
|
|
181
|
+
prefix;
|
|
170
182
|
_extraSystem = "";
|
|
171
183
|
_extraAssistant = "";
|
|
172
184
|
_replacePrompt = "";
|
|
@@ -183,18 +195,12 @@ class PromptTemplate {
|
|
|
183
195
|
this.name = tpl.name;
|
|
184
196
|
this.user = tpl.user;
|
|
185
197
|
this.assistant = tpl.assistant;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (tpl?.stop) {
|
|
193
|
-
this.stop = tpl.stop;
|
|
194
|
-
}
|
|
195
|
-
if (tpl?.linebreaks) {
|
|
196
|
-
this.linebreaks = tpl.linebreaks;
|
|
197
|
-
}
|
|
198
|
+
this.system = tpl.system;
|
|
199
|
+
this.shots = tpl.shots;
|
|
200
|
+
this.stop = tpl.stop;
|
|
201
|
+
this.linebreaks = tpl.linebreaks;
|
|
202
|
+
this.afterShot = tpl.afterShot;
|
|
203
|
+
this.prefix = tpl.prefix;
|
|
198
204
|
}
|
|
199
205
|
cloneTo(template, keepShots = true) {
|
|
200
206
|
const tpl = new PromptTemplate(template);
|
|
@@ -267,11 +273,6 @@ class PromptTemplate {
|
|
|
267
273
|
this.shots = [];
|
|
268
274
|
}
|
|
269
275
|
let _assistantMsg = assistant;
|
|
270
|
-
if (this.stop) {
|
|
271
|
-
if (this.stop.length > 0) {
|
|
272
|
-
_assistantMsg += this.stop[0];
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
276
|
this.shots.push({
|
|
276
277
|
user: user,
|
|
277
278
|
assistant: _assistantMsg,
|
|
@@ -280,6 +281,9 @@ class PromptTemplate {
|
|
|
280
281
|
}
|
|
281
282
|
render() {
|
|
282
283
|
const buf = new Array();
|
|
284
|
+
if (this.prefix) {
|
|
285
|
+
buf.push(this.prefix);
|
|
286
|
+
}
|
|
283
287
|
const _systemBlock = this._buildSystemBlock();
|
|
284
288
|
if (_systemBlock.length > 0) {
|
|
285
289
|
buf.push(_systemBlock);
|
|
@@ -290,7 +294,14 @@ class PromptTemplate {
|
|
|
290
294
|
if (this?.shots) {
|
|
291
295
|
for (const shot of this.shots) {
|
|
292
296
|
buf.push(this._buildUserBlock(shot.user));
|
|
293
|
-
|
|
297
|
+
let _assistantMsg = shot.assistant;
|
|
298
|
+
if (this.afterShot) {
|
|
299
|
+
_assistantMsg += this.afterShot;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
_assistantMsg += "\n\n";
|
|
303
|
+
}
|
|
304
|
+
buf.push(this._buildAssistantBlock(_assistantMsg));
|
|
294
305
|
}
|
|
295
306
|
}
|
|
296
307
|
buf.push(this._buildUserBlock());
|
|
@@ -310,12 +321,9 @@ class PromptTemplate {
|
|
|
310
321
|
}
|
|
311
322
|
if (this.system?.message) {
|
|
312
323
|
res = this.system.schema.replace("{system}", this.system.message);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
if (this._extraSystem) {
|
|
318
|
-
res = res + this._extraSystem;
|
|
324
|
+
if (this._extraSystem) {
|
|
325
|
+
res = res + this._extraSystem;
|
|
326
|
+
}
|
|
319
327
|
}
|
|
320
328
|
return res;
|
|
321
329
|
}
|
package/dist/mod.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const t={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:"
|
|
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|>"},mamba:{id:"mamba",name:"Mamba",user:"<|prompt|>{prompt}</s>",assistant:"<|answer|>",stop:["<|endoftext|>"]},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[0]=t[0]+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}({});
|