mjolnir-cli 0.2.0__py3-none-any.whl

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.
Files changed (80) hide show
  1. mjolnir_cli/__init__.py +8 -0
  2. mjolnir_cli/__main__.py +4 -0
  3. mjolnir_cli/accuracy.py +333 -0
  4. mjolnir_cli/autoresearch.py +539 -0
  5. mjolnir_cli/benchy.py +475 -0
  6. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4/config.yaml +78 -0
  7. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_DFLASH2/config.yaml +103 -0
  8. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_DSPARK/config.yaml +102 -0
  9. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_FA2/config.yaml +84 -0
  10. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_FA4hd256/config.yaml +104 -0
  11. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR/config.yaml +86 -0
  12. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3/config.yaml +93 -0
  13. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_DFLASH2/config.yaml +123 -0
  14. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_DSPARK/config.yaml +124 -0
  15. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8/.env +2 -0
  16. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8/config.yaml +98 -0
  17. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8_VT32K/.env +4 -0
  18. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8_VT32K/config.yaml +98 -0
  19. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8_VT64K/.env +4 -0
  20. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_LMH8_VT64K/config.yaml +102 -0
  21. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_VT32K/.env +3 -0
  22. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/NVFP4_MJOLNIR_E2M3_VT32K/config.yaml +98 -0
  23. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/draft_vocab.json +1 -0
  24. mjolnir_cli/bundled/configs/Qwen/Qwen3.8-27B/kv_scales.json +35197 -0
  25. mjolnir_cli/bundled/configs/Qwen/Qwen3.8_chat_template.jinja +456 -0
  26. mjolnir_cli/bundled/docker/litellm/docker-compose.yaml +113 -0
  27. mjolnir_cli/bundled/docker/litellm/litellm.env.example +51 -0
  28. mjolnir_cli/bundled/docker/litellm/litellm_config.template.example.yaml +192 -0
  29. mjolnir_cli/bundled/docker/perses/README.md +89 -0
  30. mjolnir_cli/bundled/docker/perses/dashboards/global-datasource.yaml +17 -0
  31. mjolnir_cli/bundled/docker/perses/dashboards/performance_statistics.yaml +771 -0
  32. mjolnir_cli/bundled/docker/perses/dashboards/project.yaml +13 -0
  33. mjolnir_cli/bundled/docker/perses/dashboards/query_statistics.yaml +399 -0
  34. mjolnir_cli/bundled/docker/perses/docker-compose.yaml +51 -0
  35. mjolnir_cli/bundled/docker/perses/perses.yml +16 -0
  36. mjolnir_cli/bundled/docker/perses/prometheus.template.yaml +20 -0
  37. mjolnir_cli/bundled/scripts/hw/setup-thor.sh +1287 -0
  38. mjolnir_cli/cachectl.py +146 -0
  39. mjolnir_cli/charts.py +1687 -0
  40. mjolnir_cli/cli.py +1480 -0
  41. mjolnir_cli/clidoc.py +170 -0
  42. mjolnir_cli/config.py +346 -0
  43. mjolnir_cli/dockerctl.py +533 -0
  44. mjolnir_cli/drivers/fa2_driver.py +89 -0
  45. mjolnir_cli/drivers/fi_driver.py +134 -0
  46. mjolnir_cli/e2e.py +302 -0
  47. mjolnir_cli/fonts/InterDisplay-Bold.ttf +0 -0
  48. mjolnir_cli/fonts/InterDisplay-Medium.ttf +0 -0
  49. mjolnir_cli/fonts/InterDisplay-Regular.ttf +0 -0
  50. mjolnir_cli/fonts/InterDisplay-SemiBold.ttf +0 -0
  51. mjolnir_cli/fonts/OFL.txt +92 -0
  52. mjolnir_cli/gate.py +233 -0
  53. mjolnir_cli/history.py +159 -0
  54. mjolnir_cli/interactive.py +383 -0
  55. mjolnir_cli/legs.py +109 -0
  56. mjolnir_cli/litellm.py +254 -0
  57. mjolnir_cli/perses.py +214 -0
  58. mjolnir_cli/picker.py +70 -0
  59. mjolnir_cli/readme.py +1020 -0
  60. mjolnir_cli/stack.py +340 -0
  61. mjolnir_cli/tasks.py +122 -0
  62. mjolnir_cli/theme.py +281 -0
  63. mjolnir_cli/thor.py +108 -0
  64. mjolnir_cli/verify/__init__.py +2 -0
  65. mjolnir_cli/verify/cli.py +816 -0
  66. mjolnir_cli/verify/docker.py +334 -0
  67. mjolnir_cli/verify/kvcache.py +180 -0
  68. mjolnir_cli/verify/legs.py +134 -0
  69. mjolnir_cli/verify/ncu.py +141 -0
  70. mjolnir_cli/verify/profile.py +312 -0
  71. mjolnir_cli/verify/report.py +177 -0
  72. mjolnir_cli/verify/results.py +157 -0
  73. mjolnir_cli/verify/spec.py +279 -0
  74. mjolnir_cli/verify/stages.py +817 -0
  75. mjolnir_cli-0.2.0.dist-info/METADATA +87 -0
  76. mjolnir_cli-0.2.0.dist-info/RECORD +80 -0
  77. mjolnir_cli-0.2.0.dist-info/WHEEL +4 -0
  78. mjolnir_cli-0.2.0.dist-info/entry_points.txt +2 -0
  79. mjolnir_cli-0.2.0.dist-info/licenses/LICENSE +202 -0
  80. mjolnir_cli-0.2.0.dist-info/licenses/NOTICE +64 -0
@@ -0,0 +1,456 @@
1
+ {%- set template_version = "qwen3.8-froggeric-v22.5" %}
2
+ {%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
3
+ {%- set image_count = namespace(value=0) %}
4
+ {%- set video_count = namespace(value=0) %}
5
+ {%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}
6
+ {%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
7
+ {%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}
8
+ {%- if preserve_reasoning is defined and preserve_reasoning is not none %}
9
+ {%- set _preserve_thinking = preserve_reasoning %}
10
+ {%- elif preserve_thinking is defined and preserve_thinking is not none %}
11
+ {%- set _preserve_thinking = preserve_thinking %}
12
+ {%- else %}
13
+ {%- set _preserve_thinking = true %}
14
+ {%- endif %}
15
+ {%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}
16
+ {%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}
17
+ {%- set _default_reasoning_effort = 'medium' %}
18
+ {%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
19
+ {%- set _effort_raw = (reasoning_effort | string | lower) if reasoning_effort is defined and reasoning_effort is not none else _default_reasoning_effort %}
20
+ {%- set _initial_thinking = enable_thinking %}
21
+ {%- if _effort_raw in ('none', 'off') %}
22
+ {%- set _initial_thinking = false %}
23
+ {%- set _initial_effort = 'medium' %}
24
+ {%- elif _effort_raw in ('minimal', 'low') %}
25
+ {%- set _initial_effort = 'low' %}
26
+ {%- elif _effort_raw in ('high', 'xhigh', 'max', 'ultracode', 'extreme') %}
27
+ {%- set _initial_effort = 'xhigh' %}
28
+ {%- else %}
29
+ {%- set _initial_effort = 'medium' %}
30
+ {%- endif %}
31
+ {%- set ns_state = namespace(thinking=_initial_thinking, effort=_initial_effort) %}
32
+ {%- if auto_disable_thinking_with_tools and _has_tools %}
33
+ {%- set ns_state.thinking = false %}
34
+ {%- endif %}
35
+ {%- for msg in messages %}
36
+ {%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}
37
+ {%- if msg.content is string %}
38
+ {%- if '<|think_off|>' in msg.content %}
39
+ {%- set ns_state.thinking = false %}
40
+ {%- elif '<|think_on|>' in msg.content %}
41
+ {%- set ns_state.thinking = true %}
42
+ {%- elif '<|think_xhigh|>' in msg.content or '<|think_high|>' in msg.content or '<|think_ultracode|>' in msg.content or '<|think_extreme|>' in msg.content or '<|think_max|>' in msg.content %}
43
+ {%- set ns_state.thinking = true %}
44
+ {%- set ns_state.effort = 'xhigh' %}
45
+ {%- elif '<|think_low|>' in msg.content or '<|think_minimal|>' in msg.content %}
46
+ {%- set ns_state.thinking = true %}
47
+ {%- set ns_state.effort = 'low' %}
48
+ {%- elif '<|think_medium|>' in msg.content %}
49
+ {%- set ns_state.thinking = true %}
50
+ {%- set ns_state.effort = 'medium' %}
51
+ {%- endif %}
52
+ {%- elif msg.content is iterable and msg.content is not mapping %}
53
+ {%- for item in msg.content %}
54
+ {%- if item is string %}
55
+ {%- set _item_text = item %}
56
+ {%- elif item is mapping and 'text' in item and item.text is string %}
57
+ {%- set _item_text = item.text %}
58
+ {%- else %}
59
+ {%- set _item_text = '' %}
60
+ {%- endif %}
61
+ {%- if _item_text %}
62
+ {%- if '<|think_off|>' in _item_text %}
63
+ {%- set ns_state.thinking = false %}
64
+ {%- elif '<|think_on|>' in _item_text %}
65
+ {%- set ns_state.thinking = true %}
66
+ {%- elif '<|think_xhigh|>' in _item_text or '<|think_high|>' in _item_text or '<|think_ultracode|>' in _item_text or '<|think_extreme|>' in _item_text or '<|think_max|>' in _item_text %}
67
+ {%- set ns_state.thinking = true %}
68
+ {%- set ns_state.effort = 'xhigh' %}
69
+ {%- elif '<|think_low|>' in _item_text or '<|think_minimal|>' in _item_text %}
70
+ {%- set ns_state.thinking = true %}
71
+ {%- set ns_state.effort = 'low' %}
72
+ {%- elif '<|think_medium|>' in _item_text %}
73
+ {%- set ns_state.thinking = true %}
74
+ {%- set ns_state.effort = 'medium' %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- endif %}
79
+ {%- endif %}
80
+ {%- endfor %}
81
+ {%- set reasoning_instructions = '' %}
82
+ {%- if ns_state.thinking %}
83
+ {%- if ns_state.effort == 'xhigh' %}
84
+ {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
85
+ {%- elif ns_state.effort == 'low' %}
86
+ {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
87
+ {%- endif %}
88
+ {%- endif %}
89
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
90
+ {%- if content is string %}
91
+ {{- content }}
92
+ {%- elif content is iterable and content is not mapping %}
93
+ {%- for item in content %}
94
+ {%- if item is mapping %}
95
+ {%- if item.type == 'image' or 'image' in item or 'image_url' in item %}
96
+ {%- if is_system_content %}
97
+ {{- raise_exception('System message cannot contain images.') }}
98
+ {%- endif %}
99
+ {%- if do_vision_count %}
100
+ {%- set image_count.value = image_count.value + 1 %}
101
+ {%- endif %}
102
+ {%- if add_vision_id %}
103
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
104
+ {%- endif %}
105
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
106
+ {%- elif item.type == 'video' or 'video' in item or 'video_url' in item %}
107
+ {%- if is_system_content %}
108
+ {{- raise_exception('System message cannot contain videos.') }}
109
+ {%- endif %}
110
+ {%- if do_vision_count %}
111
+ {%- set video_count.value = video_count.value + 1 %}
112
+ {%- endif %}
113
+ {%- if add_vision_id %}
114
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
115
+ {%- endif %}
116
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
117
+ {%- elif 'text' in item %}
118
+ {{- item.text }}
119
+ {%- else %}
120
+ {{- raise_exception('Unexpected item type in content.') }}
121
+ {%- endif %}
122
+ {%- else %}
123
+ {{- item | string }}
124
+ {%- endif %}
125
+ {%- endfor %}
126
+ {%- elif content is none or content is undefined %}
127
+ {{- '' }}
128
+ {%- else %}
129
+ {{- raise_exception('Unexpected content type.') }}
130
+ {%- endif %}
131
+ {%- endmacro %}
132
+ {%- if not messages %}
133
+ {{- raise_exception('No messages provided.') }}
134
+ {%- endif %}
135
+ {%- set head = namespace(count=0, seen_non_system=false) %}
136
+ {%- for message in messages %}
137
+ {%- set _is_sys = (message.role == 'system' or message.role == 'developer') %}
138
+ {%- if _is_sys and not head.seen_non_system %}
139
+ {%- set head.count = head.count + 1 %}
140
+ {%- else %}
141
+ {%- set head.seen_non_system = true %}
142
+ {%- endif %}
143
+ {%- endfor %}
144
+ {%- set sys_state = namespace(content='') %}
145
+ {%- for message in messages[:head.count] %}
146
+ {%- set _part = render_content(message.content, false, true) | trim %}
147
+ {%- if '<|think_off|>' in _part %}{%- set _part = _part.split('<|think_off|>') | join('') | trim %}{%- endif %}
148
+ {%- if '<|think_on|>' in _part %}{%- set _part = _part.split('<|think_on|>') | join('') | trim %}{%- endif %}
149
+ {%- if '<|think_xhigh|>' in _part %}{%- set _part = _part.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}
150
+ {%- if '<|think_high|>' in _part %}{%- set _part = _part.split('<|think_high|>') | join('') | trim %}{%- endif %}
151
+ {%- if '<|think_ultracode|>' in _part %}{%- set _part = _part.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}
152
+ {%- if '<|think_extreme|>' in _part %}{%- set _part = _part.split('<|think_extreme|>') | join('') | trim %}{%- endif %}
153
+ {%- if '<|think_max|>' in _part %}{%- set _part = _part.split('<|think_max|>') | join('') | trim %}{%- endif %}
154
+ {%- if '<|think_medium|>' in _part %}{%- set _part = _part.split('<|think_medium|>') | join('') | trim %}{%- endif %}
155
+ {%- if '<|think_low|>' in _part %}{%- set _part = _part.split('<|think_low|>') | join('') | trim %}{%- endif %}
156
+ {%- if '<|think_minimal|>' in _part %}{%- set _part = _part.split('<|think_minimal|>') | join('') | trim %}{%- endif %}
157
+ {%- if _part %}
158
+ {%- if sys_state.content %}
159
+ {%- set sys_state.content = sys_state.content ~ '\n\n' ~ _part %}
160
+ {%- else %}
161
+ {%- set sys_state.content = _part %}
162
+ {%- endif %}
163
+ {%- endif %}
164
+ {%- endfor %}
165
+ {%- set _sc = sys_state.content %}
166
+ {%- set _msgs = messages[head.count:] %}
167
+ {%- if _has_tools %}
168
+ {{- '<|im_start|>system\n' }}
169
+ {%- if reasoning_instructions %}
170
+ {{- reasoning_instructions + '\n\n' }}
171
+ {%- endif %}
172
+ {{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}
173
+ {%- for tool in tools %}
174
+ {{- '\n' }}
175
+ {{- tool | tojson }}
176
+ {%- endfor %}
177
+ {{- '\n</tools>' }}
178
+ {%- if _tool_format == 'json' %}
179
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}
180
+ {%- if ns_state.thinking %}
181
+ {{- '<think>\nBrief explanation of tool call\n</think>\n' }}
182
+ {%- endif %}
183
+ {{- '<tool_call>\n{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}\n</tool_call>\n\n<IMPORTANT>\nReminder:\n' }}
184
+ {%- if ns_state.thinking %}
185
+ {{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n' }}
186
+ {%- endif %}
187
+ {{- '- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.\n' }}
188
+ {%- if ns_state.thinking %}
189
+ {{- '- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n' }}
190
+ {%- else %}
191
+ {{- '- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY, with NO conversational text before it.\n' }}
192
+ {%- endif %}
193
+ {{- '- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
194
+ {%- else %}
195
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n' }}
196
+ {%- if ns_state.thinking %}
197
+ {{- '<think>\nBrief explanation of tool call\n</think>\n' }}
198
+ {%- endif %}
199
+ {{- '<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' }}
200
+ {%- if ns_state.thinking %}
201
+ {{- '- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n' }}
202
+ {%- endif %}
203
+ {{- '- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\n' }}
204
+ {%- if ns_state.thinking %}
205
+ {{- '- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n' }}
206
+ {%- else %}
207
+ {{- '- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY, with NO conversational text before it.\n' }}
208
+ {%- endif %}
209
+ {{- '- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
210
+ {%- endif %}
211
+ {%- if _sc %}
212
+ {{- '\n\n' + _sc }}
213
+ {%- endif %}
214
+ {{- '<|im_end|>\n' }}
215
+ {%- else %}
216
+ {%- if _sc %}
217
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + _sc + '<|im_end|>\n' }}
218
+ {%- elif reasoning_instructions %}
219
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
220
+ {%- endif %}
221
+ {%- endif %}
222
+ {%- set _last_idx = _msgs | length - 1 %}
223
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}
224
+ {%- for message in _msgs[::-1] %}
225
+ {%- set index = (_msgs | length - 1) - loop.index0 %}
226
+ {%- if ns.multi_step_tool and message.role == 'user' %}
227
+ {%- set _rc = render_content(message.content, false) | trim %}
228
+ {%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}
229
+ {%- set ns.multi_step_tool = false %}
230
+ {%- set ns.last_query_index = index %}
231
+ {%- endif %}
232
+ {%- endif %}
233
+ {%- endfor %}
234
+ {%- if ns.multi_step_tool %}
235
+ {%- if _last_idx > 50 %}
236
+ {%- set ns.last_query_index = _last_idx %}
237
+ {%- else %}
238
+ {%- set ns.last_query_index = 0 %}
239
+ {%- endif %}
240
+ {%- endif %}
241
+ {%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}
242
+ {%- for message in _msgs %}
243
+ {%- set is_system = (message.role == "system" or message.role == "developer") %}
244
+ {%- set content = render_content(message.content, true, is_system) | trim %}
245
+ {%- if is_system or message.role == 'user' %}
246
+ {%- if '<|think_off|>' in content %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- endif %}
247
+ {%- if '<|think_on|>' in content %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}
248
+ {%- if '<|think_xhigh|>' in content %}{%- set content = content.split('<|think_xhigh|>') | join('') | trim %}{%- endif %}
249
+ {%- if '<|think_high|>' in content %}{%- set content = content.split('<|think_high|>') | join('') | trim %}{%- endif %}
250
+ {%- if '<|think_ultracode|>' in content %}{%- set content = content.split('<|think_ultracode|>') | join('') | trim %}{%- endif %}
251
+ {%- if '<|think_extreme|>' in content %}{%- set content = content.split('<|think_extreme|>') | join('') | trim %}{%- endif %}
252
+ {%- if '<|think_max|>' in content %}{%- set content = content.split('<|think_max|>') | join('') | trim %}{%- endif %}
253
+ {%- if '<|think_medium|>' in content %}{%- set content = content.split('<|think_medium|>') | join('') | trim %}{%- endif %}
254
+ {%- if '<|think_low|>' in content %}{%- set content = content.split('<|think_low|>') | join('') | trim %}{%- endif %}
255
+ {%- if '<|think_minimal|>' in content %}{%- set content = content.split('<|think_minimal|>') | join('') | trim %}{%- endif %}
256
+ {%- endif %}
257
+ {%- if is_system %}
258
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
259
+ {%- elif message.role == 'user' %}
260
+ {%- set ns2.consecutive_failures = 0 %}
261
+ {{- '<|im_start|>user\n' + content + '<|im_end|>\n' }}
262
+ {%- elif message.role == 'assistant' %}
263
+ {%- set reasoning_content = '' %}
264
+ {%- set _explicit_reasoning = '' %}
265
+ {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
266
+ {%- if message.reasoning_content is string %}
267
+ {%- set _explicit_reasoning = message.reasoning_content %}
268
+ {%- else %}
269
+ {%- set _explicit_reasoning = message.reasoning_content | string %}
270
+ {%- endif %}
271
+ {%- elif message.thinking is defined and message.thinking is not none %}
272
+ {%- if message.thinking is string %}
273
+ {%- set _explicit_reasoning = message.thinking %}
274
+ {%- else %}
275
+ {%- set _explicit_reasoning = message.thinking | string %}
276
+ {%- endif %}
277
+ {%- elif message.reasoning is defined and message.reasoning is not none %}
278
+ {%- if message.reasoning is string %}
279
+ {%- set _explicit_reasoning = message.reasoning %}
280
+ {%- else %}
281
+ {%- set _explicit_reasoning = message.reasoning | string %}
282
+ {%- endif %}
283
+ {%- endif %}
284
+ {%- if _explicit_reasoning %}
285
+ {%- set _lead_end = '' %}
286
+ {%- if content.startswith('<think>') and '</think>' in content %}
287
+ {%- set _lead_end = '</think>' %}
288
+ {%- elif content.startswith('<thinking>') and '</thinking>' in content %}
289
+ {%- set _lead_end = '</thinking>' %}
290
+ {%- elif content.startswith('</think>') %}
291
+ {%- set _lead_end = '</think>' %}
292
+ {%- elif content.startswith('</thinking>') %}
293
+ {%- set _lead_end = '</thinking>' %}
294
+ {%- endif %}
295
+ {%- if _lead_end %}
296
+ {%- set content = content.split(_lead_end)[-1].lstrip('\n') %}
297
+ {%- endif %}
298
+ {%- set reasoning_content = _explicit_reasoning %}
299
+ {%- else %}
300
+ {%- set _think_end = '' %}
301
+ {%- if content.startswith('</think>') %}
302
+ {%- set _think_end = '</think>' %}
303
+ {%- elif content.startswith('</thinking>') %}
304
+ {%- set _think_end = '</thinking>' %}
305
+ {%- elif '\n</think>' in content %}
306
+ {%- set _think_end = '\n</think>' %}
307
+ {%- elif '\n</thinking>' in content %}
308
+ {%- set _think_end = '\n</thinking>' %}
309
+ {%- elif '\n</ think>' in content %}
310
+ {%- set _think_end = '\n</ think>' %}
311
+ {%- elif '\n</think >' in content %}
312
+ {%- set _think_end = '\n</think >' %}
313
+ {%- elif content.startswith('<think>') and '</think>' in content %}
314
+ {%- set _think_end = '</think>' %}
315
+ {%- elif content.startswith('<thinking>') and '</thinking>' in content %}
316
+ {%- set _think_end = '</thinking>' %}
317
+ {%- endif %}
318
+ {%- if _think_end %}
319
+ {%- if 'thinking' in _think_end %}
320
+ {%- set _think_start = '<thinking>' %}
321
+ {%- else %}
322
+ {%- set _think_start = '<think>' %}
323
+ {%- endif %}
324
+ {%- set reasoning_content = content.split(_think_end)[0].rstrip('\n') %}
325
+ {%- if _think_start in reasoning_content %}
326
+ {%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\n') %}
327
+ {%- endif %}
328
+ {%- set content = content.split(_think_end)[-1].lstrip('\n') %}
329
+ {%- endif %}
330
+ {%- endif %}
331
+ {%- set reasoning_content = reasoning_content | trim %}
332
+ {{- '<|im_start|>assistant\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
333
+ {%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
334
+ {%- for tool_call in message.tool_calls %}
335
+ {%- if tool_call.function is defined and tool_call.function is not none %}
336
+ {%- set tc = tool_call.function %}
337
+ {%- else %}
338
+ {%- set tc = tool_call %}
339
+ {%- endif %}
340
+ {%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}
341
+ {%- if _tool_format == 'json' %}
342
+ {%- if loop.first %}
343
+ {%- if content | trim %}
344
+ {{- '\n\n' }}
345
+ {%- endif %}
346
+ {%- else %}
347
+ {{- '\n' }}
348
+ {%- endif %}
349
+ {%- set _args = '{}' %}
350
+ {%- if tc.arguments is defined and tc.arguments is not none %}
351
+ {%- if tc.arguments is mapping %}
352
+ {%- set _args = tc.arguments | tojson %}
353
+ {%- elif tc.arguments is string %}
354
+ {%- if tc.arguments %}
355
+ {%- set _args = tc.arguments %}
356
+ {%- endif %}
357
+ {%- else %}
358
+ {%- set _args = tc.arguments | tojson %}
359
+ {%- endif %}
360
+ {%- endif %}
361
+ {{- '<tool_call>\n{"name": ' }}{{- tc_name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}
362
+ {%- else %}
363
+ {%- if loop.first %}
364
+ {%- if content | trim %}
365
+ {{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}
366
+ {%- else %}
367
+ {{- '<tool_call>\n<function=' + tc_name + '>\n' }}
368
+ {%- endif %}
369
+ {%- else %}
370
+ {{- '\n<tool_call>\n<function=' + tc_name + '>\n' }}
371
+ {%- endif %}
372
+ {%- if tc.arguments is defined and tc.arguments is not none %}
373
+ {%- if tc.arguments is mapping %}
374
+ {%- for args_name, args_value in tc.arguments.items() %}
375
+ {{- '<parameter=' + args_name + '>\n' }}
376
+ {%- if args_value is string %}
377
+ {%- set _av = args_value %}
378
+ {%- else %}
379
+ {%- set _av = args_value | tojson %}
380
+ {%- endif %}
381
+ {%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}
382
+ {{- _av[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_av | length | string) ~ ' chars]' }}
383
+ {%- else %}
384
+ {{- _av }}
385
+ {%- endif %}
386
+ {{- '\n</parameter>\n' }}
387
+ {%- endfor %}
388
+ {%- else %}
389
+ {%- if tc.arguments is string %}
390
+ {%- set _raw_args = tc.arguments %}
391
+ {%- else %}
392
+ {%- set _raw_args = tc.arguments | tojson %}
393
+ {%- endif %}
394
+ {%- if _raw_args %}
395
+ {%- if max_tool_arg_chars > 0 and _raw_args | length > max_tool_arg_chars %}
396
+ {{- _raw_args[:max_tool_arg_chars] + '\n[TRUNCATED - original length ' ~ (_raw_args | length | string) ~ ' chars]' }}
397
+ {%- else %}
398
+ {{- _raw_args }}
399
+ {%- endif %}
400
+ {%- endif %}
401
+ {%- endif %}
402
+ {%- endif %}
403
+ {{- '</function>\n</tool_call>' }}
404
+ {%- endif %}
405
+ {%- endfor %}
406
+ {%- endif %}
407
+ {{- '<|im_end|>\n' }}
408
+ {%- elif message.role == 'tool' %}
409
+ {%- set _content_lower = content | lower %}
410
+ {%- set _content_head = _content_lower[:120] %}
411
+ {%- set _is_code_or_grep = ('throw new ' in _content_lower or 'throw error' in _content_lower or 'console.error' in _content_lower or 'logger.error' in _content_lower or 'logging.error' in _content_lower or 'import ' in _content_head or 'def ' in _content_head or 'function ' in _content_head) %}
412
+ {%- set _exit_code_zero = ('exit code: 0' in _content_head or 'process exited with code 0' in _content_head) %}
413
+ {%- set _error_field_ok = ('"error": null' in _content_head or '"error":null' in _content_head or '"error": false' in _content_head or '"error":false' in _content_head or '"error": ""' in _content_head or '"error":""' in _content_head) %}
414
+ {%- set _strong_error = (('"error":' in _content_head and not _error_field_ok) or '"status": "error"' in _content_head or '"status":"error"' in _content_head or 'traceback (most recent call last):' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'fatal:' in _content_head or (('exit code: ' in _content_head or 'process exited with code' in _content_head) and not _exit_code_zero) or _content_head.startswith('exception:') or _content_head.startswith('failed to ')) %}
415
+ {%- set _weak_error = ('error:' in _content_head or 'err!' in _content_head) %}
416
+ {%- set _weak_suppressed = ('$ ' in _content_head or 'took ' in _content_head or content | length >= 600) %}
417
+ {%- if not _is_code_or_grep and (_strong_error or (_weak_error and not _weak_suppressed)) %}
418
+ {%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}
419
+ {%- else %}
420
+ {%- set ns2.consecutive_failures = 0 %}
421
+ {%- endif %}
422
+ {%- if ns2.prev_role != 'tool' %}
423
+ {{- '<|im_start|>user' }}
424
+ {%- endif %}
425
+ {%- set _is_json_payload = (_tool_format == 'json' and content | trim | length > 0 and (content | trim)[:1] in ('{', '[')) %}
426
+ {%- if not _is_json_payload and max_tool_response_chars > 0 and content | length > max_tool_response_chars %}
427
+ {%- set content = content[:max_tool_response_chars] + '\n[TRUNCATED - original length ' ~ (content | length | string) ~ ' chars]' %}
428
+ {%- endif %}
429
+ {{- '\n<tool_response>\n' + content }}
430
+ {%- if ns2.consecutive_failures >= 2 %}
431
+ {{- '\n\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}
432
+ {%- elif ns2.consecutive_failures == 1 %}
433
+ {{- '\n\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}
434
+ {%- endif %}
435
+ {{- '\n</tool_response>' }}
436
+ {%- if loop.last %}
437
+ {{- '<|im_end|>\n' }}
438
+ {%- else %}
439
+ {%- set _next_role = _msgs[loop.index0 + 1].role %}
440
+ {%- if _next_role != 'tool' %}
441
+ {{- '<|im_end|>\n' }}
442
+ {%- endif %}
443
+ {%- endif %}
444
+ {%- else %}
445
+ {{- '<|im_start|>user\n[' + message.role + ']: ' + content + '<|im_end|>\n' }}
446
+ {%- endif %}
447
+ {%- set ns2.prev_role = message.role %}
448
+ {%- endfor %}
449
+ {%- if add_generation_prompt %}
450
+ {{- '<|im_start|>assistant\n' }}
451
+ {%- if not ns_state.thinking %}
452
+ {{- '<think>\n\n</think>\n\n' }}
453
+ {%- else %}
454
+ {{- '<think>\n' }}
455
+ {%- endif %}
456
+ {%- endif %}
@@ -0,0 +1,113 @@
1
+ # LiteLLM proxy stack: litellm + postgres (spend logs / UI) + redis (cache +
2
+ # routing). Imported from the thor stack's docker/litellm.yaml, adapted for
3
+ # mjolnir:
4
+ #
5
+ # - driven by the `mjolnir litellm` CLI (docker compose under the hood)
6
+ # - config is rendered per-run by `mjolnir litellm up` from the user's
7
+ # template in the litellm data dir ($MAIN_LLM_MODEL = the active mjolnir
8
+ # model/config) -> ${LITELLM_DATA_DIR}/litellm_config.yaml
9
+ # - the vLLM server is reached via host.docker.internal (host-gateway) —
10
+ # the proxy works whether mjolnir's vLLM container is up or down, and
11
+ # never shares a network with it
12
+ # - data (postgres + redis) lives under ${LITELLM_DATA_DIR}
13
+ # (default ~/.local/share/mjolnir/litellm)
14
+ #
15
+ # All ${...} are interpolated at `docker compose` time; the values come from
16
+ # the user's env file ($MJOLNIR_LITELLM_ENV, default
17
+ # ~/.local/share/mjolnir/litellm/litellm.env) with the :-defaults below as
18
+ # fallback.
19
+
20
+ services:
21
+ litellm:
22
+ image: ghcr.io/berriai/litellm:${LITELLM_IMAGE_TAG:-v1.100.0}
23
+ restart: unless-stopped
24
+ init: true
25
+ ports:
26
+ - "${LITELLM_PORT:-8000}:4000"
27
+ extra_hosts:
28
+ - "host.docker.internal:host-gateway"
29
+ environment:
30
+ DO_NOT_TRACK: 1
31
+ PYTHONUNBUFFERED: 1
32
+ LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY:-sk-1234}
33
+ DATABASE_URL: postgresql://${LITELLM_POSTGRES_USER:-postgres}:${LITELLM_POSTGRES_PASSWORD:-postgres}@litellm_db:${LITELLM_POSTGRES_PORT:-5432}/${LITELLM_POSTGRES_DB:-postgres}
34
+ STORE_MODEL_IN_DB: "True"
35
+ UI_USERNAME: ${LITELLM_UI_USERNAME:-admin}
36
+ UI_PASSWORD: ${LITELLM_UI_PASSWORD:-admin}
37
+ # litellm_settings.cache: redis + router_settings.redis_* resolve these
38
+ # os.environ/LITELLM_REDIS_* lookups inside the rendered config
39
+ LITELLM_REDIS_HOST: ${LITELLM_REDIS_HOST:-litellm_redis}
40
+ LITELLM_REDIS_PORT: ${LITELLM_REDIS_PORT:-6379}
41
+ LITELLM_REDIS_PASSWORD: ${LITELLM_REDIS_PASSWORD:-redis}
42
+ REDIS_HOST: ${LITELLM_REDIS_HOST:-litellm_redis}
43
+ REDIS_PORT: ${LITELLM_REDIS_PORT:-6379}
44
+ REDIS_PASSWORD: ${LITELLM_REDIS_PASSWORD:-redis}
45
+ LITELLM_LOCAL_MODEL_COST_MAP: "False"
46
+ OPENAI_API_KEY: ${OPENAI_API_KEY:-sk-1}
47
+ OPENAI_BASE_URL: ${OPENAI_BASE_URL:-http://host.docker.internal:6001/v1}
48
+ LITELLM_LOG: INFO
49
+ volumes:
50
+ - ${LITELLM_DATA_DIR}/litellm_config.yaml:/app/config.yaml
51
+ # --keepalive_timeout: uvicorn's default is 5 s, and the close is a
52
+ # silent FIN — any client whose pool holds sockets longer than that
53
+ # surfaces it as "all connections dropped, no server-side error"
54
+ # (120 s was still below opencode's pool lifetime; clients here hold
55
+ # pooled sockets unbounded and this is a LAN-only proxy, so effectively
56
+ # disable the idle close — dead peers are reaped on the client side).
57
+ command: ["--config", "/app/config.yaml", "--keepalive_timeout", "86400"]
58
+ depends_on:
59
+ litellm_db:
60
+ condition: service_healthy
61
+ litellm_redis:
62
+ condition: service_healthy
63
+ healthcheck:
64
+ test: ["CMD-SHELL", "python3 -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:4000/health/liveliness', timeout=3).status == 200 else 1)\""]
65
+ interval: 10s
66
+ timeout: 5s
67
+ start_period: 60s
68
+ retries: 10
69
+
70
+ litellm_db:
71
+ image: postgres:16.1
72
+ hostname: litellm_db
73
+ restart: unless-stopped
74
+ expose:
75
+ - "${LITELLM_POSTGRES_PORT:-5432}/tcp"
76
+ environment:
77
+ POSTGRES_USER: ${LITELLM_POSTGRES_USER:-postgres}
78
+ POSTGRES_PASSWORD: ${LITELLM_POSTGRES_PASSWORD:-postgres}
79
+ POSTGRES_PORT: ${LITELLM_POSTGRES_PORT:-5432}
80
+ POSTGRES_DB: ${LITELLM_POSTGRES_DB:-postgres}
81
+ volumes:
82
+ - ${LITELLM_DATA_DIR}/db:/var/lib/postgresql/data
83
+ healthcheck:
84
+ test: ["CMD-SHELL", "pg_isready -U ${LITELLM_POSTGRES_USER:-postgres} -d ${LITELLM_POSTGRES_DB:-postgres} -h localhost -p ${LITELLM_POSTGRES_PORT:-5432}"]
85
+ interval: 5s
86
+ timeout: 5s
87
+ retries: 5
88
+ start_period: 10s
89
+
90
+ litellm_redis:
91
+ image: redis/redis-stack:latest
92
+ hostname: litellm_redis
93
+ restart: unless-stopped
94
+ expose:
95
+ - 6379/tcp
96
+ environment:
97
+ REDIS_HOST: ${LITELLM_REDIS_HOST:-litellm_redis}
98
+ REDIS_PORT: ${LITELLM_REDIS_PORT:-6379}
99
+ REDIS_SSL: "False"
100
+ REDIS_PASSWORD: ${LITELLM_REDIS_PASSWORD:-redis}
101
+ REDIS_ARGS: "--requirepass ${LITELLM_REDIS_PASSWORD:-redis}"
102
+ volumes:
103
+ - ${LITELLM_DATA_DIR}/redis:/root/redis
104
+ # (the thor stack's bare `redis-cli incr ping` healthcheck is vacuous:
105
+ # redis-cli exits 0 on NOAUTH, so it "passed" even unauthenticated)
106
+ # $$ is compose's escape: the password expands in the container shell,
107
+ # where REDIS_PASSWORD is set (compose itself never sees its value)
108
+ healthcheck:
109
+ test: ["CMD-SHELL", "redis-cli -a \"$$REDIS_PASSWORD\" --raw incr ping 2>/dev/null | grep -qE '^[0-9]+$'"]
110
+ interval: 5s
111
+ timeout: 3s
112
+ retries: 5
113
+ start_period: 10s
@@ -0,0 +1,51 @@
1
+ # Example env file for the `mjolnir litellm` CLI.
2
+ #
3
+ # Copy to ~/.local/share/mjolnir/litellm.env ($MJOLNIR_LITELLM_ENV to
4
+ # override) and uncomment/adjust as needed. Every variable is OPTIONAL —
5
+ # defaults are baked into docker/litellm/docker-compose.yaml.
6
+ #
7
+ # Two kinds of variables:
8
+ # 1. LITELLM_*/POSTGRES/REDIS — consumed by docker-compose.yaml
9
+ # interpolation (proxy port, keys, credentials, image tag).
10
+ # 2. Template variables (${VAR}) — consumed when rendering your
11
+ # ~/litellm_config.template.yaml. The MAIN_LLM_MODEL trio is injected
12
+ # by mjolnir from the active model/config — do not set those here.
13
+
14
+ # --- LiteLLM proxy ---------------------------------------------------------
15
+ # LITELLM_PORT=8000 # host port for the proxy
16
+ # LITELLM_IMAGE_TAG=v1.100.0 # ghcr.io/berriai/litellm:<tag>
17
+ # LITELLM_MASTER_KEY=sk-1234 # master key clients send (Authorization)
18
+ # LITELLM_UI_USERNAME=admin # proxy web UI credentials
19
+ # LITELLM_UI_PASSWORD=admin
20
+ # LITELLM_LOG=INFO
21
+
22
+ # Where the proxy finds the MAIN vLLM server. Default (injected by mjolnir):
23
+ # http://host.docker.internal:<active mjolnir vLLM port>/v1
24
+ # Set it to point the main model at a different vLLM server:
25
+ # LITELLM_MAIN_MODEL_BASE_URL=http://192.168.0.138:8000/v1
26
+
27
+ # --- Postgres (spend logs / UI) -- internal to the stack, not published ----
28
+ # LITELLM_POSTGRES_USER=postgres
29
+ # LITELLM_POSTGRES_PASSWORD=postgres
30
+ # LITELLM_POSTGRES_PORT=5432
31
+ # LITELLM_POSTGRES_DB=postgres
32
+
33
+ # --- Redis (cache + routing) -- internal to the stack, not published ------
34
+ # LITELLM_REDIS_HOST=litellm_redis
35
+ # LITELLM_REDIS_PORT=6379
36
+ # LITELLM_REDIS_PASSWORD=redis
37
+
38
+ # --- OpenAI-compatible client defaults (litellm container env) -------------
39
+ # OPENAI_API_KEY=sk-1
40
+ # OPENAI_BASE_URL=http://host.docker.internal:6001/v1
41
+
42
+ # --- Template variables for the optional task-model sections ---------------
43
+ # Only needed if you uncomment those sections in your template.
44
+ # TASK_MODELS_BASE_URL=192.168.0.138
45
+ # GRAPH_LLM_MODEL=vendor/model
46
+ # TASKS_LLM_MODEL=vendor/model
47
+ # EMBEDDINGS_MODEL=vendor/model
48
+ # RERANKER_MODEL=vendor/model
49
+ # STT_MODEL=vendor/model
50
+ # TTS_MODEL=vendor/model
51
+ # TTS_MODEL_VOICE=default