modprompt 0.9.6 → 0.10.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/cls.d.ts +5 -1
- package/dist/interfaces.d.ts +8 -1
- package/dist/main.js +81 -7
- package/dist/main.min.js +1 -1
- package/package.json +11 -11
package/dist/cls.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LmTemplate, PromptBlock, TurnBlock, SpacingSlots, HistoryTurn } from "./interfaces.js";
|
|
1
|
+
import { LmTemplate, PromptBlock, TurnBlock, SpacingSlots, HistoryTurn, LmToolsDef } from "./interfaces.js";
|
|
2
2
|
/**
|
|
3
3
|
* Represents a modified language model template.
|
|
4
4
|
*
|
|
@@ -11,6 +11,8 @@ declare class PromptTemplate {
|
|
|
11
11
|
user: string;
|
|
12
12
|
assistant: string;
|
|
13
13
|
history: Array<HistoryTurn>;
|
|
14
|
+
toolsDef: LmToolsDef;
|
|
15
|
+
tools: Array<Record<string, any>>;
|
|
14
16
|
system?: PromptBlock;
|
|
15
17
|
shots?: Array<TurnBlock>;
|
|
16
18
|
stop?: Array<string>;
|
|
@@ -30,6 +32,7 @@ declare class PromptTemplate {
|
|
|
30
32
|
* const tpl = new PromptTemplate('alpaca');
|
|
31
33
|
*/
|
|
32
34
|
constructor(template: string | LmTemplate);
|
|
35
|
+
addTool(tool: Record<string, any>): PromptTemplate;
|
|
33
36
|
/**
|
|
34
37
|
* Clones the current `PromptTemplate` instance to a new instance of `PromptTemplate`.
|
|
35
38
|
*
|
|
@@ -164,6 +167,7 @@ declare class PromptTemplate {
|
|
|
164
167
|
*/
|
|
165
168
|
pushToHistory(turn: HistoryTurn): PromptTemplate;
|
|
166
169
|
private _buildSystemBlock;
|
|
170
|
+
private _buildToolsBlock;
|
|
167
171
|
private _buildUserBlock;
|
|
168
172
|
private _buildAssistantBlock;
|
|
169
173
|
private _load;
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface SpacingSlots {
|
|
|
24
24
|
* Number of line breaks to be applied after the assistant message.
|
|
25
25
|
*/
|
|
26
26
|
assistant?: number;
|
|
27
|
+
tools?: number;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Represents a block of system-level prompts or instructions in the conversation.
|
|
@@ -67,6 +68,11 @@ interface TurnBlock {
|
|
|
67
68
|
*/
|
|
68
69
|
assistant: string;
|
|
69
70
|
}
|
|
71
|
+
interface LmToolsDef {
|
|
72
|
+
def: string;
|
|
73
|
+
call: string;
|
|
74
|
+
response: string;
|
|
75
|
+
}
|
|
70
76
|
/**
|
|
71
77
|
* Represents a template for language modeling, detailing the structure and interaction elements of a conversation.
|
|
72
78
|
*
|
|
@@ -115,6 +121,7 @@ interface LmTemplate {
|
|
|
115
121
|
* Useful for simulating multi-turn interactions.
|
|
116
122
|
*/
|
|
117
123
|
shots?: Array<TurnBlock>;
|
|
124
|
+
tools?: LmToolsDef;
|
|
118
125
|
/**
|
|
119
126
|
* Optional array of strings that signal the end of a conversation.
|
|
120
127
|
*
|
|
@@ -157,4 +164,4 @@ interface HistoryTurn {
|
|
|
157
164
|
assistant: string;
|
|
158
165
|
images?: Array<ImgData>;
|
|
159
166
|
}
|
|
160
|
-
export { SpacingSlots, PromptBlock, TurnBlock, LmTemplate, HistoryTurn, ImgData };
|
|
167
|
+
export { SpacingSlots, PromptBlock, TurnBlock, LmTemplate, HistoryTurn, ImgData, LmToolsDef };
|
package/dist/main.js
CHANGED
|
@@ -128,15 +128,65 @@ const templates = {
|
|
|
128
128
|
],
|
|
129
129
|
"user": "<start_of_turn>user\n{prompt}"
|
|
130
130
|
},
|
|
131
|
-
"
|
|
132
|
-
"assistant": "
|
|
133
|
-
"id": "
|
|
131
|
+
"granite": {
|
|
132
|
+
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
133
|
+
"id": "granite",
|
|
134
134
|
"linebreaks": {
|
|
135
|
-
"
|
|
136
|
-
"user":
|
|
135
|
+
"system": 1,
|
|
136
|
+
"user": 1
|
|
137
|
+
},
|
|
138
|
+
"name": "Granite",
|
|
139
|
+
"stop": [
|
|
140
|
+
"<|end_of_text|>",
|
|
141
|
+
"<|start_of_role|>"
|
|
142
|
+
],
|
|
143
|
+
"system": {
|
|
144
|
+
"message": "You are Granite, developed by IBM. You are a helpful AI assistant.",
|
|
145
|
+
"schema": "<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"
|
|
146
|
+
},
|
|
147
|
+
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
148
|
+
},
|
|
149
|
+
"granite-think": {
|
|
150
|
+
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
151
|
+
"id": "granite-think",
|
|
152
|
+
"linebreaks": {
|
|
153
|
+
"system": 1,
|
|
154
|
+
"user": 1
|
|
155
|
+
},
|
|
156
|
+
"name": "Granite think",
|
|
157
|
+
"stop": [
|
|
158
|
+
"<|end_of_text|>",
|
|
159
|
+
"<|start_of_role|>"
|
|
160
|
+
],
|
|
161
|
+
"system": {
|
|
162
|
+
"message": "You are Granite, developed by IBM. You are a helpful AI assistant. Respond to every user query in a comprehensive and detailed way. You can write down your thoughts and reasoning process before responding. In the thought process, engage in a comprehensive cycle of analysis, summarization, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. In the response section, based on various attempts, explorations, and reflections from the thoughts section, systematically present the final solution that you deem correct. The response should summarize the thought process. Write your thoughts after 'Here is my thought process:' and write your response after 'Here is my response:' for each user query.",
|
|
163
|
+
"schema": "<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"
|
|
137
164
|
},
|
|
138
|
-
"
|
|
139
|
-
|
|
165
|
+
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
166
|
+
},
|
|
167
|
+
"granite-tools": {
|
|
168
|
+
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
169
|
+
"id": "granite-tools",
|
|
170
|
+
"linebreaks": {
|
|
171
|
+
"system": 1,
|
|
172
|
+
"tools": 1,
|
|
173
|
+
"user": 1
|
|
174
|
+
},
|
|
175
|
+
"name": "Granite tools",
|
|
176
|
+
"stop": [
|
|
177
|
+
"<|end_of_text|>",
|
|
178
|
+
"<|start_of_role|>"
|
|
179
|
+
],
|
|
180
|
+
"system": {
|
|
181
|
+
"message": "You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.",
|
|
182
|
+
"schema": "<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"
|
|
183
|
+
},
|
|
184
|
+
"tools": {
|
|
185
|
+
"call": "<|tool_call|>",
|
|
186
|
+
"def": "<|start_of_role|>tools<|end_of_role|>{tools}<|end_of_text|>",
|
|
187
|
+
"response": "<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>"
|
|
188
|
+
},
|
|
189
|
+
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
140
190
|
},
|
|
141
191
|
"llama": {
|
|
142
192
|
"assistant": " [/INST] ",
|
|
@@ -400,6 +450,8 @@ class PromptTemplate {
|
|
|
400
450
|
user;
|
|
401
451
|
assistant;
|
|
402
452
|
history = [];
|
|
453
|
+
toolsDef;
|
|
454
|
+
tools = [];
|
|
403
455
|
system;
|
|
404
456
|
shots;
|
|
405
457
|
stop;
|
|
@@ -437,6 +489,11 @@ class PromptTemplate {
|
|
|
437
489
|
this.linebreaks = tpl.linebreaks;
|
|
438
490
|
this.afterShot = tpl.afterShot;
|
|
439
491
|
this.prefix = tpl.prefix;
|
|
492
|
+
this.toolsDef = tpl?.tools ?? { def: "", call: "", response: "" };
|
|
493
|
+
}
|
|
494
|
+
addTool(tool) {
|
|
495
|
+
this.tools.push(tool);
|
|
496
|
+
return this;
|
|
440
497
|
}
|
|
441
498
|
/**
|
|
442
499
|
* Clones the current `PromptTemplate` instance to a new instance of `PromptTemplate`.
|
|
@@ -658,6 +715,14 @@ class PromptTemplate {
|
|
|
658
715
|
buf.push("\n".repeat(this.linebreaks.system));
|
|
659
716
|
}
|
|
660
717
|
}
|
|
718
|
+
// tools
|
|
719
|
+
const _toolsBlock = this._buildToolsBlock();
|
|
720
|
+
if (_toolsBlock.length > 0) {
|
|
721
|
+
buf.push(_toolsBlock);
|
|
722
|
+
if (this?.linebreaks?.tools) {
|
|
723
|
+
buf.push("\n".repeat(this.linebreaks.tools));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
661
726
|
// shots
|
|
662
727
|
if (this?.shots) {
|
|
663
728
|
for (const shot of this.shots) {
|
|
@@ -717,6 +782,15 @@ class PromptTemplate {
|
|
|
717
782
|
}
|
|
718
783
|
return res;
|
|
719
784
|
}
|
|
785
|
+
_buildToolsBlock() {
|
|
786
|
+
let toolsBlock = "";
|
|
787
|
+
if (this.tools.length == 0) {
|
|
788
|
+
return "";
|
|
789
|
+
}
|
|
790
|
+
const _t = JSON.stringify(this.tools);
|
|
791
|
+
toolsBlock += this.toolsDef.def.replace("{tools}", _t);
|
|
792
|
+
return toolsBlock;
|
|
793
|
+
}
|
|
720
794
|
_buildUserBlock(msg) {
|
|
721
795
|
let buf = [];
|
|
722
796
|
// prompt replacement
|
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},chatml:{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},codestral:{afterShot:"\n",assistant:" [/INST]",id:"codestral",linebreaks:{system:2},name:"Codestral",stop:["</s>"],system:{schema:"<<SYS>>\n{system}\n<</SYS>>"},user:"[INST] {prompt}"},"command-r":{assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",linebreaks:{user:1},name:"Command-R",prefix:"<BOS_TOKEN>",stop:["<|END_OF_TURN_TOKEN|>"],system:{schema:"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{system}<|END_OF_TURN_TOKEN|>"},user:"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"},deepseek:{afterShot:"\n",assistant:"### Response:",id:"deepseek",linebreaks:{system:1,user:1},name:"Deepseek",stop:["<|EOT|>","### Instruction:"],system:{message:"You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.",schema:"{system}"},user:"### Instruction:\n{prompt}"},deepseek2:{assistant:"Assistant:",id:"deepseek2",linebreaks:{system:2,user:2},name:"Deepseek 2",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"User: {prompt}"},deepseek3:{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3",linebreaks:{system:2,user:2},name:"Deepseek 3",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"<|User|>{prompt}"},gemma:{afterShot:"\n",assistant:"<end_of_turn>\n<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}"},human_response:{assistant:"### RESPONSE:",id:"human_response",linebreaks:{assistant:1,user:2},name:"Human response",user:"### HUMAN:\n{prompt}"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{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.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},"mistral-system":{afterShot:"\n",assistant:"[/INST]",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},user:"[INST]{prompt}"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},octopus:{afterShot:"\n",assistant:"<|assistant|>",id:"octopus",name:"Octopus",stop:["<|end|>"],system:{message:"You are a router. Below is the query from the users, please call the correct function and generate the parameters to call the function.",schema:"<|system|>{system}<|end|>"},user:"<|user|>{prompt}<|end|>"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},opencodeinterpreter:{assistant:"<|Assistant|>",id:"opencodeinterpreter",linebreaks:{user:2},name:"Open code interpreter",stop:["<|EOT|>","<|User|>"],user:"<|User|>\n{prompt}"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi3:{afterShot:"<|end|>\n",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let e;e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix}cloneTo(s,e=!0){const a=new t(s);return e&&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?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.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,e){this?.shots||(this.shots=[]);let t=e;return this.shots.push({user:s,assistant:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t=this._buildSystemBlock(s);if(t.length>0&&(e.push(t),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this?.shots)for(const s of this.shots)e.push(this.renderShot(s));for(const s of this.history)e.push(this.renderShot(s));return e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s,e=!0){return this.render(e).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s){let e="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(e=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(e+=this._extraSystem)):s||(e=this.system.schema),e):""}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}}return s.PromptTemplate=t,s.templates=e,s}({});
|
|
1
|
+
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},chatml:{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},codestral:{afterShot:"\n",assistant:" [/INST]",id:"codestral",linebreaks:{system:2},name:"Codestral",stop:["</s>"],system:{schema:"<<SYS>>\n{system}\n<</SYS>>"},user:"[INST] {prompt}"},"command-r":{assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",linebreaks:{user:1},name:"Command-R",prefix:"<BOS_TOKEN>",stop:["<|END_OF_TURN_TOKEN|>"],system:{schema:"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{system}<|END_OF_TURN_TOKEN|>"},user:"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"},deepseek:{afterShot:"\n",assistant:"### Response:",id:"deepseek",linebreaks:{system:1,user:1},name:"Deepseek",stop:["<|EOT|>","### Instruction:"],system:{message:"You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.",schema:"{system}"},user:"### Instruction:\n{prompt}"},deepseek2:{assistant:"Assistant:",id:"deepseek2",linebreaks:{system:2,user:2},name:"Deepseek 2",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"User: {prompt}"},deepseek3:{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3",linebreaks:{system:2,user:2},name:"Deepseek 3",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"<|User|>{prompt}"},gemma:{afterShot:"\n",assistant:"<end_of_turn>\n<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}"},granite:{assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite",linebreaks:{system:1,user:1},name:"Granite",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},"granite-think":{assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite-think",linebreaks:{system:1,user:1},name:"Granite think",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant. Respond to every user query in a comprehensive and detailed way. You can write down your thoughts and reasoning process before responding. In the thought process, engage in a comprehensive cycle of analysis, summarization, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. In the response section, based on various attempts, explorations, and reflections from the thoughts section, systematically present the final solution that you deem correct. The response should summarize the thought process. Write your thoughts after 'Here is my thought process:' and write your response after 'Here is my response:' for each user query.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},"granite-tools":{assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite-tools",linebreaks:{system:1,tools:1,user:1},name:"Granite tools",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},tools:{call:"<|tool_call|>",def:"<|start_of_role|>tools<|end_of_role|>{tools}<|end_of_text|>",response:"<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{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.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},"mistral-system":{afterShot:"\n",assistant:"[/INST]",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},user:"[INST]{prompt}"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},octopus:{afterShot:"\n",assistant:"<|assistant|>",id:"octopus",name:"Octopus",stop:["<|end|>"],system:{message:"You are a router. Below is the query from the users, please call the correct function and generate the parameters to call the function.",schema:"<|system|>{system}<|end|>"},user:"<|user|>{prompt}<|end|>"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},opencodeinterpreter:{assistant:"<|Assistant|>",id:"opencodeinterpreter",linebreaks:{user:2},name:"Open code interpreter",stop:["<|EOT|>","<|User|>"],user:"<|User|>\n{prompt}"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi3:{afterShot:"<|end|>\n",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];toolsDef;tools=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let e;e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix,this.toolsDef=e?.tools??{def:"",call:"",response:""}}addTool(s){return this.tools.push(s),this}cloneTo(s,e=!0){const a=new t(s);return e&&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?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.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,e){this?.shots||(this.shots=[]);let t=e;return this.shots.push({user:s,assistant:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t=this._buildSystemBlock(s);t.length>0&&(e.push(t),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system)));const a=this._buildToolsBlock();if(a.length>0&&(e.push(a),this?.linebreaks?.tools&&e.push("\n".repeat(this.linebreaks.tools))),this?.shots)for(const s of this.shots)e.push(this.renderShot(s));for(const s of this.history)e.push(this.renderShot(s));return e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s,e=!0){return this.render(e).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s){let e="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(e=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(e+=this._extraSystem)):s||(e=this.system.schema),e):""}_buildToolsBlock(){let s="";if(0==this.tools.length)return"";const e=JSON.stringify(this.tools);return s+=this.toolsDef.def.replace("{tools}",e),s}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}}return s.PromptTemplate=t,s.templates=e,s}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modprompt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Prompt templates for language models",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -9,21 +9,21 @@
|
|
|
9
9
|
"docs": "typedoc --entryPointStrategy expand"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@rollup/plugin-node-resolve": "^
|
|
12
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
13
13
|
"@rollup/plugin-terser": "^0.4.4",
|
|
14
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
14
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
15
15
|
"@types/expect": "^24.3.2",
|
|
16
16
|
"@types/jest": "^29.5.14",
|
|
17
|
-
"@types/node": "^22.8
|
|
17
|
+
"@types/node": "^22.13.8",
|
|
18
18
|
"jest": "^29.7.0",
|
|
19
|
-
"rollup": "^4.
|
|
20
|
-
"ts-jest": "^29.2.
|
|
19
|
+
"rollup": "^4.34.9",
|
|
20
|
+
"ts-jest": "^29.2.6",
|
|
21
21
|
"ts-node": "^10.9.2",
|
|
22
|
-
"tslib": "^2.8.
|
|
23
|
-
"typedoc": "^0.
|
|
24
|
-
"typedoc-plugin-markdown": "^4.2
|
|
25
|
-
"typedoc-plugin-rename-defaults": "^0.7.
|
|
26
|
-
"typescript": "^5.
|
|
22
|
+
"tslib": "^2.8.1",
|
|
23
|
+
"typedoc": "^0.27.9",
|
|
24
|
+
"typedoc-plugin-markdown": "^4.4.2",
|
|
25
|
+
"typedoc-plugin-rename-defaults": "^0.7.2",
|
|
26
|
+
"typescript": "^5.8.2"
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
29
|
"files": [
|