modprompt 0.0.9 → 0.0.10
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 -1
- package/dist/mod.es.mjs +31 -23
- package/dist/mod.min.js +1 -1
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ declare class PromptTemplate {
|
|
|
8
8
|
shots?: Array<TurnBlock>;
|
|
9
9
|
stop?: Array<string>;
|
|
10
10
|
linebreaks?: SpacingSlots;
|
|
11
|
-
|
|
11
|
+
_extraSystem: string;
|
|
12
|
+
_extraAssistant: string;
|
|
12
13
|
constructor(template: string | LmTemplate);
|
|
13
14
|
cloneTo(name: string): PromptTemplate;
|
|
14
15
|
toJson(): LmTemplate;
|
package/dist/mod.es.mjs
CHANGED
|
@@ -166,7 +166,8 @@ class PromptTemplate {
|
|
|
166
166
|
shots;
|
|
167
167
|
stop;
|
|
168
168
|
linebreaks;
|
|
169
|
-
|
|
169
|
+
_extraSystem = "";
|
|
170
|
+
_extraAssistant = "";
|
|
170
171
|
constructor(template) {
|
|
171
172
|
let tpl;
|
|
172
173
|
if (typeof template == "string") {
|
|
@@ -191,9 +192,6 @@ class PromptTemplate {
|
|
|
191
192
|
if (tpl?.linebreaks) {
|
|
192
193
|
this.linebreaks = tpl.linebreaks;
|
|
193
194
|
}
|
|
194
|
-
if (tpl?.system) {
|
|
195
|
-
this._systemBlock = this._buildSystemBlock();
|
|
196
|
-
}
|
|
197
195
|
}
|
|
198
196
|
cloneTo(name) {
|
|
199
197
|
const tpl = new PromptTemplate(name);
|
|
@@ -209,9 +207,13 @@ class PromptTemplate {
|
|
|
209
207
|
if (this?.linebreaks) {
|
|
210
208
|
tpl.linebreaks = this.linebreaks;
|
|
211
209
|
}
|
|
212
|
-
if (
|
|
213
|
-
tpl.
|
|
210
|
+
if (this._extraSystem.length > 0) {
|
|
211
|
+
tpl.afterSystem(this._extraSystem);
|
|
214
212
|
}
|
|
213
|
+
if (this._extraAssistant.length > 0) {
|
|
214
|
+
tpl.afterAssistant(this._extraAssistant);
|
|
215
|
+
}
|
|
216
|
+
tpl.user = this.user;
|
|
215
217
|
return tpl;
|
|
216
218
|
}
|
|
217
219
|
toJson() {
|
|
@@ -236,21 +238,24 @@ class PromptTemplate {
|
|
|
236
238
|
return res;
|
|
237
239
|
}
|
|
238
240
|
replaceSystem(msg) {
|
|
239
|
-
|
|
241
|
+
if (!this.system) {
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
this.system.message = msg;
|
|
240
245
|
return this;
|
|
241
246
|
}
|
|
242
247
|
afterSystem(msg) {
|
|
243
248
|
if (!this.system) {
|
|
244
|
-
|
|
249
|
+
return this;
|
|
245
250
|
}
|
|
246
251
|
if (!this.system?.message) {
|
|
247
252
|
this.system.message = "";
|
|
248
253
|
}
|
|
249
|
-
this.
|
|
254
|
+
this._extraSystem = msg;
|
|
250
255
|
return this;
|
|
251
256
|
}
|
|
252
257
|
afterAssistant(msg) {
|
|
253
|
-
this.
|
|
258
|
+
this._extraAssistant = msg;
|
|
254
259
|
return this;
|
|
255
260
|
}
|
|
256
261
|
replacePrompt(msg) {
|
|
@@ -269,8 +274,9 @@ class PromptTemplate {
|
|
|
269
274
|
}
|
|
270
275
|
render() {
|
|
271
276
|
const buf = new Array();
|
|
272
|
-
|
|
273
|
-
|
|
277
|
+
const _systemBlock = this._buildSystemBlock();
|
|
278
|
+
if (_systemBlock.length > 0) {
|
|
279
|
+
buf.push(_systemBlock);
|
|
274
280
|
if (this?.linebreaks?.system) {
|
|
275
281
|
buf.push("\n".repeat(this.linebreaks.system));
|
|
276
282
|
}
|
|
@@ -288,21 +294,19 @@ class PromptTemplate {
|
|
|
288
294
|
prompt(msg) {
|
|
289
295
|
return this.render().replace("{prompt}", msg);
|
|
290
296
|
}
|
|
291
|
-
_buildSystemBlock(
|
|
297
|
+
_buildSystemBlock() {
|
|
292
298
|
let res = "";
|
|
293
299
|
if (!this?.system) {
|
|
294
|
-
|
|
300
|
+
return "";
|
|
295
301
|
}
|
|
296
|
-
if (
|
|
297
|
-
res = this.system.schema.replace("{system}",
|
|
302
|
+
if (this.system?.message) {
|
|
303
|
+
res = this.system.schema.replace("{system}", this.system.message);
|
|
298
304
|
}
|
|
299
305
|
else {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
res = this.system.schema;
|
|
305
|
-
}
|
|
306
|
+
res = this.system.schema.replace("{system}", "");
|
|
307
|
+
}
|
|
308
|
+
if (this._extraSystem) {
|
|
309
|
+
res = res + this._extraSystem;
|
|
306
310
|
}
|
|
307
311
|
return res;
|
|
308
312
|
}
|
|
@@ -319,7 +323,11 @@ class PromptTemplate {
|
|
|
319
323
|
}
|
|
320
324
|
_buildAssistantBlock(msg) {
|
|
321
325
|
let buf = [];
|
|
322
|
-
|
|
326
|
+
let amsg = this.assistant;
|
|
327
|
+
if (this._extraAssistant.length > 0) {
|
|
328
|
+
amsg += this._extraAssistant;
|
|
329
|
+
}
|
|
330
|
+
buf.push(amsg);
|
|
323
331
|
if (this?.linebreaks?.assistant) {
|
|
324
332
|
buf.push("\n".repeat(this.linebreaks.assistant));
|
|
325
333
|
}
|
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:"<s>[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}},llama_instruct:{id:"llama_instruct",name:"Llama instruct",user:"[INST] {prompt}",assistant:" [/INST]",linebreaks:{user:1}},mistral:{id:"mistral",name:"Mistral",user:"<s>[INST] {prompt}",assistant:" [/INST]",stop:["</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}},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;
|
|
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:"<s>[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}},llama_instruct:{id:"llama_instruct",name:"Llama instruct",user:"[INST] {prompt}",assistant:" [/INST]",linebreaks:{user:1}},mistral:{id:"mistral",name:"Mistral",user:"<s>[INST] {prompt}",assistant:" [/INST]",stop:["</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}},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;_extraSystem="";_extraAssistant="";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,t?.system&&(this.system=t.system),t?.shots&&(this.shots=t.shots),t?.stop&&(this.stop=t.stop),t?.linebreaks&&(this.linebreaks=t.linebreaks)}cloneTo(s){const t=new e(s);return this?.system&&(t.system=this.system),this?.shots&&(t.shots=this.shots),this?.stop&&(t.stop=this.stop),this?.linebreaks&&(t.linebreaks=this.linebreaks),this._extraSystem.length>0&&t.afterSystem(this._extraSystem),this._extraAssistant.length>0&&t.afterAssistant(this._extraAssistant),t.user=this.user,t}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.system.message=s,this):this}afterSystem(s){return this.system?(this.system?.message||(this.system.message=""),this._extraSystem=s,this):this}afterAssistant(s){return this._extraAssistant=s,this}replacePrompt(s){return this.user=this.user.replace("{prompt}",s),this}addShot(s,t){return this?.shots||(this.shots=[]),this.shots.push({user:s,assistant:t}),this}render(){const s=new Array,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)),s.push(this._buildAssistantBlock(t.assistant));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?(s=this.system?.message?this.system.schema.replace("{system}",this.system.message):this.system.schema.replace("{system}",""),this._extraSystem&&(s+=this._extraSystem),s):""}_buildUserBlock(s){let t=[];return t.push(this.user),this?.linebreaks?.user&&t.push("\n".repeat(this.linebreaks.user)),s&&(t[0]=t[0].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+"\n"),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}({});
|