modprompt 0.10.5 → 0.10.7
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 +10 -0
- package/dist/interfaces.d.ts +2 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.js +105 -2
- package/dist/main.min.js +1 -1
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ declare class PromptTemplate {
|
|
|
23
23
|
private _extraAssistant;
|
|
24
24
|
private _replacePrompt;
|
|
25
25
|
private _replaceSystem;
|
|
26
|
+
private _toolCallStart;
|
|
27
|
+
private _toolCallEnd;
|
|
26
28
|
/**
|
|
27
29
|
* Constructs a new `PromptTemplate` instance.
|
|
28
30
|
*
|
|
@@ -32,7 +34,14 @@ declare class PromptTemplate {
|
|
|
32
34
|
* const tpl = new PromptTemplate('alpaca');
|
|
33
35
|
*/
|
|
34
36
|
constructor(template: string | LmTemplate);
|
|
37
|
+
get hasTools(): boolean;
|
|
35
38
|
addTool(tool: ToolSpec): PromptTemplate;
|
|
39
|
+
processAnswer(answer: string): {
|
|
40
|
+
isToolCall: boolean;
|
|
41
|
+
toolsCall: Array<Record<string, any>>;
|
|
42
|
+
error?: string;
|
|
43
|
+
};
|
|
44
|
+
encodeToolResponse(response: any): string;
|
|
36
45
|
/**
|
|
37
46
|
* Clones the current `PromptTemplate` instance to a new instance of `PromptTemplate`.
|
|
38
47
|
*
|
|
@@ -172,5 +181,6 @@ declare class PromptTemplate {
|
|
|
172
181
|
private _buildUserBlock;
|
|
173
182
|
private _buildAssistantBlock;
|
|
174
183
|
private _load;
|
|
184
|
+
private _parseToolCallString;
|
|
175
185
|
}
|
|
176
186
|
export { PromptTemplate };
|
package/dist/interfaces.d.ts
CHANGED
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { templates } from "./db.js";
|
|
2
2
|
import { PromptTemplate } from "./cls.js";
|
|
3
|
-
import { SpacingSlots, PromptBlock, TurnBlock, LmTemplate, ImgData, HistoryTurn } from "./interfaces.js";
|
|
4
|
-
export { templates, PromptTemplate, SpacingSlots, PromptBlock, TurnBlock, LmTemplate, ImgData, HistoryTurn };
|
|
3
|
+
import { SpacingSlots, PromptBlock, TurnBlock, LmTemplate, ImgData, HistoryTurn, ToolSpec } from "./interfaces.js";
|
|
4
|
+
export { templates, PromptTemplate, SpacingSlots, PromptBlock, TurnBlock, LmTemplate, ImgData, HistoryTurn, ToolSpec };
|
package/dist/main.js
CHANGED
|
@@ -88,6 +88,26 @@ const templates = {
|
|
|
88
88
|
},
|
|
89
89
|
"user": "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"
|
|
90
90
|
},
|
|
91
|
+
"deephermes": {
|
|
92
|
+
"afterShot": "<|eot_id|>\n\n",
|
|
93
|
+
"assistant": "<|start_header_id|>assistant<|end_header_id|>",
|
|
94
|
+
"id": "deephermes",
|
|
95
|
+
"name": "Deephermes",
|
|
96
|
+
"stop": [
|
|
97
|
+
"<|eot_id|>",
|
|
98
|
+
"<|end_of_text|>"
|
|
99
|
+
],
|
|
100
|
+
"system": {
|
|
101
|
+
"message": "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {tools} </tools>. For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n{\"arguments\": <args-dict>, \"name\": <function-name>}\n</tool_call>",
|
|
102
|
+
"schema": "<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"
|
|
103
|
+
},
|
|
104
|
+
"tools": {
|
|
105
|
+
"call": "<tool_call>\n{tools}\n</tool_call>",
|
|
106
|
+
"def": "{system}",
|
|
107
|
+
"response": "<|start_header_id|>user<|end_header_id|>\n<tool_response>\n{tools_response}\n</tool_response><|eot_id|>\n"
|
|
108
|
+
},
|
|
109
|
+
"user": "<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"
|
|
110
|
+
},
|
|
91
111
|
"deepseek": {
|
|
92
112
|
"afterShot": "\n",
|
|
93
113
|
"assistant": "### Response:",
|
|
@@ -209,7 +229,7 @@ const templates = {
|
|
|
209
229
|
"schema": "<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"
|
|
210
230
|
},
|
|
211
231
|
"tools": {
|
|
212
|
-
"call": "
|
|
232
|
+
"call": "<tool_call>{tools}",
|
|
213
233
|
"def": "<|start_of_role|>tools<|end_of_role|>{tools}<|end_of_text|>",
|
|
214
234
|
"response": "<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>\n"
|
|
215
235
|
},
|
|
@@ -247,6 +267,21 @@ const templates = {
|
|
|
247
267
|
},
|
|
248
268
|
"user": "<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"
|
|
249
269
|
},
|
|
270
|
+
"llama3-think": {
|
|
271
|
+
"afterShot": "<|eot_id|>\n\n",
|
|
272
|
+
"assistant": "<|start_header_id|>assistant<|end_header_id|>",
|
|
273
|
+
"id": "llama3",
|
|
274
|
+
"name": "Llama 3",
|
|
275
|
+
"stop": [
|
|
276
|
+
"<|eot_id|>",
|
|
277
|
+
"<|end_of_text|>"
|
|
278
|
+
],
|
|
279
|
+
"system": {
|
|
280
|
+
"message": "You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.",
|
|
281
|
+
"schema": "<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"
|
|
282
|
+
},
|
|
283
|
+
"user": "<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"
|
|
284
|
+
},
|
|
250
285
|
"llava": {
|
|
251
286
|
"assistant": "ASSISTANT:",
|
|
252
287
|
"id": "llava",
|
|
@@ -303,7 +338,7 @@ const templates = {
|
|
|
303
338
|
"schema": "[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"
|
|
304
339
|
},
|
|
305
340
|
"tools": {
|
|
306
|
-
"call": "[TOOL_CALLS]
|
|
341
|
+
"call": "[TOOL_CALLS] {tools}</s>",
|
|
307
342
|
"def": "[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",
|
|
308
343
|
"response": "[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"
|
|
309
344
|
},
|
|
@@ -389,6 +424,17 @@ const templates = {
|
|
|
389
424
|
},
|
|
390
425
|
"user": "<|im_start|>user<|im_sep|>{prompt}<|im_end|>"
|
|
391
426
|
},
|
|
427
|
+
"reka": {
|
|
428
|
+
"afterShot": " <sep> ",
|
|
429
|
+
"assistant": "assistant:",
|
|
430
|
+
"id": "reka",
|
|
431
|
+
"name": "Reka",
|
|
432
|
+
"stop": [
|
|
433
|
+
"<sep>",
|
|
434
|
+
"<|endoftext|>"
|
|
435
|
+
],
|
|
436
|
+
"user": "human: {prompt} <sep> "
|
|
437
|
+
},
|
|
392
438
|
"vicuna": {
|
|
393
439
|
"assistant": "### ASSISTANT:",
|
|
394
440
|
"id": "vicuna",
|
|
@@ -481,6 +527,8 @@ class PromptTemplate {
|
|
|
481
527
|
_extraAssistant = "";
|
|
482
528
|
_replacePrompt = "";
|
|
483
529
|
_replaceSystem = "";
|
|
530
|
+
_toolCallStart = "";
|
|
531
|
+
_toolCallEnd = null;
|
|
484
532
|
/**
|
|
485
533
|
* Constructs a new `PromptTemplate` instance.
|
|
486
534
|
*
|
|
@@ -509,8 +557,22 @@ class PromptTemplate {
|
|
|
509
557
|
this.prefix = tpl.prefix;
|
|
510
558
|
if (tpl?.tools) {
|
|
511
559
|
this.toolsDef = tpl.tools;
|
|
560
|
+
const toolCallStartEnd = this.toolsDef?.call.split("{tools}");
|
|
561
|
+
if (!toolCallStartEnd) {
|
|
562
|
+
throw new Error(`Tool definition malformed in template ${this.name}`);
|
|
563
|
+
}
|
|
564
|
+
if (toolCallStartEnd.length == 0) {
|
|
565
|
+
throw new Error(`Tool definition malformed in template ${this.name}: no start tool call definition`);
|
|
566
|
+
}
|
|
567
|
+
this._toolCallStart = toolCallStartEnd[0];
|
|
568
|
+
if (toolCallStartEnd.length > 1) {
|
|
569
|
+
this._toolCallEnd = toolCallStartEnd[1];
|
|
570
|
+
}
|
|
512
571
|
}
|
|
513
572
|
}
|
|
573
|
+
get hasTools() {
|
|
574
|
+
return this.tools.length > 0;
|
|
575
|
+
}
|
|
514
576
|
addTool(tool) {
|
|
515
577
|
if (!this?.toolsDef) {
|
|
516
578
|
throw new Error("This template does not support tools");
|
|
@@ -518,6 +580,40 @@ class PromptTemplate {
|
|
|
518
580
|
this.tools.push(tool);
|
|
519
581
|
return this;
|
|
520
582
|
}
|
|
583
|
+
processAnswer(answer) {
|
|
584
|
+
if (!this.hasTools) {
|
|
585
|
+
return { isToolCall: false, toolsCall: [] };
|
|
586
|
+
}
|
|
587
|
+
let isToolCall = false;
|
|
588
|
+
let toolsCall = new Array();
|
|
589
|
+
if (answer.startsWith(this._toolCallStart)) {
|
|
590
|
+
isToolCall = true;
|
|
591
|
+
const tcs = this._parseToolCallString(answer);
|
|
592
|
+
let errMsg = "";
|
|
593
|
+
try {
|
|
594
|
+
const tc = JSON.parse(tcs);
|
|
595
|
+
if (!Array.isArray(tc)) {
|
|
596
|
+
errMsg = `error parsing tool call response from model: the response object is not an Array:\n${answer}`;
|
|
597
|
+
console.log(errMsg);
|
|
598
|
+
}
|
|
599
|
+
toolsCall = tc;
|
|
600
|
+
}
|
|
601
|
+
catch (e) {
|
|
602
|
+
errMsg = `error parsing tool call response from model:\n${answer}`;
|
|
603
|
+
console.log(errMsg);
|
|
604
|
+
}
|
|
605
|
+
if (errMsg) {
|
|
606
|
+
return { isToolCall: false, toolsCall: [], error: errMsg };
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return { isToolCall: isToolCall, toolsCall: toolsCall };
|
|
610
|
+
}
|
|
611
|
+
encodeToolResponse(response) {
|
|
612
|
+
if (!this.toolsDef) {
|
|
613
|
+
throw new Error("can not encode tool response: the template has no tools definition");
|
|
614
|
+
}
|
|
615
|
+
return this.toolsDef.response.replace("{tools_response}", `${response}`);
|
|
616
|
+
}
|
|
521
617
|
/**
|
|
522
618
|
* Clones the current `PromptTemplate` instance to a new instance of `PromptTemplate`.
|
|
523
619
|
*
|
|
@@ -890,6 +986,13 @@ class PromptTemplate {
|
|
|
890
986
|
throw new Error(`Error loading template ${name}: ${err}`);
|
|
891
987
|
}
|
|
892
988
|
}
|
|
989
|
+
_parseToolCallString(raw) {
|
|
990
|
+
let call = raw.replace(this._toolCallStart, "");
|
|
991
|
+
if (this._toolCallEnd) {
|
|
992
|
+
call = call.replace(this._toolCallEnd, "");
|
|
993
|
+
}
|
|
994
|
+
return call;
|
|
995
|
+
}
|
|
893
996
|
}
|
|
894
997
|
|
|
895
998
|
export { PromptTemplate, templates };
|
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const t={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|>{tool}",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}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},tools:{call:"[TOOL_CALLS] [{tool}]</s>",def:"[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",response:"[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"},user:"[INST]{prompt}[/INST]"},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}"},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|>"},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 e{id;name;user;assistant;history=[];toolsDef=null;tools=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";constructor(s){let t;t="string"==typeof s?this._load(s):s,this.id=t.id,this.name=t.name,this.user=t.user,this.assistant=t.assistant,this.system=t.system,this.shots=t.shots,this.stop=t.stop,this.linebreaks=t.linebreaks,this.afterShot=t.afterShot,this.prefix=t.prefix,t?.tools&&(this.toolsDef=t.tools)}addTool(s){if(!this?.toolsDef)throw new Error("This template does not support tools");return this.tools.push(s),this}cloneTo(s,t=!0){const o=new e(s);return t&&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,t,e){if(e&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push({user:s,assistant:t,tool:e}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const t=[];t.push(this._buildUserBlock(s.user));let e=s.assistant;return this.afterShot&&(e+=this.afterShot),t.push(this._buildAssistantBlock(e)),s?.tool&&t.push(this._buildToolResponse(s.tool)),t.join("")}render(s=!0){const t=new Array;this.prefix&&t.push(this.prefix);const e="{system}"==this?.toolsDef?.def,o=this._buildSystemBlock(s,e);if(o.length>0&&(t.push(o),this?.linebreaks?.system&&t.push("\n".repeat(this.linebreaks.system))),this.toolsDef&&!e){const s=this._buildToolsBlock();s.length>0&&(t.push(s),this?.linebreaks?.tools&&t.push("\n".repeat(this.linebreaks.tools)))}if(this?.shots)for(const s of this.shots)t.push(this.renderShot(s));let a=!1;if(this.history.length>0){for(const s of this.history)t.push(this.renderShot(s));this.history[this.history.length-1]?.tool&&(a=!0)}return a||t.push(this._buildUserBlock()),t.push(this._buildAssistantBlock()),t.join("")}prompt(s,t=!0){return this.render(t).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s,t=!1){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),t&&(e=e.replace("{tools}",this._buildToolsBlock(!0))),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(s=!1){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");let t="";if(0==this.tools.length)return"";const e=JSON.stringify(this.tools);return s?e:(t+=this.toolsDef.def.replace("{tools}",e),t)}_buildUserBlock(s){let t=[],e=this.user;return this._replacePrompt.length>0&&(e=e.replace("{prompt}",this._replacePrompt)),t.push(e),this?.linebreaks?.user&&t.push("\n".repeat(this.linebreaks.user)),s&&(t[0]=this.user.replace("{prompt}",s)),t.join("")}_buildAssistantBlock(s){let t=[],e=this.assistant;return this?.linebreaks?.assistant&&(e+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(e+=this._extraAssistant),t.push(e),s&&t.push(s),t.join("")}_load(s){try{if(s in t)return t[s];throw new Error(`Template ${s} not found`)}catch(t){throw new Error(`Error loading template ${s}: ${t}`)}}}return s.PromptTemplate=e,s.templates=t,s}({});
|
|
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|>"},deephermes:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"deephermes",name:"Deephermes",stop:["<|eot_id|>","<|end_of_text|>"],system:{message:'You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don\'t make assumptions about what values to plug into functions. Here are the available tools: <tools> {tools} </tools>. For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n{"arguments": <args-dict>, "name": <function-name>}\n</tool_call>',schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<|start_header_id|>user<|end_header_id|>\n<tool_response>\n{tools_response}\n</tool_response><|eot_id|>\n"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},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>{tools}",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|>"},"llama3-think":{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:{message:"You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.",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}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},tools:{call:"[TOOL_CALLS] {tools}</s>",def:"[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",response:"[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"},user:"[INST]{prompt}[/INST]"},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}"},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|>"},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|>"},reka:{afterShot:" <sep> ",assistant:"assistant:",id:"reka",name:"Reka",stop:["<sep>","<|endoftext|>"],user:"human: {prompt} <sep> "},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="";_toolCallStart="";_toolCallEnd=null;constructor(s){let e;if(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;const s=this.toolsDef?.call.split("{tools}");if(!s)throw new Error(`Tool definition malformed in template ${this.name}`);if(0==s.length)throw new Error(`Tool definition malformed in template ${this.name}: no start tool call definition`);this._toolCallStart=s[0],s.length>1&&(this._toolCallEnd=s[1])}}get hasTools(){return this.tools.length>0}addTool(s){if(!this?.toolsDef)throw new Error("This template does not support tools");return this.tools.push(s),this}processAnswer(s){if(!this.hasTools)return{isToolCall:!1,toolsCall:[]};let e=!1,t=new Array;if(s.startsWith(this._toolCallStart)){e=!0;const o=this._parseToolCallString(s);let a="";try{const e=JSON.parse(o);Array.isArray(e)||(a=`error parsing tool call response from model: the response object is not an Array:\n${s}`,console.log(a)),t=e}catch(e){a=`error parsing tool call response from model:\n${s}`,console.log(a)}if(a)return{isToolCall:!1,toolsCall:[],error:a}}return{isToolCall:e,toolsCall:t}}encodeToolResponse(s){if(!this.toolsDef)throw new Error("can not encode tool response: the template has no tools definition");return this.toolsDef.response.replace("{tools_response}",`${s}`)}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,t){if(t&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push({user:s,assistant:e,tool: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}`)}}_parseToolCallString(s){let e=s.replace(this._toolCallStart,"");return this._toolCallEnd&&(e=e.replace(this._toolCallEnd,"")),e}}return s.PromptTemplate=t,s.templates=e,s}({});
|