modprompt 0.12.0 → 0.12.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 +17 -17
- package/dist/main.js +175 -86
- package/dist/main.min.js +1 -1
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
|
@@ -37,6 +37,23 @@ declare class PromptTemplate {
|
|
|
37
37
|
*/
|
|
38
38
|
constructor(template: string | LmTemplate);
|
|
39
39
|
get hasTools(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Render a turn block
|
|
42
|
+
*
|
|
43
|
+
* @param {HistoryTurn} shot the shot to render
|
|
44
|
+
* @returns {string} ther rendered text
|
|
45
|
+
*/
|
|
46
|
+
renderShot(shot: HistoryTurn): string;
|
|
47
|
+
/**
|
|
48
|
+
* Renders the template into a string representation.
|
|
49
|
+
*
|
|
50
|
+
* @returns The rendered template as a string.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const rendered = tpl.render();
|
|
54
|
+
* console.log(rendered);
|
|
55
|
+
*/
|
|
56
|
+
render(skip_empty_system?: boolean): string;
|
|
40
57
|
addTool(tool: ToolDefSpec): PromptTemplate;
|
|
41
58
|
processAnswer(answer: string): {
|
|
42
59
|
isToolCall: boolean;
|
|
@@ -142,23 +159,6 @@ declare class PromptTemplate {
|
|
|
142
159
|
* ]);
|
|
143
160
|
*/
|
|
144
161
|
addShots(shots: Array<HistoryTurn>): PromptTemplate;
|
|
145
|
-
/**
|
|
146
|
-
* Render a turn block
|
|
147
|
-
*
|
|
148
|
-
* @param {HistoryTurn} shot the shot to render
|
|
149
|
-
* @returns {string} ther rendered text
|
|
150
|
-
*/
|
|
151
|
-
renderShot(shot: HistoryTurn): string;
|
|
152
|
-
/**
|
|
153
|
-
* Renders the template into a string representation.
|
|
154
|
-
*
|
|
155
|
-
* @returns The rendered template as a string.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* const rendered = tpl.render();
|
|
159
|
-
* console.log(rendered);
|
|
160
|
-
*/
|
|
161
|
-
render(skip_empty_system?: boolean): string;
|
|
162
162
|
/**
|
|
163
163
|
* Renders the template with the provided message replacing the `{prompt}` placeholder.
|
|
164
164
|
*
|
package/dist/main.js
CHANGED
|
@@ -45,6 +45,7 @@ const templates = {
|
|
|
45
45
|
"linebreaks": {
|
|
46
46
|
"assistant": 1,
|
|
47
47
|
"system": 1,
|
|
48
|
+
"tools": 1,
|
|
48
49
|
"user": 1
|
|
49
50
|
},
|
|
50
51
|
"name": "ChatMl tools",
|
|
@@ -274,6 +275,20 @@ const templates = {
|
|
|
274
275
|
},
|
|
275
276
|
"user": "<|user|>\n{prompt}"
|
|
276
277
|
},
|
|
278
|
+
"gptoss": {
|
|
279
|
+
"assistant": "<|start|>assistant",
|
|
280
|
+
"id": "gptoss",
|
|
281
|
+
"linebreaks": {
|
|
282
|
+
"assistant": 1,
|
|
283
|
+
"system": 1,
|
|
284
|
+
"user": 1
|
|
285
|
+
},
|
|
286
|
+
"name": "Gpt Oss",
|
|
287
|
+
"system": {
|
|
288
|
+
"schema": "<|start|>system<|message|>\n{system}\n<|end|>"
|
|
289
|
+
},
|
|
290
|
+
"user": "<|start|>user<|message|>\n{prompt}\n<|end|>"
|
|
291
|
+
},
|
|
277
292
|
"granite": {
|
|
278
293
|
"afterShot": "<|end_of_text|>\n",
|
|
279
294
|
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
@@ -343,6 +358,66 @@ const templates = {
|
|
|
343
358
|
},
|
|
344
359
|
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
345
360
|
},
|
|
361
|
+
"lfm": {
|
|
362
|
+
"afterShot": "<|im_end|>\n",
|
|
363
|
+
"assistant": "<|im_start|>assistant",
|
|
364
|
+
"id": "lfm",
|
|
365
|
+
"linebreaks": {
|
|
366
|
+
"assistant": 1,
|
|
367
|
+
"system": 1,
|
|
368
|
+
"tools": 1,
|
|
369
|
+
"user": 1
|
|
370
|
+
},
|
|
371
|
+
"name": "Lfm 2",
|
|
372
|
+
"stop": [
|
|
373
|
+
"<|im_end|>"
|
|
374
|
+
],
|
|
375
|
+
"system": {
|
|
376
|
+
"schema": "<|im_start|>system\n{system}<|im_end|>"
|
|
377
|
+
},
|
|
378
|
+
"tags": {
|
|
379
|
+
"think": {
|
|
380
|
+
"end": "</think>",
|
|
381
|
+
"start": "<think>"
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
385
|
+
},
|
|
386
|
+
"lfm-tools": {
|
|
387
|
+
"afterShot": "<|im_end|>\n",
|
|
388
|
+
"assistant": "<|im_start|>assistant",
|
|
389
|
+
"id": "lfm-tools",
|
|
390
|
+
"linebreaks": {
|
|
391
|
+
"assistant": 1,
|
|
392
|
+
"system": 1,
|
|
393
|
+
"tools": 1,
|
|
394
|
+
"user": 1
|
|
395
|
+
},
|
|
396
|
+
"name": "Lfm 2 tools",
|
|
397
|
+
"stop": [
|
|
398
|
+
"<|im_end|>"
|
|
399
|
+
],
|
|
400
|
+
"system": {
|
|
401
|
+
"message": "List of tools: <|tool_list_start|>{tools}<|tool_list_end|>",
|
|
402
|
+
"schema": "<|im_start|>system\n{system}<|im_end|>"
|
|
403
|
+
},
|
|
404
|
+
"tags": {
|
|
405
|
+
"think": {
|
|
406
|
+
"end": "</think>",
|
|
407
|
+
"start": "<think>"
|
|
408
|
+
},
|
|
409
|
+
"toolCall": {
|
|
410
|
+
"end": "<|tool_call_end|>",
|
|
411
|
+
"start": "<|tool_call_start|>"
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
"tools": {
|
|
415
|
+
"call": "<|tool_call_start|>\n{tools}\n<|tool_call_end|>",
|
|
416
|
+
"def": "{system}",
|
|
417
|
+
"response": "<|im_start|>tool\n<|tool_response_start|>\n{tools_response}\n<|tool_response_end|><|im_end|>"
|
|
418
|
+
},
|
|
419
|
+
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
420
|
+
},
|
|
346
421
|
"llama": {
|
|
347
422
|
"assistant": " [/INST] ",
|
|
348
423
|
"id": "llama",
|
|
@@ -753,6 +828,7 @@ class PromptTemplate {
|
|
|
753
828
|
this.tags = tpl?.tags;
|
|
754
829
|
}
|
|
755
830
|
if (tpl?.tools) {
|
|
831
|
+
//console.log("TEMPLATE TOOLS", tpl.tools);
|
|
756
832
|
this.toolsDef = tpl.tools;
|
|
757
833
|
const toolCallStartEnd = this.toolsDef?.call.split("{tools}");
|
|
758
834
|
if (!toolCallStartEnd) {
|
|
@@ -770,6 +846,102 @@ class PromptTemplate {
|
|
|
770
846
|
get hasTools() {
|
|
771
847
|
return this.tools.length > 0;
|
|
772
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Render a turn block
|
|
851
|
+
*
|
|
852
|
+
* @param {HistoryTurn} shot the shot to render
|
|
853
|
+
* @returns {string} ther rendered text
|
|
854
|
+
*/
|
|
855
|
+
renderShot(shot) {
|
|
856
|
+
const buf = [];
|
|
857
|
+
//console.log("S user", shot.user);
|
|
858
|
+
if (shot?.user) {
|
|
859
|
+
//buf.push(this._buildUserBlock(shot.user));
|
|
860
|
+
buf.push(shot.user);
|
|
861
|
+
}
|
|
862
|
+
//console.log("BS user", this._buildUserBlock(shot.user))
|
|
863
|
+
if (shot?.assistant) {
|
|
864
|
+
let _assistantMsg = shot.assistant;
|
|
865
|
+
if (this.afterShot) {
|
|
866
|
+
_assistantMsg += this.afterShot;
|
|
867
|
+
} /*else {
|
|
868
|
+
_assistantMsg += "\n\n"
|
|
869
|
+
}*/
|
|
870
|
+
buf.push(this._buildAssistantBlock(_assistantMsg));
|
|
871
|
+
}
|
|
872
|
+
if (shot?.tools) {
|
|
873
|
+
const resp = this._buildToolsResponse(shot.tools);
|
|
874
|
+
buf.push(resp);
|
|
875
|
+
/*if (this?.linebreaks?.tools) {
|
|
876
|
+
buf.push("\n".repeat(this.linebreaks.tools))
|
|
877
|
+
}*/
|
|
878
|
+
}
|
|
879
|
+
return buf.join("");
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Renders the template into a string representation.
|
|
883
|
+
*
|
|
884
|
+
* @returns The rendered template as a string.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* const rendered = tpl.render();
|
|
888
|
+
* console.log(rendered);
|
|
889
|
+
*/
|
|
890
|
+
render(skip_empty_system = true) {
|
|
891
|
+
const buf = new Array();
|
|
892
|
+
// prefix
|
|
893
|
+
if (this.prefix) {
|
|
894
|
+
buf.push(this.prefix);
|
|
895
|
+
}
|
|
896
|
+
const hasSystemTools = this?.toolsDef?.def == "{system}";
|
|
897
|
+
// system prompt if any
|
|
898
|
+
const _systemBlock = this._buildSystemBlock(skip_empty_system, hasSystemTools);
|
|
899
|
+
if (_systemBlock.length > 0) {
|
|
900
|
+
buf.push(_systemBlock);
|
|
901
|
+
if (this?.linebreaks?.system) {
|
|
902
|
+
buf.push("\n".repeat(this.linebreaks.system));
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
// tools if any
|
|
906
|
+
if (this.toolsDef && !hasSystemTools) {
|
|
907
|
+
const _toolsBlock = this._buildToolsBlock();
|
|
908
|
+
if (_toolsBlock.length > 0) {
|
|
909
|
+
buf.push(_toolsBlock);
|
|
910
|
+
if (this?.linebreaks?.tools) {
|
|
911
|
+
buf.push("\n".repeat(this.linebreaks.tools));
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
// shots if any
|
|
916
|
+
if (this?.shots) {
|
|
917
|
+
for (const shot of this.shots) {
|
|
918
|
+
buf.push(this.renderShot(shot));
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
// history
|
|
922
|
+
let isToolResponse = false;
|
|
923
|
+
if (this.history.length > 0) {
|
|
924
|
+
for (const turn of this.history) {
|
|
925
|
+
buf.push(this.renderShot(turn));
|
|
926
|
+
}
|
|
927
|
+
if (this.history[this.history.length - 1]?.tools) {
|
|
928
|
+
isToolResponse = true;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (!isToolResponse) {
|
|
932
|
+
// user block
|
|
933
|
+
buf.push(this._buildUserBlock());
|
|
934
|
+
// assistant block
|
|
935
|
+
}
|
|
936
|
+
else {
|
|
937
|
+
if (this?.linebreaks?.tools) {
|
|
938
|
+
buf.push("\n".repeat(this.linebreaks.tools));
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
buf.push(this._buildAssistantBlock());
|
|
942
|
+
//console.log(buf)
|
|
943
|
+
return buf.join("");
|
|
944
|
+
}
|
|
773
945
|
addTool(tool) {
|
|
774
946
|
if (!this?.toolsDef) {
|
|
775
947
|
throw new Error("This template does not support tools");
|
|
@@ -984,90 +1156,6 @@ class PromptTemplate {
|
|
|
984
1156
|
shots.forEach((s) => this.addShot(s));
|
|
985
1157
|
return this;
|
|
986
1158
|
}
|
|
987
|
-
/**
|
|
988
|
-
* Render a turn block
|
|
989
|
-
*
|
|
990
|
-
* @param {HistoryTurn} shot the shot to render
|
|
991
|
-
* @returns {string} ther rendered text
|
|
992
|
-
*/
|
|
993
|
-
renderShot(shot) {
|
|
994
|
-
const buf = [];
|
|
995
|
-
//console.log("S user", shot.user);
|
|
996
|
-
buf.push(this._buildUserBlock(shot.user));
|
|
997
|
-
//console.log("BS user", this._buildUserBlock(shot.user))
|
|
998
|
-
let _assistantMsg = shot.assistant;
|
|
999
|
-
if (this.afterShot) {
|
|
1000
|
-
_assistantMsg += this.afterShot;
|
|
1001
|
-
} /*else {
|
|
1002
|
-
_assistantMsg += "\n\n"
|
|
1003
|
-
}*/
|
|
1004
|
-
buf.push(this._buildAssistantBlock(_assistantMsg));
|
|
1005
|
-
if (shot?.tools) {
|
|
1006
|
-
const tts = {};
|
|
1007
|
-
shot.tools.forEach(s => tts[s.call.id] = s);
|
|
1008
|
-
buf.push(this._buildToolsResponse(tts));
|
|
1009
|
-
}
|
|
1010
|
-
return buf.join("");
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Renders the template into a string representation.
|
|
1014
|
-
*
|
|
1015
|
-
* @returns The rendered template as a string.
|
|
1016
|
-
*
|
|
1017
|
-
* @example
|
|
1018
|
-
* const rendered = tpl.render();
|
|
1019
|
-
* console.log(rendered);
|
|
1020
|
-
*/
|
|
1021
|
-
render(skip_empty_system = true) {
|
|
1022
|
-
const buf = new Array();
|
|
1023
|
-
// prefix
|
|
1024
|
-
if (this.prefix) {
|
|
1025
|
-
buf.push(this.prefix);
|
|
1026
|
-
}
|
|
1027
|
-
const hasSystemTools = this?.toolsDef?.def == "{system}";
|
|
1028
|
-
// system prompt if any
|
|
1029
|
-
const _systemBlock = this._buildSystemBlock(skip_empty_system, hasSystemTools);
|
|
1030
|
-
if (_systemBlock.length > 0) {
|
|
1031
|
-
buf.push(_systemBlock);
|
|
1032
|
-
if (this?.linebreaks?.system) {
|
|
1033
|
-
buf.push("\n".repeat(this.linebreaks.system));
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
// tools if any
|
|
1037
|
-
if (this.toolsDef && !hasSystemTools) {
|
|
1038
|
-
const _toolsBlock = this._buildToolsBlock();
|
|
1039
|
-
if (_toolsBlock.length > 0) {
|
|
1040
|
-
buf.push(_toolsBlock);
|
|
1041
|
-
if (this?.linebreaks?.tools) {
|
|
1042
|
-
buf.push("\n".repeat(this.linebreaks.tools));
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
// shots if any
|
|
1047
|
-
if (this?.shots) {
|
|
1048
|
-
for (const shot of this.shots) {
|
|
1049
|
-
buf.push(this.renderShot(shot));
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
// history
|
|
1053
|
-
let isToolResponse = false;
|
|
1054
|
-
if (this.history.length > 0) {
|
|
1055
|
-
for (const turn of this.history) {
|
|
1056
|
-
buf.push(this.renderShot(turn));
|
|
1057
|
-
}
|
|
1058
|
-
if (this.history[this.history.length - 1]?.tools) {
|
|
1059
|
-
isToolResponse = true;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
if (!isToolResponse) {
|
|
1063
|
-
// user block
|
|
1064
|
-
buf.push(this._buildUserBlock());
|
|
1065
|
-
// assistant block
|
|
1066
|
-
}
|
|
1067
|
-
buf.push(this._buildAssistantBlock());
|
|
1068
|
-
//console.log(buf)
|
|
1069
|
-
return buf.join("");
|
|
1070
|
-
}
|
|
1071
1159
|
/**
|
|
1072
1160
|
* Renders the template with the provided message replacing the `{prompt}` placeholder.
|
|
1073
1161
|
*
|
|
@@ -1129,8 +1217,9 @@ class PromptTemplate {
|
|
|
1129
1217
|
throw new Error("No tools def in template to build tool response");
|
|
1130
1218
|
}
|
|
1131
1219
|
const buf = new Array();
|
|
1132
|
-
|
|
1133
|
-
|
|
1220
|
+
//console.log("TOOL TURNS", toolTurns);
|
|
1221
|
+
for (const tt of toolTurns) {
|
|
1222
|
+
buf.push(this.toolsDef.response.replace("{tools_response}", JSON.stringify(tt.response)));
|
|
1134
1223
|
}
|
|
1135
1224
|
return buf.join("");
|
|
1136
1225
|
}
|
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|>"},tags:{think:{end:"</think>",start:"<think>"}},user:"<|im_start|>user\n{prompt}<|im_end|>"},"chatml-tools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml-tools",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl tools",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|>"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"</tool_call>",start:"<tool_call>"}},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|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|>"},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|>"},user:"<|start_header_id|>user<|end_header_id|>\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}"},"deepseek3-tools":{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3-tools",linebreaks:{system:2,user:2},name:"Deepseek 3 tools",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{message:"## Tools\nYou have access to the following tools:\n\n{tools}\n\nIMPORTANT: ALWAYS adhere to this exact format for tool use:\n<|tool▁calls▁begin|><|tool▁call▁begin|>tool_call_name<|tool▁sep|>tool_call_arguments<|tool▁call▁end|>{{additional_tool_calls}}<|tool▁calls▁end|>\n\nWhere:\n- `tool_call_name` must be an exact match to one of the available tools\n- `tool_call_arguments` must be valid JSON that strictly follows the tool's Parameters Schema\n- For multiple tool calls, chain them directly without separators or spaces",schema:"<|begin▁of▁sentence|>{system}"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"<|tool▁call▁end|>",start:"<|tool▁call▁begin|>"}},tools:{call:"<|tool▁calls▁begin|>{tools}<|tool▁calls▁end|>",def:"{system}",response:"<|tool▁output▁begin|>{tools_response}<|tool▁output▁end|>"},user:"<|User|>{prompt}"},exaone:{afterShot:"[|endofturn|]",assistant:"[|assistant|]",id:"exaone",linebreaks:{system:1,user:1},name:"Exaone",stop:["[|endofturn|]"],system:{message:"You are EXAONE model from LG AI Research, a helpful assistant.",schema:"[|system|]{system}[|endofturn|]"},user:"[|user|]{prompt}[|endofturn|]"},gemma:{afterShot:"<end_of_turn>",assistant:"<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}\n <end_of_turn>\n "},glm:{afterShot:"\n",assistant:"<|assistant|>",id:"glm",name:"Glm",prefix:"[gMASK]<sop>",stop:["<sop>"],system:{schema:"<|system|>{system}"},user:"<|user|>\n{prompt}"},"glm-tools":{afterShot:"\n",assistant:"<|assistant|>",id:"glm-tools",name:"Glm tools",prefix:"[gMASK]<sop>",stop:["<sop>"],system:{message:"# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n{tools}\n</tools>\n\nFor each function call, output the function name and arguments within the following XML format:\n<tool_call>{function-name}\n<arg_key>{arg-key-1}</arg_key>\n<arg_value>{arg-value-1}</arg_value>\n<arg_key>{arg-key-2}</arg_key>\n<arg_value>{arg-value-2}</arg_value>\n...\n</tool_call>",schema:"<|system|>{system}"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<tool_response>\n{tools_response}\n</tool_response>"},user:"<|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|>"},tags:{toolCall:{end:"<|start_of_role|>",start:"<|tool_call|>"}},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-think",name:"Llama 3 think",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|>"},tags:{think:{end:"</think>",start:"<think>"}},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}[/SYSTEM_PROMPT] "},user:"[INST] {prompt}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system-tools",name:"Mistral system tools",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system}[/SYSTEM_PROMPT] "},tags:{toolCall:{end:"[/TOOL_RESULTS]",start:"[TOOL_CALLS]"}},tools:{call:"[TOOL_CALLS]{tools}",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\n",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|>"},"phi4-tools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4-tools",name:"Phi 4 tools",stop:["<|im_end|>","<|im_sep|>"],system:{message:"You are a helpful assistant with some tools.\n<|tool|>\n{tools}\n<|/tool|>",schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},tags:{toolCall:{end:"<|/tool_call|>",start:"<|tool_call|>"}},tools:{call:"<|tool_call|>\n{tools}\n<|/tool_call|>",def:"{system}",response:"<|im_start|>user\n<|tool_response|>\n{tools_response}\n<|/tool_response|><|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|>"}};function e(s,t,e){try{const o=s.indexOf(t);if(-1===o)return s;let a,n=o+t.length;if(e){if(a=s.indexOf(e,n),-1===a)return s}else a=s.indexOf("\n",n),-1===a&&(a=s.length);return s.substring(n,a).trim()}catch(s){throw new Error(`Error parsing content between tags ${t} ${e}: ${s}`)}}class o{id;name;user;assistant;history=[];toolsDef=null;tools=[];tags={};system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;constructor(s){let t;if(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?.tags&&(this.tags=t?.tags),t?.tools){this.toolsDef=t.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 t=!1,e=[];if(s.trim().includes(this._toolCallStart)){t=!0;try{const t=this._parseToolCallString(s);if(!Array.isArray(t))throw new Error(`error parsing tool call response from model: the response object is not an Array:\n${t}`);e=t}catch(t){const e=new Array;throw e.push("error parsing tool call from model:"),e.push("------------- tool call ---------------"),e.push(s),e.push("----------- parsing error --------------"),e.push(`${t}`),new Error(e.join("\n"))}}return{isToolCall:t,toolsCall:e}}encodeToolResponse(s){if(!this.toolsDef)throw new Error("can not encode tool response: the template has no tools definition");if(!this.toolsDef.response.includes("{tools_response}"))throw new Error(`Template ${this.name} has invalid tool response format`);const t="string"==typeof s?s:JSON.stringify(s);return this.toolsDef.response.replace("{tools_response}",t)}cloneTo(s,t=!0){const e=new o(s);return Object.assign(e,this),t?e.history=this.history.map(s=>({...s})):e.shots=[],e}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){if(s.tools&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push(s),this}addShots(s){return s.forEach(s=>this.addShot(s)),this}renderShot(s){const t=[];t.push(this._buildUserBlock(s.user));let e=s.assistant;if(this.afterShot&&(e+=this.afterShot),t.push(this._buildAssistantBlock(e)),s?.tools){const e={};s.tools.forEach(s=>e[s.call.id]=s),t.push(this._buildToolsResponse(e))}return 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]?.tools&&(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,t=!0){if(t&&s?.assistant&&this.tags?.think){const t=s.assistant.split(this.tags.think.end);t.length>1&&(s.think=e(s.assistant,this.tags.think.start,this.tags.think.end),s.assistant=t[1].trim())}return this.history.push(s),this}_buildSystemBlock(s,t=!1){let e="";if(!this?.system)return"";let o=this._replaceSystem||this.system.message||"";return this._extraSystem&&(o+=this._extraSystem),o?e=this.system.schema.replace("{system}",o):s||(e=this.system.schema.replace("{system}","")),t&&this.tools.length>0&&(e=e.replace("{tools}",this._buildToolsBlock(!0))),e}_buildToolsResponse(s){if(!this.toolsDef)throw new Error("No tools def in template to build tool response");const t=new Array;for(const e of Object.values(s))t.push(this.toolsDef.response.replace("{tools_response}",JSON.stringify(e.response)));return t.join("")}_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+=e,s&&(t+=s),t}_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}`)}}_parseToolCallString(s){return function(s,t,o){try{let a=e(s,t,o);a.startsWith("[")&&!a.endsWith("]")&&(a+="]");let n=JSON.parse(a);return Array.isArray(n)||(n=[n]),n}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s,this._toolCallStart,this._toolCallEnd??void 0)}}return s.PromptTemplate=o,s.templates=t,s}({});
|
|
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|>"},tags:{think:{end:"</think>",start:"<think>"}},user:"<|im_start|>user\n{prompt}<|im_end|>"},"chatml-tools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml-tools",linebreaks:{assistant:1,system:1,tools:1,user:1},name:"ChatMl tools",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|>"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"</tool_call>",start:"<tool_call>"}},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|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|>"},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|>"},user:"<|start_header_id|>user<|end_header_id|>\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}"},"deepseek3-tools":{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3-tools",linebreaks:{system:2,user:2},name:"Deepseek 3 tools",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{message:"## Tools\nYou have access to the following tools:\n\n{tools}\n\nIMPORTANT: ALWAYS adhere to this exact format for tool use:\n<|tool▁calls▁begin|><|tool▁call▁begin|>tool_call_name<|tool▁sep|>tool_call_arguments<|tool▁call▁end|>{{additional_tool_calls}}<|tool▁calls▁end|>\n\nWhere:\n- `tool_call_name` must be an exact match to one of the available tools\n- `tool_call_arguments` must be valid JSON that strictly follows the tool's Parameters Schema\n- For multiple tool calls, chain them directly without separators or spaces",schema:"<|begin▁of▁sentence|>{system}"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"<|tool▁call▁end|>",start:"<|tool▁call▁begin|>"}},tools:{call:"<|tool▁calls▁begin|>{tools}<|tool▁calls▁end|>",def:"{system}",response:"<|tool▁output▁begin|>{tools_response}<|tool▁output▁end|>"},user:"<|User|>{prompt}"},exaone:{afterShot:"[|endofturn|]",assistant:"[|assistant|]",id:"exaone",linebreaks:{system:1,user:1},name:"Exaone",stop:["[|endofturn|]"],system:{message:"You are EXAONE model from LG AI Research, a helpful assistant.",schema:"[|system|]{system}[|endofturn|]"},user:"[|user|]{prompt}[|endofturn|]"},gemma:{afterShot:"<end_of_turn>",assistant:"<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}\n <end_of_turn>\n "},glm:{afterShot:"\n",assistant:"<|assistant|>",id:"glm",name:"Glm",prefix:"[gMASK]<sop>",stop:["<sop>"],system:{schema:"<|system|>{system}"},user:"<|user|>\n{prompt}"},"glm-tools":{afterShot:"\n",assistant:"<|assistant|>",id:"glm-tools",name:"Glm tools",prefix:"[gMASK]<sop>",stop:["<sop>"],system:{message:"# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n{tools}\n</tools>\n\nFor each function call, output the function name and arguments within the following XML format:\n<tool_call>{function-name}\n<arg_key>{arg-key-1}</arg_key>\n<arg_value>{arg-value-1}</arg_value>\n<arg_key>{arg-key-2}</arg_key>\n<arg_value>{arg-value-2}</arg_value>\n...\n</tool_call>",schema:"<|system|>{system}"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<tool_response>\n{tools_response}\n</tool_response>"},user:"<|user|>\n{prompt}"},gptoss:{assistant:"<|start|>assistant",id:"gptoss",linebreaks:{assistant:1,system:1,user:1},name:"Gpt Oss",system:{schema:"<|start|>system<|message|>\n{system}\n<|end|>"},user:"<|start|>user<|message|>\n{prompt}\n<|end|>"},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|>"},tags:{toolCall:{end:"<|start_of_role|>",start:"<|tool_call|>"}},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|>"},lfm:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant",id:"lfm",linebreaks:{assistant:1,system:1,tools:1,user:1},name:"Lfm 2",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},tags:{think:{end:"</think>",start:"<think>"}},user:"<|im_start|>user\n{prompt}<|im_end|>"},"lfm-tools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant",id:"lfm-tools",linebreaks:{assistant:1,system:1,tools:1,user:1},name:"Lfm 2 tools",stop:["<|im_end|>"],system:{message:"List of tools: <|tool_list_start|>{tools}<|tool_list_end|>",schema:"<|im_start|>system\n{system}<|im_end|>"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"<|tool_call_end|>",start:"<|tool_call_start|>"}},tools:{call:"<|tool_call_start|>\n{tools}\n<|tool_call_end|>",def:"{system}",response:"<|im_start|>tool\n<|tool_response_start|>\n{tools_response}\n<|tool_response_end|><|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},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-think",name:"Llama 3 think",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|>"},tags:{think:{end:"</think>",start:"<think>"}},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}[/SYSTEM_PROMPT] "},user:"[INST] {prompt}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system-tools",name:"Mistral system tools",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system}[/SYSTEM_PROMPT] "},tags:{toolCall:{end:"[/TOOL_RESULTS]",start:"[TOOL_CALLS]"}},tools:{call:"[TOOL_CALLS]{tools}",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\n",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|>"},"phi4-tools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4-tools",name:"Phi 4 tools",stop:["<|im_end|>","<|im_sep|>"],system:{message:"You are a helpful assistant with some tools.\n<|tool|>\n{tools}\n<|/tool|>",schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},tags:{toolCall:{end:"<|/tool_call|>",start:"<|tool_call|>"}},tools:{call:"<|tool_call|>\n{tools}\n<|/tool_call|>",def:"{system}",response:"<|im_start|>user\n<|tool_response|>\n{tools_response}\n<|/tool_response|><|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|>"}};function e(s,t,e){try{const o=s.indexOf(t);if(-1===o)return s;let a,n=o+t.length;if(e){if(a=s.indexOf(e,n),-1===a)return s}else a=s.indexOf("\n",n),-1===a&&(a=s.length);return s.substring(n,a).trim()}catch(s){throw new Error(`Error parsing content between tags ${t} ${e}: ${s}`)}}class o{id;name;user;assistant;history=[];toolsDef=null;tools=[];tags={};system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;constructor(s){let t;if(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?.tags&&(this.tags=t?.tags),t?.tools){this.toolsDef=t.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}renderShot(s){const t=[];if(s?.user&&t.push(s.user),s?.assistant){let e=s.assistant;this.afterShot&&(e+=this.afterShot),t.push(this._buildAssistantBlock(e))}if(s?.tools){const e=this._buildToolsResponse(s.tools);t.push(e)}return 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]?.tools&&(a=!0)}return a?this?.linebreaks?.tools&&t.push("\n".repeat(this.linebreaks.tools)):t.push(this._buildUserBlock()),t.push(this._buildAssistantBlock()),t.join("")}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 t=!1,e=[];if(s.trim().includes(this._toolCallStart)){t=!0;try{const t=this._parseToolCallString(s);if(!Array.isArray(t))throw new Error(`error parsing tool call response from model: the response object is not an Array:\n${t}`);e=t}catch(t){const e=new Array;throw e.push("error parsing tool call from model:"),e.push("------------- tool call ---------------"),e.push(s),e.push("----------- parsing error --------------"),e.push(`${t}`),new Error(e.join("\n"))}}return{isToolCall:t,toolsCall:e}}encodeToolResponse(s){if(!this.toolsDef)throw new Error("can not encode tool response: the template has no tools definition");if(!this.toolsDef.response.includes("{tools_response}"))throw new Error(`Template ${this.name} has invalid tool response format`);const t="string"==typeof s?s:JSON.stringify(s);return this.toolsDef.response.replace("{tools_response}",t)}cloneTo(s,t=!0){const e=new o(s);return Object.assign(e,this),t?e.history=this.history.map(s=>({...s})):e.shots=[],e}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){if(s.tools&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push(s),this}addShots(s){return s.forEach(s=>this.addShot(s)),this}prompt(s,t=!0){return this.render(t).replace("{prompt}",s)}pushToHistory(s,t=!0){if(t&&s?.assistant&&this.tags?.think){const t=s.assistant.split(this.tags.think.end);t.length>1&&(s.think=e(s.assistant,this.tags.think.start,this.tags.think.end),s.assistant=t[1].trim())}return this.history.push(s),this}_buildSystemBlock(s,t=!1){let e="";if(!this?.system)return"";let o=this._replaceSystem||this.system.message||"";return this._extraSystem&&(o+=this._extraSystem),o?e=this.system.schema.replace("{system}",o):s||(e=this.system.schema.replace("{system}","")),t&&this.tools.length>0&&(e=e.replace("{tools}",this._buildToolsBlock(!0))),e}_buildToolsResponse(s){if(!this.toolsDef)throw new Error("No tools def in template to build tool response");const t=new Array;for(const e of s)t.push(this.toolsDef.response.replace("{tools_response}",JSON.stringify(e.response)));return t.join("")}_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+=e,s&&(t+=s),t}_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}`)}}_parseToolCallString(s){return function(s,t,o){try{let a=e(s,t,o);a.startsWith("[")&&!a.endsWith("]")&&(a+="]");let n=JSON.parse(a);return Array.isArray(n)||(n=[n]),n}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s,this._toolCallStart,this._toolCallEnd??void 0)}}return s.PromptTemplate=o,s.templates=t,s}({});
|