modprompt 0.0.12 → 0.1.0
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/mod.es.mjs +39 -7
- package/dist/mod.min.js +1 -1
- package/package.json +7 -3
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",
|
|
@@ -37,6 +43,14 @@ const templates = {
|
|
|
37
43
|
"user": 1
|
|
38
44
|
},
|
|
39
45
|
},
|
|
46
|
+
"amazon": {
|
|
47
|
+
"id": "amazon",
|
|
48
|
+
"name": "Amazon",
|
|
49
|
+
"user": "<|prompter|>{prompt}</s>",
|
|
50
|
+
"assistant": "<|assistant|>",
|
|
51
|
+
"afterShot": "\n",
|
|
52
|
+
"stop": ["</s>"],
|
|
53
|
+
},
|
|
40
54
|
"mistral": {
|
|
41
55
|
"id": "mistral",
|
|
42
56
|
"name": "Mistral",
|
|
@@ -116,12 +130,30 @@ const templates = {
|
|
|
116
130
|
"stop": ["<|im_end|>"],
|
|
117
131
|
"afterShot": " <|im_end|>",
|
|
118
132
|
},
|
|
119
|
-
"
|
|
120
|
-
"id": "
|
|
121
|
-
"name": "
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
"zephyr": {
|
|
134
|
+
"id": "zephyr",
|
|
135
|
+
"name": "Zephyr",
|
|
136
|
+
"system": {
|
|
137
|
+
"schema": "<|system|>\n{system}</s>",
|
|
138
|
+
},
|
|
139
|
+
"user": "<|user|>\n{prompt}</s>",
|
|
140
|
+
"assistant": "<|assistant|>",
|
|
141
|
+
"linebreaks": {
|
|
142
|
+
"system": 1,
|
|
143
|
+
"user": 1,
|
|
144
|
+
"assistant": 1,
|
|
145
|
+
},
|
|
146
|
+
"afterShot": "\n",
|
|
147
|
+
},
|
|
148
|
+
"synthia-cot": {
|
|
149
|
+
"id": "synthia-cot",
|
|
150
|
+
"name": "Synthia CoT",
|
|
151
|
+
"system": {
|
|
152
|
+
"schema": "SYSTEM: {system}",
|
|
153
|
+
"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."
|
|
154
|
+
},
|
|
155
|
+
"user": "USER: {prompt}",
|
|
156
|
+
"assistant": "ASSISTANT:",
|
|
125
157
|
},
|
|
126
158
|
"wizardlm": {
|
|
127
159
|
"id": "wizardlm",
|
|
@@ -347,7 +379,7 @@ class PromptTemplate {
|
|
|
347
379
|
buf.push("\n".repeat(this.linebreaks.assistant));
|
|
348
380
|
}
|
|
349
381
|
if (msg) {
|
|
350
|
-
buf
|
|
382
|
+
buf.push(msg);
|
|
351
383
|
}
|
|
352
384
|
return buf.join("");
|
|
353
385
|
}
|
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:"[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:{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}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modprompt",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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",
|