modprompt 0.0.8 → 0.0.9
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 +4 -4
- package/dist/cls.d.ts +3 -2
- package/dist/interfaces.d.ts +1 -0
- package/dist/mod.es.mjs +23 -0
- package/dist/mod.min.js +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -36,11 +36,11 @@ console.log(templateNames);
|
|
|
36
36
|
To load a template:
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
|
-
import { templates,
|
|
39
|
+
import { templates, PromptTemplate } from "modprompt";
|
|
40
40
|
|
|
41
|
-
const tpl = new
|
|
41
|
+
const tpl = new PromptTemplate(templates.alpaca)
|
|
42
42
|
// or
|
|
43
|
-
const tpl = new
|
|
43
|
+
const tpl = new PromptTemplate("alpaca")
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
### Render a template
|
|
@@ -158,7 +158,7 @@ fix this invalid json:
|
|
|
158
158
|
The calls can be chained. Example with the code above:
|
|
159
159
|
|
|
160
160
|
```js
|
|
161
|
-
const tpl = new
|
|
161
|
+
const tpl = new PromptTemplate(templates.llama)
|
|
162
162
|
.afterSystem("You are a javascript specialist")
|
|
163
163
|
.afterAssistant(" (answer in valid json)")
|
|
164
164
|
.replacePrompt("fix this invalid json:\n\n```json\n{prompt}\n```")
|
package/dist/cls.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LmTemplate, PromptBlock, TurnBlock, SpacingSlots } from "./interfaces";
|
|
2
|
-
declare class PromptTemplate
|
|
2
|
+
declare class PromptTemplate {
|
|
3
|
+
id: string;
|
|
3
4
|
name: string;
|
|
4
5
|
user: string;
|
|
5
6
|
assistant: string;
|
|
@@ -7,7 +8,7 @@ declare class PromptTemplate implements LmTemplate {
|
|
|
7
8
|
shots?: Array<TurnBlock>;
|
|
8
9
|
stop?: Array<string>;
|
|
9
10
|
linebreaks?: SpacingSlots;
|
|
10
|
-
|
|
11
|
+
_systemBlock: string;
|
|
11
12
|
constructor(template: string | LmTemplate);
|
|
12
13
|
cloneTo(name: string): PromptTemplate;
|
|
13
14
|
toJson(): LmTemplate;
|
package/dist/interfaces.d.ts
CHANGED
package/dist/mod.es.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const templates = {
|
|
2
2
|
"alpaca": {
|
|
3
|
+
"id": "alpaca",
|
|
3
4
|
"name": "Alpaca",
|
|
4
5
|
"system": {
|
|
5
6
|
"schema": "{system}",
|
|
@@ -13,6 +14,7 @@ const templates = {
|
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"llama": {
|
|
17
|
+
"id": "llama",
|
|
16
18
|
"name": "Llama",
|
|
17
19
|
"system": {
|
|
18
20
|
"schema": "<s>[INST] <<SYS>>\n{system}\n<</SYS>>",
|
|
@@ -26,6 +28,7 @@ const templates = {
|
|
|
26
28
|
}
|
|
27
29
|
},
|
|
28
30
|
"llama_instruct": {
|
|
31
|
+
"id": "llama_instruct",
|
|
29
32
|
"name": "Llama instruct",
|
|
30
33
|
"user": "[INST] {prompt}",
|
|
31
34
|
"assistant": " [/INST]",
|
|
@@ -33,7 +36,15 @@ const templates = {
|
|
|
33
36
|
"user": 1
|
|
34
37
|
},
|
|
35
38
|
},
|
|
39
|
+
"mistral": {
|
|
40
|
+
"id": "mistral",
|
|
41
|
+
"name": "Mistral",
|
|
42
|
+
"user": "<s>[INST] {prompt}",
|
|
43
|
+
"assistant": " [/INST]",
|
|
44
|
+
"stop": ["</s>"]
|
|
45
|
+
},
|
|
36
46
|
"orca": {
|
|
47
|
+
"id": "orca",
|
|
37
48
|
"name": "Orca",
|
|
38
49
|
"system": {
|
|
39
50
|
"schema": "### System:\n{system}",
|
|
@@ -47,6 +58,7 @@ const templates = {
|
|
|
47
58
|
}
|
|
48
59
|
},
|
|
49
60
|
"vicuna": {
|
|
61
|
+
"id": "vicuna",
|
|
50
62
|
"name": "Vicuna",
|
|
51
63
|
"user": "USER: {prompt}",
|
|
52
64
|
"assistant": "### ASSISTANT:",
|
|
@@ -55,6 +67,7 @@ const templates = {
|
|
|
55
67
|
},
|
|
56
68
|
},
|
|
57
69
|
"vicuna_system": {
|
|
70
|
+
"id": "vicuna_system",
|
|
58
71
|
"name": "Vicuna system",
|
|
59
72
|
"system": {
|
|
60
73
|
"schema": "SYSTEM: {system}",
|
|
@@ -66,6 +79,7 @@ const templates = {
|
|
|
66
79
|
},
|
|
67
80
|
},
|
|
68
81
|
"wizard_vicuna": {
|
|
82
|
+
"id": "wizard_vicuna",
|
|
69
83
|
"name": "Wizard Vicuna",
|
|
70
84
|
"user": "### Human:\n{prompt}",
|
|
71
85
|
"assistant": "### ASSISTANT:",
|
|
@@ -75,6 +89,7 @@ const templates = {
|
|
|
75
89
|
"stop": ["<|endoftext|>"]
|
|
76
90
|
},
|
|
77
91
|
"guanaco": {
|
|
92
|
+
"id": "guanaco",
|
|
78
93
|
"name": "Guanaco",
|
|
79
94
|
"user": "### Human: {prompt}",
|
|
80
95
|
"assistant": "### Assistant:",
|
|
@@ -83,6 +98,7 @@ const templates = {
|
|
|
83
98
|
},
|
|
84
99
|
},
|
|
85
100
|
"chatml": {
|
|
101
|
+
"id": "chatml",
|
|
86
102
|
"name": "ChatMl",
|
|
87
103
|
"system": {
|
|
88
104
|
"schema": "<|im_start|>system\n{system}\n<|im_end|>",
|
|
@@ -96,12 +112,14 @@ const templates = {
|
|
|
96
112
|
}
|
|
97
113
|
},
|
|
98
114
|
"mamba": {
|
|
115
|
+
"id": "mamba",
|
|
99
116
|
"name": "Mamba",
|
|
100
117
|
"user": "<|prompt|>{prompt}</s>",
|
|
101
118
|
"assistant": "<|answer|>",
|
|
102
119
|
"stop": ["<|endoftext|>"]
|
|
103
120
|
},
|
|
104
121
|
"wizardlm": {
|
|
122
|
+
"id": "wizardlm",
|
|
105
123
|
"name": "WizardLM",
|
|
106
124
|
"system": {
|
|
107
125
|
"schema": "{system}",
|
|
@@ -114,6 +132,7 @@ const templates = {
|
|
|
114
132
|
},
|
|
115
133
|
},
|
|
116
134
|
"human_response": {
|
|
135
|
+
"id": "human_response",
|
|
117
136
|
"name": "Human response",
|
|
118
137
|
"user": "### HUMAN:\n{prompt}",
|
|
119
138
|
"assistant": "### RESPONSE:",
|
|
@@ -123,6 +142,7 @@ const templates = {
|
|
|
123
142
|
},
|
|
124
143
|
},
|
|
125
144
|
"coding_assistant": {
|
|
145
|
+
"id": "coding_assistant",
|
|
126
146
|
"name": "Coding assistant",
|
|
127
147
|
"system": {
|
|
128
148
|
"schema": "{system}",
|
|
@@ -138,6 +158,7 @@ const templates = {
|
|
|
138
158
|
};
|
|
139
159
|
|
|
140
160
|
class PromptTemplate {
|
|
161
|
+
id;
|
|
141
162
|
name;
|
|
142
163
|
user;
|
|
143
164
|
assistant;
|
|
@@ -154,6 +175,7 @@ class PromptTemplate {
|
|
|
154
175
|
else {
|
|
155
176
|
tpl = template;
|
|
156
177
|
}
|
|
178
|
+
this.id = tpl.id;
|
|
157
179
|
this.name = tpl.name;
|
|
158
180
|
this.user = tpl.user;
|
|
159
181
|
this.assistant = tpl.assistant;
|
|
@@ -194,6 +216,7 @@ class PromptTemplate {
|
|
|
194
216
|
}
|
|
195
217
|
toJson() {
|
|
196
218
|
const res = {
|
|
219
|
+
id: this.id,
|
|
197
220
|
name: this.name,
|
|
198
221
|
user: this.user,
|
|
199
222
|
assistant: this.assistant,
|
package/dist/mod.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const t={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:{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:{name:"Llama instruct",user:"[INST] {prompt}",assistant:" [/INST]",linebreaks:{user:1}},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:{name:"Vicuna",user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2}},vicuna_system:{name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2}},wizard_vicuna:{name:"Wizard Vicuna",user:"### Human:\n{prompt}",assistant:"### ASSISTANT:",linebreaks:{user:2},stop:["<|endoftext|>"]},guanaco:{name:"Guanaco",user:"### Human: {prompt}",assistant:"### Assistant:",linebreaks:{user:1}},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:{name:"Mamba",user:"<|prompt|>{prompt}</s>",assistant:"<|answer|>",stop:["<|endoftext|>"]},wizardlm:{name:"WizardLM",system:{schema:"{system}",message:"You are a helpful AI assistant."},user:"USER: {prompt}",assistant:"ASSISTANT:",linebreaks:{user:1}},human_response:{name:"Human response",user:"### HUMAN:\n{prompt}",assistant:"### RESPONSE:",linebreaks:{user:2,assistant:1}},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{name;user;assistant;system;shots;stop;linebreaks;_systemBlock="";constructor(s){let t;t="string"==typeof s?this._load(s):s,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),t?.system&&(this._systemBlock=this._buildSystemBlock())}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),t?.system&&t.replaceSystem(this._buildSystemBlock()),t}toJson(){const s={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._systemBlock=this._buildSystemBlock(s),this}afterSystem(s){if(!this.system)throw new Error("This template has no system var");return this.system?.message||(this.system.message=""),this._systemBlock=this._buildSystemBlock(this.system.message+" "+s),this}afterAssistant(s){return this.assistant=this.assistant+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;if(this._systemBlock.length>0&&(s.push(this._systemBlock),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(s){let t="";if(!this?.system)throw new Error(`The template ${this.name} has no system var`);return t=s?this.system.schema.replace("{system}",s):this.system?.message?this.system.schema.replace("{system}",this.system.message):this.system.schema,t}_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=[];return t.push(this.assistant),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}({});
|
|
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;_systemBlock="";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),t?.system&&(this._systemBlock=this._buildSystemBlock())}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),t?.system&&t.replaceSystem(this._buildSystemBlock()),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._systemBlock=this._buildSystemBlock(s),this}afterSystem(s){if(!this.system)throw new Error("This template has no system var");return this.system?.message||(this.system.message=""),this._systemBlock=this._buildSystemBlock(this.system.message+" "+s),this}afterAssistant(s){return this.assistant=this.assistant+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;if(this._systemBlock.length>0&&(s.push(this._systemBlock),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(s){let t="";if(!this?.system)throw new Error(`The template ${this.name} has no system var`);return t=s?this.system.schema.replace("{system}",s):this.system?.message?this.system.schema.replace("{system}",this.system.message):this.system.schema,t}_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=[];return t.push(this.assistant),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}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modprompt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Prompt templates for language models",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@rollup/plugin-commonjs": "^25.0.4",
|
|
14
13
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
15
14
|
"@rollup/plugin-typescript": "^11.1.3",
|
|
16
15
|
"@types/node": "^20.6.0",
|