modprompt 0.10.1 → 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/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]",
@@ -715,8 +739,9 @@ class PromptTemplate {
715
739
  if (this.prefix) {
716
740
  buf.push(this.prefix);
717
741
  }
742
+ const hasSystemTools = this?.toolsDef?.def == "{system}";
718
743
  // system prompt if any
719
- const _systemBlock = this._buildSystemBlock(skip_empty_system);
744
+ const _systemBlock = this._buildSystemBlock(skip_empty_system, hasSystemTools);
720
745
  if (_systemBlock.length > 0) {
721
746
  buf.push(_systemBlock);
722
747
  if (this?.linebreaks?.system) {
@@ -724,7 +749,7 @@ class PromptTemplate {
724
749
  }
725
750
  }
726
751
  // tools if any
727
- if (this.toolsDef) {
752
+ if (this.toolsDef && !hasSystemTools) {
728
753
  const _toolsBlock = this._buildToolsBlock();
729
754
  if (_toolsBlock.length > 0) {
730
755
  buf.push(_toolsBlock);
@@ -781,7 +806,7 @@ class PromptTemplate {
781
806
  this.history.push(turn);
782
807
  return this;
783
808
  }
784
- _buildSystemBlock(skip_empty_system) {
809
+ _buildSystemBlock(skip_empty_system, systemTools = false) {
785
810
  let res = "";
786
811
  if (!this?.system) {
787
812
  return "";
@@ -798,6 +823,9 @@ class PromptTemplate {
798
823
  else if (!skip_empty_system) {
799
824
  res = this.system.schema;
800
825
  }
826
+ if (systemTools) {
827
+ res = res.replace("{tools}", this._buildToolsBlock(true));
828
+ }
801
829
  return res;
802
830
  }
803
831
  _buildToolResponse(txt) {
@@ -806,7 +834,7 @@ class PromptTemplate {
806
834
  }
807
835
  return this.toolsDef.response.replace("{tools_response}", txt);
808
836
  }
809
- _buildToolsBlock() {
837
+ _buildToolsBlock(raw = false) {
810
838
  if (!this.toolsDef) {
811
839
  throw new Error(`Can not build tools block: no tools definition found in template`);
812
840
  }
@@ -815,6 +843,9 @@ class PromptTemplate {
815
843
  return "";
816
844
  }
817
845
  const _t = JSON.stringify(this.tools);
846
+ if (raw) {
847
+ return _t;
848
+ }
818
849
  toolsBlock += this.toolsDef.def.replace("{tools}", _t);
819
850
  return toolsBlock;
820
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:{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 r=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{r.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&r.afterSystem(this._extraSystem),this._replaceSystem.length>0&&r.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&r.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&r.replacePrompt(this._replacePrompt),r}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=this._buildSystemBlock(s);if(t.length>0&&(e.push(t),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this.toolsDef){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 r=!1;if(this.history.length>0){for(const s of this.history)e.push(this.renderShot(s));this.history[this.history.length-1]?.tool&&(r=!0)}return r||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):""}_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(){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");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.1",
3
+ "version": "0.10.2",
4
4
  "description": "Prompt templates for language models",
5
5
  "license": "MIT",
6
6
  "scripts": {