modprompt 0.14.0 → 0.14.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 +2 -0
- package/dist/interfaces.d.ts +2 -0
- package/dist/main.js +127 -5
- package/dist/main.min.js +1 -1
- package/dist/tools/qwen.d.ts +4 -0
- package/package.json +1 -1
package/dist/cls.d.ts
CHANGED
|
@@ -28,7 +28,9 @@ declare class PromptTemplate {
|
|
|
28
28
|
private _toolCallStart;
|
|
29
29
|
private _toolCallEnd;
|
|
30
30
|
private _toolCallParser;
|
|
31
|
+
private _toolCallBuilder;
|
|
31
32
|
private _beforeToolResponse;
|
|
33
|
+
private _afterToolResponse;
|
|
32
34
|
/**
|
|
33
35
|
* Constructs a new `PromptTemplate` instance.
|
|
34
36
|
*
|
package/dist/interfaces.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -73,6 +73,45 @@ const templates = {
|
|
|
73
73
|
},
|
|
74
74
|
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
75
75
|
},
|
|
76
|
+
"chatml-xmltools": {
|
|
77
|
+
"afterShot": "<|im_end|>\n",
|
|
78
|
+
"assistant": "<|im_start|>assistant",
|
|
79
|
+
"id": "chatml-xmltools",
|
|
80
|
+
"linebreaks": {
|
|
81
|
+
"assistant": 1,
|
|
82
|
+
"system": 1,
|
|
83
|
+
"tools": 1,
|
|
84
|
+
"user": 1
|
|
85
|
+
},
|
|
86
|
+
"name": "ChatMl Xml tools",
|
|
87
|
+
"stop": [
|
|
88
|
+
"<|im_end|>"
|
|
89
|
+
],
|
|
90
|
+
"system": {
|
|
91
|
+
"message": "You are a helpful assistant.\n\nYou have access to the following functions:\n\n<tools>\n{tools}\n</tools>\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>",
|
|
92
|
+
"schema": "<|im_start|>system\n{system}<|im_end|>"
|
|
93
|
+
},
|
|
94
|
+
"tags": {
|
|
95
|
+
"think": {
|
|
96
|
+
"end": "</think>",
|
|
97
|
+
"start": "<think>"
|
|
98
|
+
},
|
|
99
|
+
"toolCall": {
|
|
100
|
+
"end": "</tool_call>",
|
|
101
|
+
"start": "<tool_call>"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"tools": {
|
|
105
|
+
"afterResponse": "<|im_end|>\n",
|
|
106
|
+
"beforeResponse": "<|im_start|>user\n",
|
|
107
|
+
"builder": "qwen",
|
|
108
|
+
"call": "<tool_call>\n{tools}\n</tool_call>",
|
|
109
|
+
"def": "{system}",
|
|
110
|
+
"parser": "qwen",
|
|
111
|
+
"response": "<tool_response>\n{tools_response}\n</tool_response>\n"
|
|
112
|
+
},
|
|
113
|
+
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
114
|
+
},
|
|
76
115
|
"codestral": {
|
|
77
116
|
"afterShot": "\n",
|
|
78
117
|
"assistant": " [/INST]",
|
|
@@ -873,6 +912,69 @@ function extractJsonToolSpec(text, startTag, endTag) {
|
|
|
873
912
|
}
|
|
874
913
|
}
|
|
875
914
|
|
|
915
|
+
function extractQwenToolSpec(text, startTag, endTag) {
|
|
916
|
+
try {
|
|
917
|
+
// Optional: Pre-filter to only content between startTag/endTag blocks
|
|
918
|
+
const toolCallRegex = /<function=([^>]+)>([\s\S]*?)<\/function>/g;
|
|
919
|
+
const tcs = [];
|
|
920
|
+
let match;
|
|
921
|
+
while ((match = toolCallRegex.exec(text)) !== null) {
|
|
922
|
+
const functionName = match[1].trim();
|
|
923
|
+
const paramsBlock = match[2];
|
|
924
|
+
// Extract parameters with newline-safe regex
|
|
925
|
+
const paramRegex = /<parameter=([^>]+)>([\s\S]*?)<\/parameter>/g;
|
|
926
|
+
const parameters = {};
|
|
927
|
+
let paramMatch;
|
|
928
|
+
while ((paramMatch = paramRegex.exec(paramsBlock)) !== null) {
|
|
929
|
+
const key = paramMatch[1].trim();
|
|
930
|
+
const value = paramMatch[2].trim(); // trim to remove surrounding whitespace/newlines
|
|
931
|
+
parameters[key] = value;
|
|
932
|
+
}
|
|
933
|
+
tcs.push({
|
|
934
|
+
id: crypto.randomUUID(),
|
|
935
|
+
name: functionName,
|
|
936
|
+
arguments: Object.keys(parameters).length > 0 ? parameters : undefined
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
return tcs;
|
|
940
|
+
}
|
|
941
|
+
catch (error) {
|
|
942
|
+
throw new Error(`tool call parsing error: ${error}`);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
function buildQwenToolDef(tools) {
|
|
946
|
+
const buf = new Array();
|
|
947
|
+
for (const td of tools) {
|
|
948
|
+
buf.push("<function>");
|
|
949
|
+
buf.push(`<name>${td.name}</name>`);
|
|
950
|
+
buf.push(`<description>${td.description}</description>`);
|
|
951
|
+
const args = Object.keys(td.arguments);
|
|
952
|
+
if (args.length > 0) {
|
|
953
|
+
buf.push("<parameters>");
|
|
954
|
+
}
|
|
955
|
+
const required = new Array();
|
|
956
|
+
args.forEach(a => {
|
|
957
|
+
const p = td.arguments[a];
|
|
958
|
+
buf.push("<parameter>");
|
|
959
|
+
buf.push(`<name>${a}</name>`);
|
|
960
|
+
buf.push(`<description>${p.description}</description>`);
|
|
961
|
+
buf.push("</parameter>");
|
|
962
|
+
if (p.required) {
|
|
963
|
+
required.push(a);
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
if (args.length > 0) {
|
|
967
|
+
if (required.length > 0) {
|
|
968
|
+
const r = required.toString().replaceAll('"', "`");
|
|
969
|
+
buf.push(`<required>${r}</required>`);
|
|
970
|
+
}
|
|
971
|
+
buf.push("</parameters>");
|
|
972
|
+
}
|
|
973
|
+
buf.push("</function>");
|
|
974
|
+
}
|
|
975
|
+
return buf.join("\n");
|
|
976
|
+
}
|
|
977
|
+
|
|
876
978
|
function routeToolResponseParsing(text, startTag, endTag, parser) {
|
|
877
979
|
if (!parser) {
|
|
878
980
|
return extractJsonToolSpec(text, startTag, endTag);
|
|
@@ -880,6 +982,9 @@ function routeToolResponseParsing(text, startTag, endTag, parser) {
|
|
|
880
982
|
else if (parser == "glm") {
|
|
881
983
|
return extractGlmToolSpec(text);
|
|
882
984
|
}
|
|
985
|
+
else if (parser == "qwen") {
|
|
986
|
+
return extractQwenToolSpec(text);
|
|
987
|
+
}
|
|
883
988
|
else {
|
|
884
989
|
throw new Error(`unknown tool response parser ${parser}`);
|
|
885
990
|
}
|
|
@@ -942,7 +1047,9 @@ class PromptTemplate {
|
|
|
942
1047
|
_toolCallStart = "";
|
|
943
1048
|
_toolCallEnd = null;
|
|
944
1049
|
_toolCallParser = null;
|
|
1050
|
+
_toolCallBuilder = null;
|
|
945
1051
|
_beforeToolResponse = null;
|
|
1052
|
+
_afterToolResponse = null;
|
|
946
1053
|
/**
|
|
947
1054
|
* Constructs a new `PromptTemplate` instance.
|
|
948
1055
|
*
|
|
@@ -985,7 +1092,9 @@ class PromptTemplate {
|
|
|
985
1092
|
this._toolCallStart = this.tags?.toolCall?.start || "";
|
|
986
1093
|
this._toolCallEnd = this.tags?.toolCall?.end || null;
|
|
987
1094
|
this._toolCallParser = tpl?.tools?.parser ?? null;
|
|
1095
|
+
this._toolCallBuilder = tpl?.tools?.builder ?? null;
|
|
988
1096
|
this._beforeToolResponse = tpl?.tools?.beforeResponse ?? null;
|
|
1097
|
+
this._afterToolResponse = tpl?.tools?.afterResponse ?? null;
|
|
989
1098
|
}
|
|
990
1099
|
}
|
|
991
1100
|
get hasTools() {
|
|
@@ -1096,12 +1205,12 @@ class PromptTemplate {
|
|
|
1096
1205
|
}
|
|
1097
1206
|
processAnswer(answer) {
|
|
1098
1207
|
if (!this.hasTools) {
|
|
1099
|
-
return { isToolCall: false, toolsCall: [] };
|
|
1208
|
+
return { isToolCall: false, toolsCall: [], assistant: answer };
|
|
1100
1209
|
}
|
|
1101
1210
|
let isToolCall = false;
|
|
1102
1211
|
let assistant = "";
|
|
1103
1212
|
let toolsCall = [];
|
|
1104
|
-
|
|
1213
|
+
let ans = answer.trim();
|
|
1105
1214
|
//console.log("\nTC ANSWER", ans);
|
|
1106
1215
|
//console.log("TC SW", this._toolCallStart + "||", ans.includes(this._toolCallStart));
|
|
1107
1216
|
if (ans.includes(this._toolCallStart)) {
|
|
@@ -1137,6 +1246,9 @@ class PromptTemplate {
|
|
|
1137
1246
|
throw new Error(buf.join("\n"));
|
|
1138
1247
|
}
|
|
1139
1248
|
}
|
|
1249
|
+
else {
|
|
1250
|
+
assistant = ans;
|
|
1251
|
+
}
|
|
1140
1252
|
//console.log("FTC", isToolCall, toolsCall);
|
|
1141
1253
|
const resp = {
|
|
1142
1254
|
isToolCall: isToolCall, toolsCall: toolsCall
|
|
@@ -1385,9 +1497,13 @@ class PromptTemplate {
|
|
|
1385
1497
|
for (const tt of toolTurns) {
|
|
1386
1498
|
buf.push(this.toolsDef.response.replace("{tools_response}", JSON.stringify(tt.response)));
|
|
1387
1499
|
}
|
|
1388
|
-
let tr =
|
|
1500
|
+
let tr = "";
|
|
1389
1501
|
if (this._beforeToolResponse) {
|
|
1390
|
-
tr = this._beforeToolResponse
|
|
1502
|
+
tr = this._beforeToolResponse;
|
|
1503
|
+
}
|
|
1504
|
+
tr = tr + buf.join("");
|
|
1505
|
+
if (this._afterToolResponse) {
|
|
1506
|
+
tr = tr + this._afterToolResponse;
|
|
1391
1507
|
}
|
|
1392
1508
|
return tr;
|
|
1393
1509
|
}
|
|
@@ -1399,7 +1515,13 @@ class PromptTemplate {
|
|
|
1399
1515
|
if (this.tools.length == 0) {
|
|
1400
1516
|
return "";
|
|
1401
1517
|
}
|
|
1402
|
-
|
|
1518
|
+
let _t;
|
|
1519
|
+
if (this._toolCallBuilder == "qwen") {
|
|
1520
|
+
_t = buildQwenToolDef(this.tools);
|
|
1521
|
+
}
|
|
1522
|
+
else {
|
|
1523
|
+
_t = JSON.stringify(this.tools);
|
|
1524
|
+
}
|
|
1403
1525
|
if (raw) {
|
|
1404
1526
|
return _t;
|
|
1405
1527
|
}
|
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,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":{afterShot:"<|END_OF_TURN_TOKEN|>",assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",name:"Command-R",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}"},tags:{think:{end:"</think>",start:"<think>"}},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}"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"</tool_call>",start:"<tool_call>"}},tools:{beforeResponse:"<|observation|>\n",call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",parser:"glm",response:"<tool_response>{tools_response}</tool_response>"},user:"<|user|>\n{prompt}"},gptoss:{assistant:"",id:"gptoss",linebreaks:{assistant:1,system:1,user:1},name:"Gpt Oss",system:{schema:"<|start|>system<|message|>\n{system}\n<|end|>"},tags:{think:{end:"<|end|><|start|>assistant<|channel|>final<|message|>",start:"<|channel|>analysis<|message|>"}},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|>"},ling:{assistant:"<role>ASSISTANT</role>",id:"ling",linebreaks:{assistant:1,user:1},name:"Ling",stop:["<|role_end|>"],user:"<role>HUMAN</role>{prompt}<|role_end|>"},"ling-tools":{assistant:"<role>ASSISTANT</role>",id:"ling-tools",name:"Ling tools",stop:["<|role_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 function calls, return a json array of objects with function names and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n[{"name": <function-name>, "arguments": <args-json-object>}, {"name": <function-name>, "arguments": <args-json-object>}]\n</tool_call>',schema:"<role>SYSTEM</role>{system}<|role_end|>"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<role>OBSERVATION</role>\n<tool_response>\n{tools_response}\n</tool_response><|role_end|>"},user:"<role>HUMAN</role>{prompt}<|role_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>"},minimax:{afterShot:"\n",assistant:"]~b]ai",id:"minimax",name:"Minimax",prefix:"]~!b[",stop:["[e~[","]~b]user"],system:{message:'You are a helpful assistant.\n\n# Tools\nYou may call one or more tools to assist with the user query.\nHere are the tools available in JSONSchema format:\n\n<tools>\n{tools}\n</tools>\n\nWhen making tool calls, use XML format to invoke tools and pass parameters:\n\n<minimax:tool_call>\n<invoke name="tool-name-1">\n<parameter name="param-key-1">param-value-1</parameter>\n<parameter name="param-key-2">param-value-2</parameter>\n...\n</invoke>',schema:"]~b]system"},tools:{call:"<minimax:tool_call>\n{tools}\n</minimax:tool_call>",def:"\n{system}",response:"<minimax:tool_call>\n{tools_response}\n</minimax:tool_call>"},user:"]~b]user\n{prompt}[e~["},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,o){if(o){if("glm"==o)return function(s){try{const t=s.trim().split("</tool_call>").map(s=>s.replace("<tool_call>","")),e=new Array;t.forEach(s=>{s.length>0&&e.push(s.trim().replace("<tool_call>",""))});const o=new Array;for(const s of e)if(s.includes("<arg_key>")){const t=s.indexOf("<arg_key>"),e=s.slice(0,t).trim(),a=s.slice(t),n={},r=a.split(/<\/arg_key>|<\/arg_value>/).filter(s=>s.trim());let l="";for(const s of r)if(s.includes("<arg_key>"))l=s.replace(/<arg_key>/g,"").trim();else{const t=s.replace(/<arg_value>/g,"").trim();n[l]=t}o.push({id:crypto.randomUUID(),name:e,arguments:Object.keys(n).length>0?n:void 0})}else{const t={id:crypto.randomUUID(),name:s.trim()};o.push(t)}return o}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s);throw new Error(`unknown tool response parser ${o}`)}return function(s,t,e){try{const o=s.trim().split(e).map(s=>s.replace(t,"")),a=new Array;o.forEach(s=>{s.length>0&&a.push(s.trim().replace(t,""))});const n=new Array;for(const s of a){let t=JSON.parse(s);t?.id||(t.id=crypto.randomUUID()),n.push(t)}return n}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s,t,e)}class o{id;name;user;assistant;history=[];toolsDef=null;tools=[];tags={};system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;_toolCallParser=null;_beforeToolResponse=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=this.tags?.toolCall?.start||"",this._toolCallEnd=this.tags?.toolCall?.end||null,this._toolCallParser=t?.tools?.parser??null,this._beforeToolResponse=t?.tools?.beforeResponse??null}}get hasTools(){return this.tools.length>0}renderShot(s){const t=[];if(s?.user&&t.push(this._buildUserBlock(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,o="",a=[];const n=s.trim();if(n.includes(this._toolCallStart)){let r;if(t=!0,n.startsWith(this._toolCallStart))r=n;else{const s=n.indexOf(this._toolCallStart);o=n.slice(0,s),r=n.slice(s)}try{const s=e(r,this._toolCallStart,this._toolCallEnd??"",this._toolCallParser??void 0);if(!Array.isArray(s))throw new Error(`error parsing tool call response from model: the response object is not an Array:\n${s}`);a=s}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"))}}const r={isToolCall:t,toolsCall:a};return o.length>0&&(r.assistant=o),r}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=function(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}`)}}(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)));let e=t.join("");return this._beforeToolResponse&&(e=this._beforeToolResponse+e),e}_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}`)}}}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|>"},"chatml-xmltools":{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml-xmltools",linebreaks:{assistant:1,system:1,tools:1,user:1},name:"ChatMl Xml tools",stop:["<|im_end|>"],system:{message:"You are a helpful assistant.\n\nYou have access to the following functions:\n\n<tools>\n{tools}\n</tools>\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>",schema:"<|im_start|>system\n{system}<|im_end|>"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"</tool_call>",start:"<tool_call>"}},tools:{afterResponse:"<|im_end|>\n",beforeResponse:"<|im_start|>user\n",builder:"qwen",call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",parser:"qwen",response:"<tool_response>\n{tools_response}\n</tool_response>\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":{afterShot:"<|END_OF_TURN_TOKEN|>",assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",name:"Command-R",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}"},tags:{think:{end:"</think>",start:"<think>"}},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}"},tags:{think:{end:"</think>",start:"<think>"},toolCall:{end:"</tool_call>",start:"<tool_call>"}},tools:{beforeResponse:"<|observation|>\n",call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",parser:"glm",response:"<tool_response>{tools_response}</tool_response>"},user:"<|user|>\n{prompt}"},gptoss:{assistant:"",id:"gptoss",linebreaks:{assistant:1,system:1,user:1},name:"Gpt Oss",system:{schema:"<|start|>system<|message|>\n{system}\n<|end|>"},tags:{think:{end:"<|end|><|start|>assistant<|channel|>final<|message|>",start:"<|channel|>analysis<|message|>"}},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|>"},ling:{assistant:"<role>ASSISTANT</role>",id:"ling",linebreaks:{assistant:1,user:1},name:"Ling",stop:["<|role_end|>"],user:"<role>HUMAN</role>{prompt}<|role_end|>"},"ling-tools":{assistant:"<role>ASSISTANT</role>",id:"ling-tools",name:"Ling tools",stop:["<|role_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 function calls, return a json array of objects with function names and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n[{"name": <function-name>, "arguments": <args-json-object>}, {"name": <function-name>, "arguments": <args-json-object>}]\n</tool_call>',schema:"<role>SYSTEM</role>{system}<|role_end|>"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<role>OBSERVATION</role>\n<tool_response>\n{tools_response}\n</tool_response><|role_end|>"},user:"<role>HUMAN</role>{prompt}<|role_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>"},minimax:{afterShot:"\n",assistant:"]~b]ai",id:"minimax",name:"Minimax",prefix:"]~!b[",stop:["[e~[","]~b]user"],system:{message:'You are a helpful assistant.\n\n# Tools\nYou may call one or more tools to assist with the user query.\nHere are the tools available in JSONSchema format:\n\n<tools>\n{tools}\n</tools>\n\nWhen making tool calls, use XML format to invoke tools and pass parameters:\n\n<minimax:tool_call>\n<invoke name="tool-name-1">\n<parameter name="param-key-1">param-value-1</parameter>\n<parameter name="param-key-2">param-value-2</parameter>\n...\n</invoke>',schema:"]~b]system"},tools:{call:"<minimax:tool_call>\n{tools}\n</minimax:tool_call>",def:"\n{system}",response:"<minimax:tool_call>\n{tools_response}\n</minimax:tool_call>"},user:"]~b]user\n{prompt}[e~["},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,o){if(o){if("glm"==o)return function(s){try{const t=s.trim().split("</tool_call>").map(s=>s.replace("<tool_call>","")),e=new Array;t.forEach(s=>{s.length>0&&e.push(s.trim().replace("<tool_call>",""))});const o=new Array;for(const s of e)if(s.includes("<arg_key>")){const t=s.indexOf("<arg_key>"),e=s.slice(0,t).trim(),n=s.slice(t),a={},r=n.split(/<\/arg_key>|<\/arg_value>/).filter(s=>s.trim());let l="";for(const s of r)if(s.includes("<arg_key>"))l=s.replace(/<arg_key>/g,"").trim();else{const t=s.replace(/<arg_value>/g,"").trim();a[l]=t}o.push({id:crypto.randomUUID(),name:e,arguments:Object.keys(a).length>0?a:void 0})}else{const t={id:crypto.randomUUID(),name:s.trim()};o.push(t)}return o}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s);if("qwen"==o)return function(s){try{const t=/<function=([^>]+)>([\s\S]*?)<\/function>/g,e=[];let o;for(;null!==(o=t.exec(s));){const s=o[1].trim(),t=o[2],n=/<parameter=([^>]+)>([\s\S]*?)<\/parameter>/g,a={};let r;for(;null!==(r=n.exec(t));){const s=r[1].trim(),t=r[2].trim();a[s]=t}e.push({id:crypto.randomUUID(),name:s,arguments:Object.keys(a).length>0?a:void 0})}return e}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s);throw new Error(`unknown tool response parser ${o}`)}return function(s,t,e){try{const o=s.trim().split(e).map(s=>s.replace(t,"")),n=new Array;o.forEach(s=>{s.length>0&&n.push(s.trim().replace(t,""))});const a=new Array;for(const s of n){let t=JSON.parse(s);t?.id||(t.id=crypto.randomUUID()),a.push(t)}return a}catch(s){throw new Error(`tool call parsing error: ${s}`)}}(s,t,e)}class o{id;name;user;assistant;history=[];toolsDef=null;tools=[];tags={};system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;_toolCallParser=null;_toolCallBuilder=null;_beforeToolResponse=null;_afterToolResponse=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=this.tags?.toolCall?.start||"",this._toolCallEnd=this.tags?.toolCall?.end||null,this._toolCallParser=t?.tools?.parser??null,this._toolCallBuilder=t?.tools?.builder??null,this._beforeToolResponse=t?.tools?.beforeResponse??null,this._afterToolResponse=t?.tools?.afterResponse??null}}get hasTools(){return this.tools.length>0}renderShot(s){const t=[];if(s?.user&&t.push(this._buildUserBlock(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 n=!1;if(this.history.length>0){for(const s of this.history)t.push(this.renderShot(s));this.history[this.history.length-1]?.tools&&(n=!0)}return n?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:[],assistant:s};let t=!1,o="",n=[],a=s.trim();if(a.includes(this._toolCallStart)){let r;if(t=!0,a.startsWith(this._toolCallStart))r=a;else{const s=a.indexOf(this._toolCallStart);o=a.slice(0,s),r=a.slice(s)}try{const s=e(r,this._toolCallStart,this._toolCallEnd??"",this._toolCallParser??void 0);if(!Array.isArray(s))throw new Error(`error parsing tool call response from model: the response object is not an Array:\n${s}`);n=s}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"))}}else o=a;const r={isToolCall:t,toolsCall:n};return o.length>0&&(r.assistant=o),r}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=function(s,t,e){try{const o=s.indexOf(t);if(-1===o)return s;let n,a=o+t.length;if(e){if(n=s.indexOf(e,a),-1===n)return s}else n=s.indexOf("\n",a),-1===n&&(n=s.length);return s.substring(a,n).trim()}catch(s){throw new Error(`Error parsing content between tags ${t} ${e}: ${s}`)}}(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)));let e="";return this._beforeToolResponse&&(e=this._beforeToolResponse),e+=t.join(""),this._afterToolResponse&&(e+=this._afterToolResponse),e}_buildToolsBlock(s=!1){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");let t,e="";return 0==this.tools.length?"":(t="qwen"==this._toolCallBuilder?function(s){const t=new Array;for(const e of s){t.push("<function>"),t.push(`<name>${e.name}</name>`),t.push(`<description>${e.description}</description>`);const s=Object.keys(e.arguments);s.length>0&&t.push("<parameters>");const o=new Array;if(s.forEach(s=>{const n=e.arguments[s];t.push("<parameter>"),t.push(`<name>${s}</name>`),t.push(`<description>${n.description}</description>`),t.push("</parameter>"),n.required&&o.push(s)}),s.length>0){if(o.length>0){const s=o.toString().replaceAll('"',"`");t.push(`<required>${s}</required>`)}t.push("</parameters>")}t.push("</function>")}return t.join("\n")}(this.tools):JSON.stringify(this.tools),s?t:(e+=this.toolsDef.def.replace("{tools}",t),e))}_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}`)}}}return s.PromptTemplate=o,s.templates=t,s}({});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolCallSpec, ToolDefSpec } from "@locallm/types";
|
|
2
|
+
declare function extractQwenToolSpec(text: string, startTag: string, endTag: string): ToolCallSpec[];
|
|
3
|
+
declare function buildQwenToolDef(tools: Array<ToolDefSpec>): string;
|
|
4
|
+
export { extractQwenToolSpec, buildQwenToolDef, };
|