modprompt 0.10.0 → 0.10.2

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 CHANGED
@@ -11,7 +11,7 @@ declare class PromptTemplate {
11
11
  user: string;
12
12
  assistant: string;
13
13
  history: Array<HistoryTurn>;
14
- toolsDef: LmToolsDef;
14
+ toolsDef: LmToolsDef | null;
15
15
  tools: Array<Record<string, any>>;
16
16
  system?: PromptBlock;
17
17
  shots?: Array<TurnBlock>;
@@ -167,6 +167,7 @@ declare class PromptTemplate {
167
167
  */
168
168
  pushToHistory(turn: HistoryTurn): PromptTemplate;
169
169
  private _buildSystemBlock;
170
+ private _buildToolResponse;
170
171
  private _buildToolsBlock;
171
172
  private _buildUserBlock;
172
173
  private _buildAssistantBlock;
@@ -67,6 +67,7 @@ interface TurnBlock {
67
67
  * The corresponding response from the assistant.
68
68
  */
69
69
  assistant: string;
70
+ tool?: string;
70
71
  }
71
72
  interface LmToolsDef {
72
73
  def: string;
@@ -162,6 +163,7 @@ interface ImgData {
162
163
  interface HistoryTurn {
163
164
  user: string;
164
165
  assistant: string;
166
+ tool?: string;
165
167
  images?: Array<ImgData>;
166
168
  }
167
169
  export { SpacingSlots, PromptBlock, TurnBlock, LmTemplate, HistoryTurn, ImgData, LmToolsDef };
package/dist/main.js CHANGED
@@ -32,6 +32,30 @@ const templates = {
32
32
  },
33
33
  "user": "<|im_start|>user\n{prompt}<|im_end|>"
34
34
  },
35
+ "chatml-tools": {
36
+ "afterShot": " <|im_end|>\n",
37
+ "assistant": "<|im_start|>assistant",
38
+ "id": "chatml",
39
+ "linebreaks": {
40
+ "assistant": 1,
41
+ "system": 1,
42
+ "user": 1
43
+ },
44
+ "name": "ChatMl",
45
+ "stop": [
46
+ "<|im_end|>"
47
+ ],
48
+ "system": {
49
+ "message": "You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query.\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\\n{tools}\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\\n</tool_call>",
50
+ "schema": "<|im_start|>system\n{system}<|im_end|>"
51
+ },
52
+ "tools": {
53
+ "call": "<tool_call>\n{tool}\n</tool_call>",
54
+ "def": "{system}",
55
+ "response": "<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|im_end|>\n"
56
+ },
57
+ "user": "<|im_start|>user\n{prompt}<|im_end|>"
58
+ },
35
59
  "codestral": {
36
60
  "afterShot": "\n",
37
61
  "assistant": " [/INST]",
@@ -129,6 +153,7 @@ const templates = {
129
153
  "user": "<start_of_turn>user\n{prompt}"
130
154
  },
131
155
  "granite": {
156
+ "afterShot": "<|end_of_text|>\n",
132
157
  "assistant": "<|start_of_role|>assistant<|end_of_role|>",
133
158
  "id": "granite",
134
159
  "linebreaks": {
@@ -147,6 +172,7 @@ const templates = {
147
172
  "user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
148
173
  },
149
174
  "granite-think": {
175
+ "afterShot": "<|end_of_text|>\n",
150
176
  "assistant": "<|start_of_role|>assistant<|end_of_role|>",
151
177
  "id": "granite-think",
152
178
  "linebreaks": {
@@ -165,6 +191,7 @@ const templates = {
165
191
  "user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
166
192
  },
167
193
  "granite-tools": {
194
+ "afterShot": "<|end_of_text|>\n",
168
195
  "assistant": "<|start_of_role|>assistant<|end_of_role|>",
169
196
  "id": "granite-tools",
170
197
  "linebreaks": {
@@ -184,7 +211,7 @@ const templates = {
184
211
  "tools": {
185
212
  "call": "<|tool_call|>",
186
213
  "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|>"
214
+ "response": "<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>\n"
188
215
  },
189
216
  "user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
190
217
  },
@@ -450,7 +477,7 @@ class PromptTemplate {
450
477
  user;
451
478
  assistant;
452
479
  history = [];
453
- toolsDef;
480
+ toolsDef = null;
454
481
  tools = [];
455
482
  system;
456
483
  shots;
@@ -489,7 +516,9 @@ class PromptTemplate {
489
516
  this.linebreaks = tpl.linebreaks;
490
517
  this.afterShot = tpl.afterShot;
491
518
  this.prefix = tpl.prefix;
492
- this.toolsDef = tpl?.tools ?? { def: "", call: "", response: "" };
519
+ if (tpl?.tools) {
520
+ this.toolsDef = tpl.tools;
521
+ }
493
522
  }
494
523
  addTool(tool) {
495
524
  this.tools.push(tool);
@@ -690,6 +719,9 @@ class PromptTemplate {
690
719
  _assistantMsg += "\n\n"
691
720
  }*/
692
721
  buf.push(this._buildAssistantBlock(_assistantMsg));
722
+ if (shot?.tool) {
723
+ buf.push(this._buildToolResponse(shot.tool));
724
+ }
693
725
  return buf.join("");
694
726
  }
695
727
  /**
@@ -707,35 +739,46 @@ class PromptTemplate {
707
739
  if (this.prefix) {
708
740
  buf.push(this.prefix);
709
741
  }
742
+ const hasSystemTools = this?.toolsDef?.def == "{system}";
710
743
  // system prompt if any
711
- const _systemBlock = this._buildSystemBlock(skip_empty_system);
744
+ const _systemBlock = this._buildSystemBlock(skip_empty_system, hasSystemTools);
712
745
  if (_systemBlock.length > 0) {
713
746
  buf.push(_systemBlock);
714
747
  if (this?.linebreaks?.system) {
715
748
  buf.push("\n".repeat(this.linebreaks.system));
716
749
  }
717
750
  }
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));
751
+ // tools if any
752
+ if (this.toolsDef && !hasSystemTools) {
753
+ const _toolsBlock = this._buildToolsBlock();
754
+ if (_toolsBlock.length > 0) {
755
+ buf.push(_toolsBlock);
756
+ if (this?.linebreaks?.tools) {
757
+ buf.push("\n".repeat(this.linebreaks.tools));
758
+ }
724
759
  }
725
760
  }
726
- // shots
761
+ // shots if any
727
762
  if (this?.shots) {
728
763
  for (const shot of this.shots) {
729
764
  buf.push(this.renderShot(shot));
730
765
  }
731
766
  }
732
767
  // history
733
- for (const turn of this.history) {
734
- buf.push(this.renderShot(turn));
768
+ let isToolResponse = false;
769
+ if (this.history.length > 0) {
770
+ for (const turn of this.history) {
771
+ buf.push(this.renderShot(turn));
772
+ }
773
+ if (this.history[this.history.length - 1]?.tool) {
774
+ isToolResponse = true;
775
+ }
776
+ }
777
+ if (!isToolResponse) {
778
+ // user block
779
+ buf.push(this._buildUserBlock());
780
+ // assistant block
735
781
  }
736
- // user block
737
- buf.push(this._buildUserBlock());
738
- // assistant block
739
782
  buf.push(this._buildAssistantBlock());
740
783
  //console.log(buf)
741
784
  return buf.join("");
@@ -763,7 +806,7 @@ class PromptTemplate {
763
806
  this.history.push(turn);
764
807
  return this;
765
808
  }
766
- _buildSystemBlock(skip_empty_system) {
809
+ _buildSystemBlock(skip_empty_system, systemTools = false) {
767
810
  let res = "";
768
811
  if (!this?.system) {
769
812
  return "";
@@ -780,14 +823,29 @@ class PromptTemplate {
780
823
  else if (!skip_empty_system) {
781
824
  res = this.system.schema;
782
825
  }
826
+ if (systemTools) {
827
+ res = res.replace("{tools}", this._buildToolsBlock(true));
828
+ }
783
829
  return res;
784
830
  }
785
- _buildToolsBlock() {
831
+ _buildToolResponse(txt) {
832
+ if (!this.toolsDef) {
833
+ throw new Error("No tools def in template to build tool response");
834
+ }
835
+ return this.toolsDef.response.replace("{tools_response}", txt);
836
+ }
837
+ _buildToolsBlock(raw = false) {
838
+ if (!this.toolsDef) {
839
+ throw new Error(`Can not build tools block: no tools definition found in template`);
840
+ }
786
841
  let toolsBlock = "";
787
842
  if (this.tools.length == 0) {
788
843
  return "";
789
844
  }
790
845
  const _t = JSON.stringify(this.tools);
846
+ if (raw) {
847
+ return _t;
848
+ }
791
849
  toolsBlock += this.toolsDef.def.replace("{tools}", _t);
792
850
  return toolsBlock;
793
851
  }
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}"},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}({});
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|>"},"chatml-tools":{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{message:'You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query.\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\\n{tools}\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{"name": <function-name>, "arguments": <args-json-object>}\\n</tool_call>',schema:"<|im_start|>system\n{system}<|im_end|>"},tools:{call:"<tool_call>\n{tool}\n</tool_call>",def:"{system}",response:"<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|im_end|>\n"},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:{afterShot:"<|end_of_text|>\n",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":{afterShot:"<|end_of_text|>\n",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":{afterShot:"<|end_of_text|>\n",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|>\n"},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=null;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,e?.tools&&(this.toolsDef=e.tools)}addTool(s){return this.tools.push(s),this}cloneTo(s,e=!0){const o=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{o.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&o.afterSystem(this._extraSystem),this._replaceSystem.length>0&&o.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&o.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&o.replacePrompt(this._replacePrompt),o}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)),s?.tool&&e.push(this._buildToolResponse(s.tool)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t="{system}"==this?.toolsDef?.def,o=this._buildSystemBlock(s,t);if(o.length>0&&(e.push(o),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this.toolsDef&&!t){const s=this._buildToolsBlock();s.length>0&&(e.push(s),this?.linebreaks?.tools&&e.push("\n".repeat(this.linebreaks.tools)))}if(this?.shots)for(const s of this.shots)e.push(this.renderShot(s));let a=!1;if(this.history.length>0){for(const s of this.history)e.push(this.renderShot(s));this.history[this.history.length-1]?.tool&&(a=!0)}return a||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,e=!1){let t="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(t=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(t+=this._extraSystem)):s||(t=this.system.schema),e&&(t=t.replace("{tools}",this._buildToolsBlock(!0))),t):""}_buildToolResponse(s){if(!this.toolsDef)throw new Error("No tools def in template to build tool response");return this.toolsDef.response.replace("{tools_response}",s)}_buildToolsBlock(s=!1){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");let e="";if(0==this.tools.length)return"";const t=JSON.stringify(this.tools);return s?t:(e+=this.toolsDef.def.replace("{tools}",t),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}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modprompt",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Prompt templates for language models",
5
5
  "license": "MIT",
6
6
  "scripts": {