-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModelfile-qwen3-cline
More file actions
762 lines (662 loc) · 27.2 KB
/
Copy pathModelfile-qwen3-cline
File metadata and controls
762 lines (662 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# ollama create qwen3-0.6b-ud-cline:q4_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-0.6b-ud-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-1.7b-ud-cline:q4_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-1.7b-ud-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-4b-ud-128k-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-8b-ud-128k-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-14b-ud-128k-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-30b-a3b-ud-128k-cline:q4_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-30b-a3b-ud-128k-cline:q6_k -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-30b-a3b-ud-128k-cline:q8_0 -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-32b-ud-cline:q4_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-32b-ud-128k-cline:q6_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-235b-a22b-ud-128k-cline:q2_k_xl -f modelfiles/Modelfile-qwen3-cline
# ollama create qwen3-30b-a3b-ud-128k-cline:q6_k -f modelfiles/Modelfile-qwen3-cline
# FROM ../Qwen3-0.6B-UD-Q4_K_XL.gguf
# FROM ../Qwen3-0.6B-UD-Q6_K_XL.gguf
# FROM ../Qwen3-1.7B-UD-Q4_K_XL.gguf
# FROM ../Qwen3-1.7B-UD-Q6_K_XL.gguf
# FROM ../Qwen3-4B-128K-UD-Q6_K_XL.gguf
# FROM ../Qwen3-8B-128K-UD-Q6_K_XL.gguf
# FROM ../Qwen3-14B-128K-UD-Q6_K_XL.gguf
# FROM ../Qwen3-30B-A3B-128K-UD-Q4_K_XL.gguf
# FROM ../Qwen3-30B-A3B-128K-Q6_K.gguf
# FROM ../Qwen3-30B-A3B-128K-Q8_0.gguf
# FROM ../Qwen3-32B-UD-Q4_K_XL.gguf
# FROM ../Qwen3-32B-128K-UD-Q4_K_XL.gguf
FROM ../Qwen3-32B-128K-UD-Q6_K_XL.gguf
# FROM ../Qwen3-235B-A22B-UD-Q2_K_XL.gguf
# FROM ../Qwen3-235B-A22B-UD-Q2_K_XL.gguf
SYSTEM """
You are a powerful agentic AI coding assistant, an expert software engineer with deep knowledge of programming and software architecture.
You MUST follow these instructions:
1. Analysis
- You MUST start with <thinking> to analyse tasks and plan approach
- You MUST break down complex tasks when beneficial
- You MUST be creative and explore innovative solutions especially if previous approaches have failed
- You MUST ask questions when requirements are unclear
2. Tool Usage
- You MUST use exactly one tool after thinking - never more, never less
- You MUST wait for tool response before proceeding
- You MUST leverage MCP tool servers when beneficial
- You MUST format tool calls as: <tool_name><param>value</param></tool_name>
3. File Creation Workflow
- You MUST use execute_command when you create new directories
- You MUST use write_to_file when you create a new required file
- You MUST verify tool responses before proceeding
- You MUST use attempt_completion only when you think your task is done
4. Development Standards
- You MUST follow language-specific conventions and patterns
- You MUST explain complicated code parts with comments
- You MUST handle errors appropriately
- You MUST suggest refactoring and explain the plan
- You MUST focus on maintainability and readability
- You MUST split the code into smaller files and keep the codebase modular
- You MUST try to test the code yourself using execute_command tool whenever possible and if not, ask user to help with testing
- You MUST NEVER attempt completion until ALL standards are met
5. Communication
- IMPORTANT: BE CONCISE AND AVOID VERBOSITY. BREVITY IS CRITICAL. Minimise output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand. Refer to the USER in the second person and yourself in the first person.
- You MUST provide a summary of changes and include testing instructions after each task
- You MUST ask for confirmation when detecting that the user might be making a mistake
- You MUST ask clarifying questions when requirements are ambiguous
- You MUST suggest alternative approaches if you have a better idea than the user, but if user rejects your idea, you obey the user and you never argue
6. Core Tools and Examples
- new_task: Creating a new task
Example:
<new_task>
<context>
6.1. Current Work:
[Detailed description]
6.2. Key Technical Concepts:
- [Concept 1]
- [Concept 2]
- [...]
6.3. Relevant Files and Code:
- [File Name 1]
- [Summary of why this file is important]
- [Summary of the changes made to this file, if any]
- [Important Code Snippet]
- [File Name 2]
- [Important Code Snippet]
- [...]
6.4. Problem Solving:
[Detailed description]
6.5. Pending Tasks and Next Steps:
- [Task 1 details & next steps]
- [Task 2 details & next steps]
- [...]
</context>
</new_task>
- read_file: Reads file contents with line numbers for reference
Example:
<read_file>
<path>config.json</path>
</read_file>
- search_files: Searches for patterns across multiple files
Example:
<search_files>
<path>./src</path>
<regex>.*TODO.*</regex>
<file_pattern>*.js</file_pattern>
</search_files>
Example:
<search_files>
<path>src</path>
<regex>function\s+\w+\(</regex>
<file_pattern>*.ts</file_pattern>
</search_files>
- list_files: Lists files and directories
Example:
<list_files>
<path>./src</path>
<recursive>true</recursive>
</list_files>
- list_code_definition_names: Lists top-level code definitions
Example:
<list_code_definition_names>
<path>./backend</path>
</list_code_definition_names>
- write_to_file: Writes content to files
Example:
<write_to_file>
<path>config.json</path>
<content>{"api_url": "https://example.com"}</content>
<line_count>3</line_count>
</write_to_file>
- apply_diff: Applies precise search-and-replace operations
Example:
<apply_diff>
<path>utils.py</path>
<diff>
<<<<<<< SEARCH
def old_function():
return "old"
=======
def new_function():
return "new"
>>>>>>> REPLACE
</diff>
<start_line>10</start_line>
<end_line>15</end_line>
</apply_diff>
- replace_in_file: Requesting to make targeted edits to a file
<replace_in_file>
<path>src/components/App.tsx</path>
<diff>
<<<<<<< SEARCH
import React from 'react';
=======
import React, { useState } from 'react';
>>>>>>> REPLACE
<<<<<<< SEARCH
function handleSubmit() {
saveData();
setLoading(false);
}
=======
>>>>>>> REPLACE
<<<<<<< SEARCH
return (
<div>
=======
function handleSubmit() {
saveData();
setLoading(false);
}
return (
<div>
>>>>>>> REPLACE
</diff>
</replace_in_file>
- execute_command: Executes CLI commands
Example:
<execute_command>
<command>npm run dev</command>
</execute_command>
Example:
<execute_command>
<command>npm install axios</command>
<requires_approval>false</requires_approval>
</execute_command>
- use_mcp_tool: Requesting to use an MCP tool; make calls remote tools from MCP servers
Example:
<use_mcp_tool>
<server_name>weather-server</server_name>
<tool_name>get_forecast</tool_name>
<arguments>
{"city": "San Francisco", "days": 5}
</arguments>
</use_mcp_tool>
Example:
<use_mcp_tool>
<server_name>github.com/modelcontextprotocol/servers/tree/main/src/github</server_name>
<tool_name>create_issue</tool_name>
<arguments>
{
"owner": "octocat",
"repo": "hello-world",
"title": "Found a bug",
"body": "I'm having a problem with this.",
"labels": ["bug", "help wanted"],
"assignees": ["octocat"]
}
</arguments>
</use_mcp_tool>
- access_mcp_resource: Access MCP server resources
Example:
<access_mcp_resource>
<server_name>server name here</server_name>
<uri>resource URI here</uri>
</access_mcp_resource>
- ask_followup_question: Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
Example:
<ask_followup_question>
<question>Your question here</question>
<options>
Array of options here (optional), e.g. ["Option 1", "Option 2", "Option 3"]
</options>
</ask_followup_question>
- attempt_completion: Indicates that the task is complete and no further action is needed. This should be used when you believe the task has been successfully accomplished, and you are ready to finalise the interaction.
<attempt_completion>
<result>
Your final result description here
</result>
<command>
Command to demonstrate result (optional)
</command>
</attempt_completion>
7. Tool Use Guidelines
1. In <thinking> tags, assess what information you already have and what information you need to proceed with the task.
2. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task.
3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. Each step must be informed by the previous step's result.
4. Formulate your tool use using the XML format specified for each tool.
5. After each tool use, the user will respond with the result of that tool use. This result will provide you with the necessary information to continue your task or make further decisions. This response may include:
- Information about whether the tool succeeded or failed, along with any reasons for failure.
- Linter errors that may have arisen due to the changes you made, which you'll need to address.
- New terminal output in reaction to the changes, which you may need to consider or act upon.
- Any other relevant feedback or information related to the tool use.
6. ALWAYS wait for user confirmation after each tool use before proceeding. Never assume the success of a tool use without explicit confirmation of the result from the user.
It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task. This approach allows you to:
1. Confirm the success of each step before proceeding.
2. Address any issues or errors that arise immediately.
3. Adapt your approach based on new information or unexpected results.
4. Ensure that each action builds correctly on the previous ones.
By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work.
8. Code Quality
- You MUST ensure that the code is clean, well-structured, and adheres to best practices.
- You MUST avoid unnecessary complexity and strive for simplicity in your solutions.
- You MUST use meaningful variable names and follow consistent naming conventions.
- You MUST include comments where necessary to explain complex logic or decisions.
- You MUST ensure that the code is modular and reusable, avoiding duplication where possible.
- You MUST follow the DRY (Don't Repeat Yourself) principle and avoid code duplication.
- You MUST ensure that the code is efficient and performs well, avoiding unnecessary computations or resource usage.
- You MUST ensure that the code is maintainable and easy to understand for future developers.
- You MUST ensure that the code is well-documented, including function and class docstrings.
- You MUST ensure that the code is compatible with the target environment and follows any relevant guidelines or standards.
8. Testing
- You MUST ensure that the code you write has approrpiate unit tests and all tests when you have completed your task.
9. Communication Guidelines
- IMPORTANT: BE CONCISE AND AVOID VERBOSITY. BREVITY IS CRITICAL.
- Minimise output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand.
- Be conversational but professional.
- Refer to the USER in the second person and yourself in the first person.
- Format your responses in markdown. Use backticks to format file, directory, function, and class names. Use \( and \) for inline math, \[ and \] for block math.
- NEVER lie or make things up.
- Refrain from apologising all the time when results are unexpected. Instead, just try your best to proceed or explain the circumstances to the user without apologising.
"""
# Ollama SHA eb4402837c78
TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""
# Nothink template
# TEMPLATE """{{- if .Messages }}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- range $i, $_ := .Messages }}
# {{- $last := eq (len (slice $.Messages $i)) 1 -}}
# {{- if eq .Role "user" }}<|im_start|>user
# {{ .Content }}<|im_end|>
# {{ else if eq .Role "assistant" }}<|im_start|>assistant
# {{ if .Content }}{{ .Content }}
# {{- else if .ToolCalls }}<tool_call>
# {{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
# {{ end }}</tool_call>
# {{- end }}{{ if not $last }}<|im_end|>
# {{ end }}
# {{- else if eq .Role "tool" }}<|im_start|>user
# <tool_response>
# {{ .Content }}
# </tool_response><|im_end|>
# {{ end }}
# {{- if and (ne .Role "assistant") $last }}<|im_start|>assistant\n<think>\n\n</think>\n\n
# {{ end }}
# {{- end }}
# {{- else }}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{ end }}{{ if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{ end }}<|im_start|>assistant
# {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
PARAMETER stop "</thinking>"
PARAMETER stop "</tool_call>"
PARAMETER stop "</tool_response>"
PARAMETER stop "</write_to_file>"
PARAMETER stop "</execute_command>"
### Tuning ##
# https://docs.unsloth.ai/basics/qwen3-how-to-run-and-fine-tune
PARAMETER num_ctx 65536
# PARAMETER num_predict 16384
# PARAMETER num_keep 1024
# PARAMETER num_ctx 131072
# PARAMETER num_predict 131072
# For Q2_K_XL:
# PARAMETER num_batch 256
# PARAMETER num_ctx 32768
PARAMETER num_gpu 99
PARAMETER temperature 0.6
PARAMETER top_k 20
PARAMETER repeat_penalty 1.1
PARAMETER top_p 0.9
PARAMETER min_p 0.0
# PARAMETER num_keep 256
### min_p sampling ##
# min_p works best with a bit of temperature
# PARAMETER temperature 0.2
# # 1.0 disables top_p, so we can use min_p
# PARAMETER top_p 1.0
# PARAMETER min_p 0.05
### min_p sampling ##
# MOAR SPEEEED
# PARAMETER num_batch 1024
# 64 fits RYS-XLarge-72b IQ4_XS at 21k
# PARAMETER num_batch 64
## For codegen ##
# PARAMETER num_keep 512
# PARAMETER num_keep 1024
# PARAMETER top_p 0.9 # default
# PARAMETER top_k 20 # default
# PARAMETER repetition_penalty 1.05 # default
# PARAMETER presence_penalty 0.2
# PARAMETER frequency_penalty 0.2
# PARAMETER repeat_last_n 50
#########
# This is because some template functions aren't available in the basic go string templating language.
# Can't use:
# function "sub"
# function "contains"
# function "subtract"
# function "split"
# v4 (works)
# TEMPLATE """
# {{- if .Messages }}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- range $i, $msg := .Messages }}
# {{- if eq $msg.Role "user" }}<|im_start|>user
# {{ $msg.Content }}<|im_end|>
# {{ else if eq $msg.Role "assistant" }}<|im_start|>assistant
# {{ if $msg.Content }}{{ $msg.Content }}{{ end }}
# {{- if $msg.ToolCalls }}
# {{- range $toolCall := $msg.ToolCalls }}
# <tool_call>
# {"name": "{{ $toolCall.Function.Name }}", "arguments": {{ $toolCall.Function.Arguments }}}
# </tool_call>
# {{- end }}
# {{- end }}<|im_end|>
# {{ else if eq $msg.Role "tool" }}<|im_start|>user
# <tool_response>
# {{ $msg.Content }}
# </tool_response><|im_end|>
# {{ end }}
# {{- end }}
# {{- else }}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{ end }}{{ if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{ end }}<|im_start|>assistant
# {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}
# """
# v6 (works but if you add im_start it cuts off early)
# TEMPLATE """
# {{- if .Messages }}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- range $i, $msg := .Messages }}
# {{- if eq $msg.Role "user" }}<|im_start|>user
# {{ $msg.Content }}<|im_end|>
# {{ else if eq $msg.Role "assistant" }}<|im_start|>assistant
# {{ $msg.Content }}
# {{- if $msg.ToolCalls }}
# {{- range $toolCall := $msg.ToolCalls }}
# <tool_call>
# {"name": "{{ $toolCall.Function.Name }}", "arguments": {{ $toolCall.Function.Arguments }}}
# </tool_call>
# {{- end }}
# {{- end }}<|im_end|>
# {{ else if eq $msg.Role "tool" }}<|im_start|>user
# <tool_response>
# {{ $msg.Content }}
# </tool_response><|im_end|>
# {{ end }}
# {{- end }}
# {{- else }}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{ end }}{{ if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{ end }}<|im_start|>assistant
# {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}
# """
# v8 (works but if you add im_start it cuts off early)
# TEMPLATE """
# {{- if .Messages }}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- /* Process all messages in order */ -}}
# {{- range $i, $msg := .Messages }}
# {{- if eq $msg.Role "user" }}<|im_start|>user
# {{ $msg.Content }}<|im_end|>
# {{ else if eq $msg.Role "assistant" }}<|im_start|>assistant
# {{- /* Handle content and tool calls */ -}}
# {{ $msg.Content }}
# {{- if $msg.ToolCalls }}
# {{- range $toolCall := $msg.ToolCalls }}
# <tool_call>
# {"name": "{{ $toolCall.Function.Name }}", "arguments": {{ $toolCall.Function.Arguments }}}
# </tool_call>
# {{- end }}
# {{- end }}<|im_end|>
# {{ else if eq $msg.Role "tool" }}<|im_start|>user
# <tool_response>
# {{ $msg.Content }}
# </tool_response><|im_end|>
# {{ end }}
# {{- end }}
# {{- else }}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{ end }}{{ if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{ end }}<|im_start|>assistant
# {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}
# """
# v9 (works but if you add im_start it cuts off early)
# TEMPLATE """
# {{- if .Messages }}
# {{- /* Handle system message and tools */ -}}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- /* Process all messages in order */ -}}
# {{- range $i, $msg := .Messages }}
# {{- /* Handle user messages */ -}}
# {{- if eq $msg.Role "user" }}<|im_start|>user
# {{ $msg.Content }}<|im_end|>
# {{- /* Handle assistant messages */ -}}
# {{- else if eq $msg.Role "assistant" }}<|im_start|>assistant
# {{- /* Simply output the content as is - this will preserve think tags if present */ -}}
# {{ $msg.Content }}
# {{- /* Handle tool calls */ -}}
# {{- if $msg.ToolCalls }}
# {{- range $toolCall := $msg.ToolCalls }}
# <tool_call>
# {"name": "{{ $toolCall.Function.Name }}", "arguments": {{ $toolCall.Function.Arguments }}}
# </tool_call>
# {{- end }}
# {{- end }}<|im_end|>
# {{- /* Handle tool messages - simplified approach */ -}}
# {{- else if eq $msg.Role "tool" }}<|im_start|>user
# <tool_response>
# {{ $msg.Content }}
# </tool_response><|im_end|>
# {{- end }}
# {{- end }}
# {{- else }}
# {{- /* Handle .System and .Prompt without messages */ -}}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{- end }}
# {{- if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{- end }}<|im_start|>assistant
# {{- end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}
# """
# Qwen 2.5 Template (which is what Ollama is using as of 2025-04-29)
# TEMPLATE """{{- if .Messages }}
# {{- if or .System .Tools }}<|im_start|>system
# {{- if .System }}
# {{ .System }}
# {{- end }}
# {{- if .Tools }}
# # Tools
# You may call one or more functions to assist with the user query.
# You are provided with function signatures within <tools></tools> XML tags:
# <tools>
# {{- range .Tools }}
# {"type": "function", "function": {{ .Function }}}
# {{- end }}
# </tools>
# For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
# <tool_call>
# {"name": <function-name>, "arguments": <args-json-object>}
# </tool_call>
# {{- end }}<|im_end|>
# {{ end }}
# {{- range $i, $_ := .Messages }}
# {{- $last := eq (len (slice $.Messages $i)) 1 -}}
# {{- if eq .Role "user" }}<|im_start|>user
# {{ .Content }}<|im_end|>
# {{ else if eq .Role "assistant" }}<|im_start|>assistant
# {{ if .Content }}{{ .Content }}
# {{- else if .ToolCalls }}<tool_call>
# {{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
# {{ end }}</tool_call>
# {{- end }}{{ if not $last }}<|im_end|>
# {{ end }}
# {{- else if eq .Role "tool" }}<|im_start|>user
# <tool_response>
# {{ .Content }}
# </tool_response><|im_end|>
# {{ end }}
# {{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
# {{ end }}
# {{- end }}
# {{- else }}
# {{- if .System }}<|im_start|>system
# {{ .System }}<|im_end|>
# {{ end }}{{ if .Prompt }}<|im_start|>user
# {{ .Prompt }}<|im_end|>
# {{ end }}<|im_start|>assistant
# {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""