modprompt 0.10.7 → 0.10.8
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/interfaces.d.ts +136 -3
- package/dist/main.js +48 -21
- package/dist/main.min.js +1 -1
- package/package.json +1 -1
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Defines interfaces for managing conversation structures, templates, and tools.
|
|
3
|
+
* Imports: None.
|
|
4
|
+
* @example
|
|
5
|
+
* import { LmTemplate, HistoryTurn } from './conversation';
|
|
6
|
+
* const template: LmTemplate = {
|
|
7
|
+
* id: "alapaca",
|
|
8
|
+
* name: "Alpaca",
|
|
9
|
+
* system: {
|
|
10
|
+
* schema: "{system}",
|
|
11
|
+
* message: "Below is an instruction that describes a task. Write a response that appropriately completes the request.",
|
|
12
|
+
* },
|
|
13
|
+
* user: "### Instruction:\n{prompt}",
|
|
14
|
+
* assistant: "### Response:",
|
|
15
|
+
* linebreaks: {
|
|
16
|
+
* system: 2,
|
|
17
|
+
* user: 2,
|
|
18
|
+
* },
|
|
19
|
+
* tools: {
|
|
20
|
+
* def: "Tool definition",
|
|
21
|
+
* call: "Tool call format",
|
|
22
|
+
* response: "Expected tool response"
|
|
23
|
+
* }
|
|
24
|
+
* };
|
|
25
|
+
* const historyTurn: HistoryTurn = {
|
|
26
|
+
* user: 'What's the weather like?',
|
|
27
|
+
* assistant: 'It's sunny today!',
|
|
28
|
+
* images: [{ id: 1, data: 'base64image' }]
|
|
29
|
+
* };
|
|
30
|
+
*/
|
|
1
31
|
/**
|
|
2
32
|
* Defines the spacing (in terms of line breaks) to be applied between different parts of the conversation.
|
|
3
33
|
*
|
|
@@ -8,7 +38,8 @@
|
|
|
8
38
|
* const spacingExample: SpacingSlots = {
|
|
9
39
|
* system: 2,
|
|
10
40
|
* user: 1,
|
|
11
|
-
* assistant: 1
|
|
41
|
+
* assistant: 1,
|
|
42
|
+
* tools: 0
|
|
12
43
|
* };
|
|
13
44
|
*/
|
|
14
45
|
interface SpacingSlots {
|
|
@@ -24,11 +55,17 @@ interface SpacingSlots {
|
|
|
24
55
|
* Number of line breaks to be applied after the assistant message.
|
|
25
56
|
*/
|
|
26
57
|
assistant?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Number of line breaks to be applied after tool messages.
|
|
60
|
+
*/
|
|
27
61
|
tools?: number;
|
|
28
62
|
}
|
|
29
63
|
/**
|
|
30
64
|
* Represents a block of system-level prompts or instructions in the conversation.
|
|
31
65
|
*
|
|
66
|
+
* @interface PromptBlock
|
|
67
|
+
* @typedef {PromptBlock}
|
|
68
|
+
*
|
|
32
69
|
* @example
|
|
33
70
|
* const promptExample: PromptBlock = {
|
|
34
71
|
* schema: '### System: {system}',
|
|
@@ -52,6 +89,9 @@ interface PromptBlock {
|
|
|
52
89
|
/**
|
|
53
90
|
* Represents a single turn in a conversation, consisting of a user message followed by an assistant response.
|
|
54
91
|
*
|
|
92
|
+
* @interface TurnBlock
|
|
93
|
+
* @typedef {TurnBlock}
|
|
94
|
+
*
|
|
55
95
|
* @example
|
|
56
96
|
* const turnExample: TurnBlock = {
|
|
57
97
|
* user: 'What's the weather like?',
|
|
@@ -67,16 +107,44 @@ interface TurnBlock {
|
|
|
67
107
|
* The corresponding response from the assistant.
|
|
68
108
|
*/
|
|
69
109
|
assistant: string;
|
|
110
|
+
/**
|
|
111
|
+
* Optional tool usage in the turn.
|
|
112
|
+
*/
|
|
70
113
|
tool?: string;
|
|
71
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Definition of language model tools.
|
|
117
|
+
*
|
|
118
|
+
* @interface LmToolsDef
|
|
119
|
+
* @typedef {LmToolsDef}
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const toolDefExample: LmToolsDef = {
|
|
123
|
+
* def: "Tool definition",
|
|
124
|
+
* call: "Tool call format",
|
|
125
|
+
* response: "Expected tool response"
|
|
126
|
+
* };
|
|
127
|
+
*/
|
|
72
128
|
interface LmToolsDef {
|
|
129
|
+
/**
|
|
130
|
+
* The definition or description of the tool.
|
|
131
|
+
*/
|
|
73
132
|
def: string;
|
|
133
|
+
/**
|
|
134
|
+
* The call format for the tool.
|
|
135
|
+
*/
|
|
74
136
|
call: string;
|
|
137
|
+
/**
|
|
138
|
+
* The expected response format from the tool.
|
|
139
|
+
*/
|
|
75
140
|
response: string;
|
|
76
141
|
}
|
|
77
142
|
/**
|
|
78
143
|
* Represents a template for language modeling, detailing the structure and interaction elements of a conversation.
|
|
79
144
|
*
|
|
145
|
+
* @interface LmTemplate
|
|
146
|
+
* @typedef {LmTemplate}
|
|
147
|
+
*
|
|
80
148
|
* @example
|
|
81
149
|
* const sampleTemplate: LmTemplate = {
|
|
82
150
|
* id: "alapaca",
|
|
@@ -90,6 +158,11 @@ interface LmToolsDef {
|
|
|
90
158
|
* linebreaks: {
|
|
91
159
|
* system: 2,
|
|
92
160
|
* user: 2,
|
|
161
|
+
* },
|
|
162
|
+
* tools: {
|
|
163
|
+
* def: "Tool definition",
|
|
164
|
+
* call: "Tool call format",
|
|
165
|
+
* response: "Expected tool response"
|
|
93
166
|
* }
|
|
94
167
|
* };
|
|
95
168
|
*/
|
|
@@ -122,6 +195,9 @@ interface LmTemplate {
|
|
|
122
195
|
* Useful for simulating multi-turn interactions.
|
|
123
196
|
*/
|
|
124
197
|
shots?: Array<TurnBlock>;
|
|
198
|
+
/**
|
|
199
|
+
* Tool definitions for the template.
|
|
200
|
+
*/
|
|
125
201
|
tools?: LmToolsDef;
|
|
126
202
|
/**
|
|
127
203
|
* Optional array of strings that signal the end of a conversation.
|
|
@@ -145,30 +221,87 @@ interface LmTemplate {
|
|
|
145
221
|
prefix?: string;
|
|
146
222
|
}
|
|
147
223
|
/**
|
|
148
|
-
* Image data
|
|
224
|
+
* Image data associated with a message or response.
|
|
149
225
|
*
|
|
150
226
|
* @interface ImgData
|
|
151
227
|
* @typedef {ImgData}
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* const imgExample: ImgData = {
|
|
231
|
+
* id: 1,
|
|
232
|
+
* data: 'base64image'
|
|
233
|
+
* };
|
|
152
234
|
*/
|
|
153
235
|
interface ImgData {
|
|
236
|
+
/**
|
|
237
|
+
* Unique identifier for the image.
|
|
238
|
+
*/
|
|
154
239
|
id: number;
|
|
240
|
+
/**
|
|
241
|
+
* Base64 encoded image data.
|
|
242
|
+
*/
|
|
155
243
|
data: string;
|
|
156
244
|
}
|
|
157
245
|
/**
|
|
158
|
-
*
|
|
246
|
+
* Represents a turn in the conversation history, including user and assistant messages, optional tool usage, and associated images.
|
|
159
247
|
*
|
|
160
248
|
* @interface HistoryTurn
|
|
161
249
|
* @typedef {HistoryTurn}
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* const historyTurnExample: HistoryTurn = {
|
|
253
|
+
* user: 'What's the weather like?',
|
|
254
|
+
* assistant: 'It's sunny today!',
|
|
255
|
+
* images: [{ id: 1, data: 'base64image' }]
|
|
256
|
+
* };
|
|
162
257
|
*/
|
|
163
258
|
interface HistoryTurn {
|
|
259
|
+
/**
|
|
260
|
+
* The message content from the user.
|
|
261
|
+
*/
|
|
164
262
|
user: string;
|
|
263
|
+
/**
|
|
264
|
+
* The corresponding response from the assistant.
|
|
265
|
+
*/
|
|
165
266
|
assistant: string;
|
|
267
|
+
/**
|
|
268
|
+
* Optional tool usage in the turn.
|
|
269
|
+
*/
|
|
166
270
|
tool?: string;
|
|
271
|
+
/**
|
|
272
|
+
* Array of images associated with the turn.
|
|
273
|
+
*/
|
|
167
274
|
images?: Array<ImgData>;
|
|
168
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Specification for a tool that can be used within the conversation.
|
|
278
|
+
*
|
|
279
|
+
* @interface ToolSpec
|
|
280
|
+
* @typedef {ToolSpec}
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* const toolSpecExample: ToolSpec = {
|
|
284
|
+
* name: "WeatherFetcher",
|
|
285
|
+
* description: "Fetches weather information.",
|
|
286
|
+
* arguments: {
|
|
287
|
+
* location: {
|
|
288
|
+
* description: "The location for which to fetch the weather."
|
|
289
|
+
* }
|
|
290
|
+
* }
|
|
291
|
+
* };
|
|
292
|
+
*/
|
|
169
293
|
interface ToolSpec {
|
|
294
|
+
/**
|
|
295
|
+
* The name of the tool.
|
|
296
|
+
*/
|
|
170
297
|
name: string;
|
|
298
|
+
/**
|
|
299
|
+
* A description of what the tool does.
|
|
300
|
+
*/
|
|
171
301
|
description: string;
|
|
302
|
+
/**
|
|
303
|
+
* Arguments required by the tool, with descriptions for each argument.
|
|
304
|
+
*/
|
|
172
305
|
arguments: {
|
|
173
306
|
[key: string]: {
|
|
174
307
|
description: string;
|
package/dist/main.js
CHANGED
|
@@ -15,7 +15,7 @@ const templates = {
|
|
|
15
15
|
"user": "### Instruction:\n{prompt}"
|
|
16
16
|
},
|
|
17
17
|
"chatml": {
|
|
18
|
-
"afterShot": "
|
|
18
|
+
"afterShot": "<|im_end|>",
|
|
19
19
|
"assistant": "<|im_start|>assistant",
|
|
20
20
|
"id": "chatml",
|
|
21
21
|
"linebreaks": {
|
|
@@ -33,7 +33,7 @@ const templates = {
|
|
|
33
33
|
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
34
34
|
},
|
|
35
35
|
"chatml-tools": {
|
|
36
|
-
"afterShot": "
|
|
36
|
+
"afterShot": "<|im_end|>",
|
|
37
37
|
"assistant": "<|im_start|>assistant",
|
|
38
38
|
"id": "chatml",
|
|
39
39
|
"linebreaks": {
|
|
@@ -46,13 +46,13 @@ const templates = {
|
|
|
46
46
|
"<|im_end|>"
|
|
47
47
|
],
|
|
48
48
|
"system": {
|
|
49
|
-
"message": "You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query
|
|
49
|
+
"message": "You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query.\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n{tools}\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n[{\"name\": <function-name>, \"arguments\": <args-json-object>}]\n</tool_call>",
|
|
50
50
|
"schema": "<|im_start|>system\n{system}<|im_end|>"
|
|
51
51
|
},
|
|
52
52
|
"tools": {
|
|
53
|
-
"call": "<tool_call>\n{
|
|
53
|
+
"call": "<tool_call>\n{tools}\n</tool_call>",
|
|
54
54
|
"def": "{system}",
|
|
55
|
-
"response": "<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|im_end
|
|
55
|
+
"response": "<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|im_end|>"
|
|
56
56
|
},
|
|
57
57
|
"user": "<|im_start|>user\n{prompt}<|im_end|>"
|
|
58
58
|
},
|
|
@@ -89,7 +89,7 @@ const templates = {
|
|
|
89
89
|
"user": "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"
|
|
90
90
|
},
|
|
91
91
|
"deephermes": {
|
|
92
|
-
"afterShot": "<|eot_id
|
|
92
|
+
"afterShot": "<|eot_id|>",
|
|
93
93
|
"assistant": "<|start_header_id|>assistant<|end_header_id|>",
|
|
94
94
|
"id": "deephermes",
|
|
95
95
|
"name": "Deephermes",
|
|
@@ -98,15 +98,15 @@ const templates = {
|
|
|
98
98
|
"<|end_of_text|>"
|
|
99
99
|
],
|
|
100
100
|
"system": {
|
|
101
|
-
"message": "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {tools} </tools>. For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n{\"arguments\": <args-dict>, \"name\": <function-name>}\n</tool_call>",
|
|
101
|
+
"message": "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {tools} </tools>. For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n[{\"arguments\": <args-dict>, \"name\": <function-name>}]\n</tool_call>",
|
|
102
102
|
"schema": "<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"
|
|
103
103
|
},
|
|
104
104
|
"tools": {
|
|
105
105
|
"call": "<tool_call>\n{tools}\n</tool_call>",
|
|
106
106
|
"def": "{system}",
|
|
107
|
-
"response": "<|start_header_id|>user<|end_header_id|>\n<tool_response>\n{tools_response}\n</tool_response><|eot_id
|
|
107
|
+
"response": "<|start_header_id|>user<|end_header_id|>\n<tool_response>\n{tools_response}\n</tool_response><|eot_id|>"
|
|
108
108
|
},
|
|
109
|
-
"user": "<|start_header_id|>user<|end_header_id|>\n
|
|
109
|
+
"user": "<|start_header_id|>user<|end_header_id|>\n{prompt}<|eot_id|>"
|
|
110
110
|
},
|
|
111
111
|
"deepseek": {
|
|
112
112
|
"afterShot": "\n",
|
|
@@ -162,18 +162,36 @@ const templates = {
|
|
|
162
162
|
},
|
|
163
163
|
"user": "<|User|>{prompt}"
|
|
164
164
|
},
|
|
165
|
+
"exaone": {
|
|
166
|
+
"afterShot": "[|endofturn|]",
|
|
167
|
+
"assistant": "[|assistant|]",
|
|
168
|
+
"id": "exaone",
|
|
169
|
+
"linebreaks": {
|
|
170
|
+
"system": 1,
|
|
171
|
+
"user": 1
|
|
172
|
+
},
|
|
173
|
+
"name": "Exaone",
|
|
174
|
+
"stop": [
|
|
175
|
+
"[|endofturn|]"
|
|
176
|
+
],
|
|
177
|
+
"system": {
|
|
178
|
+
"message": "You are EXAONE model from LG AI Research, a helpful assistant.",
|
|
179
|
+
"schema": "[|system|]{system}[|endofturn|]"
|
|
180
|
+
},
|
|
181
|
+
"user": "[|user|]{prompt}[|endofturn|]"
|
|
182
|
+
},
|
|
165
183
|
"gemma": {
|
|
166
|
-
"afterShot": "
|
|
167
|
-
"assistant": "<
|
|
184
|
+
"afterShot": "<end_of_turn>",
|
|
185
|
+
"assistant": "<start_of_turn>model",
|
|
168
186
|
"id": "gemma",
|
|
169
187
|
"name": "Gemma",
|
|
170
188
|
"stop": [
|
|
171
189
|
"<end_of_turn>"
|
|
172
190
|
],
|
|
173
|
-
"user": "<start_of_turn>user\n{prompt}"
|
|
191
|
+
"user": "<start_of_turn>user\n{prompt}\n <end_of_turn>"
|
|
174
192
|
},
|
|
175
193
|
"granite": {
|
|
176
|
-
"afterShot": "<|end_of_text
|
|
194
|
+
"afterShot": "<|end_of_text|>",
|
|
177
195
|
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
178
196
|
"id": "granite",
|
|
179
197
|
"linebreaks": {
|
|
@@ -192,7 +210,7 @@ const templates = {
|
|
|
192
210
|
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
193
211
|
},
|
|
194
212
|
"granite-think": {
|
|
195
|
-
"afterShot": "<|end_of_text
|
|
213
|
+
"afterShot": "<|end_of_text|>",
|
|
196
214
|
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
197
215
|
"id": "granite-think",
|
|
198
216
|
"linebreaks": {
|
|
@@ -211,7 +229,7 @@ const templates = {
|
|
|
211
229
|
"user": "<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"
|
|
212
230
|
},
|
|
213
231
|
"granite-tools": {
|
|
214
|
-
"afterShot": "<|end_of_text
|
|
232
|
+
"afterShot": "<|end_of_text|>",
|
|
215
233
|
"assistant": "<|start_of_role|>assistant<|end_of_role|>",
|
|
216
234
|
"id": "granite-tools",
|
|
217
235
|
"linebreaks": {
|
|
@@ -268,7 +286,7 @@ const templates = {
|
|
|
268
286
|
"user": "<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"
|
|
269
287
|
},
|
|
270
288
|
"llama3-think": {
|
|
271
|
-
"afterShot": "<|eot_id
|
|
289
|
+
"afterShot": "<|eot_id|>",
|
|
272
290
|
"assistant": "<|start_header_id|>assistant<|end_header_id|>",
|
|
273
291
|
"id": "llama3",
|
|
274
292
|
"name": "Llama 3",
|
|
@@ -338,7 +356,7 @@ const templates = {
|
|
|
338
356
|
"schema": "[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"
|
|
339
357
|
},
|
|
340
358
|
"tools": {
|
|
341
|
-
"call": "[TOOL_CALLS]
|
|
359
|
+
"call": "[TOOL_CALLS]{tools}",
|
|
342
360
|
"def": "[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",
|
|
343
361
|
"response": "[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"
|
|
344
362
|
},
|
|
@@ -397,7 +415,7 @@ const templates = {
|
|
|
397
415
|
"user": "### User:\n{prompt}"
|
|
398
416
|
},
|
|
399
417
|
"phi3": {
|
|
400
|
-
"afterShot": "<|end
|
|
418
|
+
"afterShot": "<|end|>",
|
|
401
419
|
"assistant": "<|assistant|>",
|
|
402
420
|
"id": "phi3",
|
|
403
421
|
"name": "Phi 3",
|
|
@@ -411,7 +429,7 @@ const templates = {
|
|
|
411
429
|
"user": "<|user|> {prompt}<|end|>"
|
|
412
430
|
},
|
|
413
431
|
"phi4": {
|
|
414
|
-
"afterShot": "<|im_end
|
|
432
|
+
"afterShot": "<|im_end|>",
|
|
415
433
|
"assistant": "<|im_start|>assistant<|im_sep|>",
|
|
416
434
|
"id": "phi4",
|
|
417
435
|
"name": "Phi 4",
|
|
@@ -586,9 +604,13 @@ class PromptTemplate {
|
|
|
586
604
|
}
|
|
587
605
|
let isToolCall = false;
|
|
588
606
|
let toolsCall = new Array();
|
|
589
|
-
|
|
607
|
+
const ans = answer.trim();
|
|
608
|
+
//console.log("\nTC ANSWER", ans);
|
|
609
|
+
//console.log("TC SW", this._toolCallStart, ans.startsWith(this._toolCallStart));
|
|
610
|
+
if (ans.startsWith(this._toolCallStart)) {
|
|
590
611
|
isToolCall = true;
|
|
591
|
-
|
|
612
|
+
let tcs = this._parseToolCallString(answer).trim();
|
|
613
|
+
//console.log("TCS", tcs);
|
|
592
614
|
let errMsg = "";
|
|
593
615
|
try {
|
|
594
616
|
const tc = JSON.parse(tcs);
|
|
@@ -596,6 +618,7 @@ class PromptTemplate {
|
|
|
596
618
|
errMsg = `error parsing tool call response from model: the response object is not an Array:\n${answer}`;
|
|
597
619
|
console.log(errMsg);
|
|
598
620
|
}
|
|
621
|
+
//console.log("TC", tc)
|
|
599
622
|
toolsCall = tc;
|
|
600
623
|
}
|
|
601
624
|
catch (e) {
|
|
@@ -606,6 +629,7 @@ class PromptTemplate {
|
|
|
606
629
|
return { isToolCall: false, toolsCall: [], error: errMsg };
|
|
607
630
|
}
|
|
608
631
|
}
|
|
632
|
+
//console.log("FTC", isToolCall, toolsCall);
|
|
609
633
|
return { isToolCall: isToolCall, toolsCall: toolsCall };
|
|
610
634
|
}
|
|
611
635
|
encodeToolResponse(response) {
|
|
@@ -936,6 +960,9 @@ class PromptTemplate {
|
|
|
936
960
|
return _t;
|
|
937
961
|
}
|
|
938
962
|
toolsBlock += this.toolsDef.def.replace("{tools}", _t);
|
|
963
|
+
/*console.log("TB-------");
|
|
964
|
+
console.log(toolsBlock);
|
|
965
|
+
console.log("END------------")*/
|
|
939
966
|
return toolsBlock;
|
|
940
967
|
}
|
|
941
968
|
_buildUserBlock(msg) {
|
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},chatml:{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},"chatml-tools":{afterShot:" <|im_end|>\n",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{message:'You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query.\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\\n{tools}\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{"name": <function-name>, "arguments": <args-json-object>}\\n</tool_call>',schema:"<|im_start|>system\n{system}<|im_end|>"},tools:{call:"<tool_call>\n{tool}\n</tool_call>",def:"{system}",response:"<|im_start|>user\n<tool_response>\n{tools_response}\n</tool_response><|im_end|>\n"},user:"<|im_start|>user\n{prompt}<|im_end|>"},codestral:{afterShot:"\n",assistant:" [/INST]",id:"codestral",linebreaks:{system:2},name:"Codestral",stop:["</s>"],system:{schema:"<<SYS>>\n{system}\n<</SYS>>"},user:"[INST] {prompt}"},"command-r":{assistant:"<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",id:"command-r",linebreaks:{user:1},name:"Command-R",prefix:"<BOS_TOKEN>",stop:["<|END_OF_TURN_TOKEN|>"],system:{schema:"<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{system}<|END_OF_TURN_TOKEN|>"},user:"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{prompt}<|END_OF_TURN_TOKEN|>"},deephermes:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"deephermes",name:"Deephermes",stop:["<|eot_id|>","<|end_of_text|>"],system:{message:'You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don\'t make assumptions about what values to plug into functions. Here are the available tools: <tools> {tools} </tools>. For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n{"arguments": <args-dict>, "name": <function-name>}\n</tool_call>',schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},tools:{call:"<tool_call>\n{tools}\n</tool_call>",def:"{system}",response:"<|start_header_id|>user<|end_header_id|>\n<tool_response>\n{tools_response}\n</tool_response><|eot_id|>\n"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},deepseek:{afterShot:"\n",assistant:"### Response:",id:"deepseek",linebreaks:{system:1,user:1},name:"Deepseek",stop:["<|EOT|>","### Instruction:"],system:{message:"You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer.",schema:"{system}"},user:"### Instruction:\n{prompt}"},deepseek2:{assistant:"Assistant:",id:"deepseek2",linebreaks:{system:2,user:2},name:"Deepseek 2",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"User: {prompt}"},deepseek3:{afterShot:"<|end▁of▁sentence|>",assistant:"<|Assistant|>",id:"deepseek3",linebreaks:{system:2,user:2},name:"Deepseek 3",stop:["<|end▁of▁sentence|>","<|tool▁calls▁end|>"],system:{schema:"<|begin▁of▁sentence|>{system}"},user:"<|User|>{prompt}"},gemma:{afterShot:"\n",assistant:"<end_of_turn>\n<start_of_turn>model",id:"gemma",name:"Gemma",stop:["<end_of_turn>"],user:"<start_of_turn>user\n{prompt}"},granite:{afterShot:"<|end_of_text|>\n",assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite",linebreaks:{system:1,user:1},name:"Granite",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},"granite-think":{afterShot:"<|end_of_text|>\n",assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite-think",linebreaks:{system:1,user:1},name:"Granite think",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant. Respond to every user query in a comprehensive and detailed way. You can write down your thoughts and reasoning process before responding. In the thought process, engage in a comprehensive cycle of analysis, summarization, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. In the response section, based on various attempts, explorations, and reflections from the thoughts section, systematically present the final solution that you deem correct. The response should summarize the thought process. Write your thoughts after 'Here is my thought process:' and write your response after 'Here is my response:' for each user query.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},"granite-tools":{afterShot:"<|end_of_text|>\n",assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite-tools",linebreaks:{system:1,tools:1,user:1},name:"Granite tools",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},tools:{call:"<tool_call>{tools}",def:"<|start_of_role|>tools<|end_of_role|>{tools}<|end_of_text|>",response:"<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>\n"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{message:"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},"llama3-think":{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{message:"You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.",schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},"mistral-system":{afterShot:"\n",assistant:"[/INST]",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},user:"[INST]{prompt}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},tools:{call:"[TOOL_CALLS] {tools}</s>",def:"[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",response:"[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"},user:"[INST]{prompt}[/INST]"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi3:{afterShot:"<|end|>\n",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>\n",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},reka:{afterShot:" <sep> ",assistant:"assistant:",id:"reka",name:"Reka",stop:["<sep>","<|endoftext|>"],user:"human: {prompt} <sep> "},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];toolsDef=null;tools=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;constructor(s){let e;if(e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix,e?.tools){this.toolsDef=e.tools;const s=this.toolsDef?.call.split("{tools}");if(!s)throw new Error(`Tool definition malformed in template ${this.name}`);if(0==s.length)throw new Error(`Tool definition malformed in template ${this.name}: no start tool call definition`);this._toolCallStart=s[0],s.length>1&&(this._toolCallEnd=s[1])}}get hasTools(){return this.tools.length>0}addTool(s){if(!this?.toolsDef)throw new Error("This template does not support tools");return this.tools.push(s),this}processAnswer(s){if(!this.hasTools)return{isToolCall:!1,toolsCall:[]};let e=!1,t=new Array;if(s.startsWith(this._toolCallStart)){e=!0;const o=this._parseToolCallString(s);let a="";try{const e=JSON.parse(o);Array.isArray(e)||(a=`error parsing tool call response from model: the response object is not an Array:\n${s}`,console.log(a)),t=e}catch(e){a=`error parsing tool call response from model:\n${s}`,console.log(a)}if(a)return{isToolCall:!1,toolsCall:[],error:a}}return{isToolCall:e,toolsCall:t}}encodeToolResponse(s){if(!this.toolsDef)throw new Error("can not encode tool response: the template has no tools definition");return this.toolsDef.response.replace("{tools_response}",`${s}`)}cloneTo(s,e=!0){const o=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{o.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&o.afterSystem(this._extraSystem),this._replaceSystem.length>0&&o.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&o.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&o.replacePrompt(this._replacePrompt),o}toJson(){const s={id:this.id,name:this.name,user:this.user,assistant:this.assistant};return this?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.linebreaks=this.linebreaks),s}replaceSystem(s){return this.system?(this._replaceSystem=s,this):this}afterSystem(s){return this.system?(this._extraSystem=s,this):this}afterAssistant(s){return this._extraAssistant=s,this}replacePrompt(s){return this._replacePrompt=s,this}addShot(s,e,t){if(t&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push({user:s,assistant:e,tool:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),s?.tool&&e.push(this._buildToolResponse(s.tool)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t="{system}"==this?.toolsDef?.def,o=this._buildSystemBlock(s,t);if(o.length>0&&(e.push(o),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this.toolsDef&&!t){const s=this._buildToolsBlock();s.length>0&&(e.push(s),this?.linebreaks?.tools&&e.push("\n".repeat(this.linebreaks.tools)))}if(this?.shots)for(const s of this.shots)e.push(this.renderShot(s));let a=!1;if(this.history.length>0){for(const s of this.history)e.push(this.renderShot(s));this.history[this.history.length-1]?.tool&&(a=!0)}return a||e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s,e=!0){return this.render(e).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s,e=!1){let t="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(t=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(t+=this._extraSystem)):s||(t=this.system.schema),e&&(t=t.replace("{tools}",this._buildToolsBlock(!0))),t):""}_buildToolResponse(s){if(!this.toolsDef)throw new Error("No tools def in template to build tool response");return this.toolsDef.response.replace("{tools_response}",s)}_buildToolsBlock(s=!1){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");let e="";if(0==this.tools.length)return"";const t=JSON.stringify(this.tools);return s?t:(e+=this.toolsDef.def.replace("{tools}",t),e)}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}_parseToolCallString(s){let e=s.replace(this._toolCallStart,"");return this._toolCallEnd&&(e=e.replace(this._toolCallEnd,"")),e}}return s.PromptTemplate=t,s.templates=e,s}({});
|
|
1
|
+
var $tpl=function(s){"use strict";const e={alpaca:{assistant:"### Response:",id:"alpaca",linebreaks:{system:2,user:2},name:"Alpaca",system:{message:"Below is an instruction that describes a task. Write a response that appropriately completes the request.",schema:"{system}"},user:"### Instruction:\n{prompt}"},chatml:{afterShot:"<|im_end|>",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{schema:"<|im_start|>system\n{system}<|im_end|>"},user:"<|im_start|>user\n{prompt}<|im_end|>"},"chatml-tools":{afterShot:"<|im_end|>",assistant:"<|im_start|>assistant",id:"chatml",linebreaks:{assistant:1,system:1,user:1},name:"ChatMl",stop:["<|im_end|>"],system:{message:'You are a helpful assistant with tool calling capabilities. You may call one or more functions to assist with the user query.\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>\n{tools}\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n[{"name": <function-name>, "arguments": <args-json-object>}]\n</tool_call>',schema:"<|im_start|>system\n{system}<|im_end|>"},tools:{call:"<tool_call>\n{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|>",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}"},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>"},granite:{afterShot:"<|end_of_text|>",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|>",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|>",assistant:"<|start_of_role|>assistant<|end_of_role|>",id:"granite-tools",linebreaks:{system:1,tools:1,user:1},name:"Granite tools",stop:["<|end_of_text|>","<|start_of_role|>"],system:{message:"You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.",schema:"<|start_of_role|>system<|end_of_role|>{system}<|end_of_text|>"},tools:{call:"<tool_call>{tools}",def:"<|start_of_role|>tools<|end_of_role|>{tools}<|end_of_text|>",response:"<|start_of_role|>tool_response<|end_of_role|>{tools_response}<|end_of_text|>\n"},user:"<|start_of_role|>user<|end_of_role|>{prompt}<|end_of_text|>"},llama:{assistant:" [/INST] ",id:"llama",linebreaks:{system:2,user:0},name:"Llama",prefix:"<s>",stop:["</s>"],system:{message:"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.",schema:"[INST] <<SYS>>\n{system}\n<</SYS>>"},user:"{prompt}"},llama3:{afterShot:"<|eot_id|>\n\n",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},"llama3-think":{afterShot:"<|eot_id|>",assistant:"<|start_header_id|>assistant<|end_header_id|>",id:"llama3",name:"Llama 3",stop:["<|eot_id|>","<|end_of_text|>"],system:{message:"You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.",schema:"<|start_header_id|>system<|end_header_id|>\n\n{system}<|eot_id|>"},user:"<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|>"},llava:{assistant:"ASSISTANT:",id:"llava",linebreaks:{user:1},name:"Llava",user:"USER: {prompt}"},minichat:{afterShot:"\n",assistant:"[|Assistant|]",id:"minichat",name:"Minichat",prefix:"<s> ",stop:["</s>","[|User|]"],user:"[|User|] {prompt} </s>"},mistral:{afterShot:"\n",assistant:" [/INST]",id:"mistral",name:"Mistral",stop:["</s>"],user:"[INST] {prompt}"},"mistral-system":{afterShot:"\n",assistant:"[/INST]",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},user:"[INST]{prompt}"},"mistral-system-tools":{afterShot:"\n",assistant:"",id:"mistral-system",name:"Mistral system",stop:["</s>"],system:{schema:"[SYSTEM_PROMPT]{system_prompt}[/SYSTEM_PROMPT]"},tools:{call:"[TOOL_CALLS]{tools}",def:"[AVAILABLE_TOOLS]{tools}[/AVAILABLE_TOOLS]",response:"[TOOL_RESULTS]{tools_response}[/TOOL_RESULTS]"},user:"[INST]{prompt}[/INST]"},nemotron:{afterShot:"\n\n",assistant:"<extra_id_1>Assistant",id:"nemotron",linebreaks:{system:2,user:1},name:"Nemotron",system:{schema:"<extra_id_0>System\n{system}"},user:"<extra_id_1>User\n{prompt}"},none:{assistant:"",id:"none",name:"No template",user:"{prompt}"},openchat:{assistant:"GPT4 Assistant:",id:"openchat",name:"OpenChat",stop:["<|end_of_turn|>"],user:"GPT4 User: {prompt}<|end_of_turn|>"},"openchat-correct":{assistant:"GPT4 Correct Assistant:",id:"openchat-correct",name:"OpenChat correct",stop:["<|end_of_turn|>"],user:"GPT4 Correct User: {prompt}<|end_of_turn|>"},orca:{assistant:"### Response:",id:"orca",linebreaks:{system:2,user:2},name:"Orca",system:{message:"You are an AI assistant that follows instruction extremely well. Help as much as you can.",schema:"### System:\n{system}"},user:"### User:\n{prompt}"},phi3:{afterShot:"<|end|>",assistant:"<|assistant|>",id:"phi3",name:"Phi 3",stop:["<|end|>","<|user|>"],system:{schema:"<|system|> {system}<|end|>"},user:"<|user|> {prompt}<|end|>"},phi4:{afterShot:"<|im_end|>",assistant:"<|im_start|>assistant<|im_sep|>",id:"phi4",name:"Phi 4",stop:["<|im_end|>","<|im_sep|>"],system:{schema:"<|im_start|>system<|im_sep|>{system}<|im_end|>"},user:"<|im_start|>user<|im_sep|>{prompt}<|im_end|>"},reka:{afterShot:" <sep> ",assistant:"assistant:",id:"reka",name:"Reka",stop:["<sep>","<|endoftext|>"],user:"human: {prompt} <sep> "},vicuna:{assistant:"### ASSISTANT:",id:"vicuna",linebreaks:{user:2},name:"Vicuna",user:"USER: {prompt}"},vicuna_system:{assistant:"### ASSISTANT:",id:"vicuna_system",linebreaks:{system:2,user:2},name:"Vicuna system",system:{schema:"SYSTEM: {system}"},user:"USER: {prompt}"},wizard_vicuna:{assistant:"### ASSISTANT:",id:"wizard_vicuna",linebreaks:{user:2},name:"Wizard Vicuna",stop:["<|endoftext|>"],user:"### Human:\n{prompt}"},wizardlm:{assistant:"ASSISTANT:",id:"wizardlm",linebreaks:{user:1},name:"WizardLM",system:{message:"You are a helpful AI assistant.",schema:"{system}"},user:"USER: {prompt}"},zephyr:{afterShot:"\n",assistant:"<|assistant|>",id:"zephyr",linebreaks:{assistant:1,system:1,user:1},name:"Zephyr",stop:["<|endoftext|>"],system:{schema:"<|system|>\n{system}<|endoftext|>"},user:"<|user|>\n{prompt}<|endoftext|>"}};class t{id;name;user;assistant;history=[];toolsDef=null;tools=[];system;shots;stop;linebreaks;afterShot;prefix;_extraSystem="";_extraAssistant="";_replacePrompt="";_replaceSystem="";_toolCallStart="";_toolCallEnd=null;constructor(s){let e;if(e="string"==typeof s?this._load(s):s,this.id=e.id,this.name=e.name,this.user=e.user,this.assistant=e.assistant,this.system=e.system,this.shots=e.shots,this.stop=e.stop,this.linebreaks=e.linebreaks,this.afterShot=e.afterShot,this.prefix=e.prefix,e?.tools){this.toolsDef=e.tools;const s=this.toolsDef?.call.split("{tools}");if(!s)throw new Error(`Tool definition malformed in template ${this.name}`);if(0==s.length)throw new Error(`Tool definition malformed in template ${this.name}: no start tool call definition`);this._toolCallStart=s[0],s.length>1&&(this._toolCallEnd=s[1])}}get hasTools(){return this.tools.length>0}addTool(s){if(!this?.toolsDef)throw new Error("This template does not support tools");return this.tools.push(s),this}processAnswer(s){if(!this.hasTools)return{isToolCall:!1,toolsCall:[]};let e=!1,t=new Array;if(s.trim().startsWith(this._toolCallStart)){e=!0;let o=this._parseToolCallString(s).trim(),a="";try{const e=JSON.parse(o);Array.isArray(e)||(a=`error parsing tool call response from model: the response object is not an Array:\n${s}`,console.log(a)),t=e}catch(e){a=`error parsing tool call response from model:\n${s}`,console.log(a)}if(a)return{isToolCall:!1,toolsCall:[],error:a}}return{isToolCall:e,toolsCall:t}}encodeToolResponse(s){if(!this.toolsDef)throw new Error("can not encode tool response: the template has no tools definition");return this.toolsDef.response.replace("{tools_response}",`${s}`)}cloneTo(s,e=!0){const o=new t(s);return e&&this?.shots&&this.shots.forEach((s=>{o.addShot(s.user,s.assistant)})),this._extraSystem.length>0&&o.afterSystem(this._extraSystem),this._replaceSystem.length>0&&o.replaceSystem(this._replaceSystem),this._extraAssistant.length>0&&o.afterAssistant(this._extraAssistant),this._replacePrompt.length>0&&o.replacePrompt(this._replacePrompt),o}toJson(){const s={id:this.id,name:this.name,user:this.user,assistant:this.assistant};return this?.prefix&&(s.prefix=this.prefix),this?.system&&(s.system=this.system),this?.shots&&(s.shots=this.shots),this?.afterShot&&(s.afterShot=this.afterShot),this?.stop&&(s.stop=this.stop),this?.linebreaks&&(s.linebreaks=this.linebreaks),s}replaceSystem(s){return this.system?(this._replaceSystem=s,this):this}afterSystem(s){return this.system?(this._extraSystem=s,this):this}afterAssistant(s){return this._extraAssistant=s,this}replacePrompt(s){return this._replacePrompt=s,this}addShot(s,e,t){if(t&&!this.toolsDef)throw new Error("This template does not support tools");return this.shots||(this.shots=[]),this.shots.push({user:s,assistant:e,tool:t}),this}addShots(s){return s.forEach((s=>this.addShot(s.user,s.assistant))),this}renderShot(s){const e=[];e.push(this._buildUserBlock(s.user));let t=s.assistant;return this.afterShot&&(t+=this.afterShot),e.push(this._buildAssistantBlock(t)),s?.tool&&e.push(this._buildToolResponse(s.tool)),e.join("")}render(s=!0){const e=new Array;this.prefix&&e.push(this.prefix);const t="{system}"==this?.toolsDef?.def,o=this._buildSystemBlock(s,t);if(o.length>0&&(e.push(o),this?.linebreaks?.system&&e.push("\n".repeat(this.linebreaks.system))),this.toolsDef&&!t){const s=this._buildToolsBlock();s.length>0&&(e.push(s),this?.linebreaks?.tools&&e.push("\n".repeat(this.linebreaks.tools)))}if(this?.shots)for(const s of this.shots)e.push(this.renderShot(s));let a=!1;if(this.history.length>0){for(const s of this.history)e.push(this.renderShot(s));this.history[this.history.length-1]?.tool&&(a=!0)}return a||e.push(this._buildUserBlock()),e.push(this._buildAssistantBlock()),e.join("")}prompt(s,e=!0){return this.render(e).replace("{prompt}",s)}pushToHistory(s){return this.history.push(s),this}_buildSystemBlock(s,e=!1){let t="";return this?.system?(this._replaceSystem&&(this.system.message=this._replaceSystem),this.system?.message?(t=this.system.schema.replace("{system}",this.system.message),this._extraSystem&&(t+=this._extraSystem)):s||(t=this.system.schema),e&&(t=t.replace("{tools}",this._buildToolsBlock(!0))),t):""}_buildToolResponse(s){if(!this.toolsDef)throw new Error("No tools def in template to build tool response");return this.toolsDef.response.replace("{tools_response}",s)}_buildToolsBlock(s=!1){if(!this.toolsDef)throw new Error("Can not build tools block: no tools definition found in template");let e="";if(0==this.tools.length)return"";const t=JSON.stringify(this.tools);return s?t:(e+=this.toolsDef.def.replace("{tools}",t),e)}_buildUserBlock(s){let e=[],t=this.user;return this._replacePrompt.length>0&&(t=t.replace("{prompt}",this._replacePrompt)),e.push(t),this?.linebreaks?.user&&e.push("\n".repeat(this.linebreaks.user)),s&&(e[0]=this.user.replace("{prompt}",s)),e.join("")}_buildAssistantBlock(s){let e=[],t=this.assistant;return this?.linebreaks?.assistant&&(t+="\n".repeat(this.linebreaks.assistant)),this._extraAssistant.length>0&&(t+=this._extraAssistant),e.push(t),s&&e.push(s),e.join("")}_load(s){try{if(s in e)return e[s];throw new Error(`Template ${s} not found`)}catch(e){throw new Error(`Error loading template ${s}: ${e}`)}}_parseToolCallString(s){let e=s.replace(this._toolCallStart,"");return this._toolCallEnd&&(e=e.replace(this._toolCallEnd,"")),e}}return s.PromptTemplate=t,s.templates=e,s}({});
|