Image-Text-to-Text
Transformers
Safetensors
kimi_k3
feature-extraction
compressed-tensors
conversational
custom_code
Eval Results
8-bit precision
Instructions to use moonshotai/Kimi-K3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moonshotai/Kimi-K3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="moonshotai/Kimi-K3", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("moonshotai/Kimi-K3", trust_remote_code=True, device_map="auto") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use moonshotai/Kimi-K3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moonshotai/Kimi-K3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/moonshotai/Kimi-K3
- SGLang
How to use moonshotai/Kimi-K3 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "moonshotai/Kimi-K3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "moonshotai/Kimi-K3" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moonshotai/Kimi-K3", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use moonshotai/Kimi-K3 with Docker Model Runner:
docker model run hf.co/moonshotai/Kimi-K3
Upload tokenizer.json (HF-compatible tokenizer without trust_remote_code)
#60
by Xenova HF Staff - opened
- .gitattributes +1 -0
- chat_template.jinja +301 -0
- tokenizer.json +3 -0
- tokenizer_config.json +4 -140
.gitattributes
CHANGED
|
@@ -35,3 +35,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
assets/k3-hero.jpg filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
assets/k3-hero.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- macro escape_attr(value) -%}
|
| 2 |
+
{{- value|string|replace('&', '&')|replace('"', '"') -}}
|
| 3 |
+
{%- endmacro -%}
|
| 4 |
+
|
| 5 |
+
{%- macro open_tag(tag, attrs=[]) -%}
|
| 6 |
+
{{- '<|open|>' + tag -}}
|
| 7 |
+
{%- for attr in attrs -%}
|
| 8 |
+
{{- ' ' + attr[0] + '="' -}}{{- escape_attr(attr[1]) -}}{{- '"' -}}
|
| 9 |
+
{%- endfor -%}
|
| 10 |
+
{{- '<|sep|>' -}}
|
| 11 |
+
{%- endmacro -%}
|
| 12 |
+
|
| 13 |
+
{%- macro close_tag(tag) -%}
|
| 14 |
+
{{- '<|close|>' + tag + '<|sep|>' -}}
|
| 15 |
+
{%- endmacro -%}
|
| 16 |
+
|
| 17 |
+
{%- macro next_image(state) -%}
|
| 18 |
+
{%- if image_prompts is defined and image_prompts is not none -%}
|
| 19 |
+
{%- if state.image_index >= image_prompts|length -%}
|
| 20 |
+
{{- raise_exception('More image placeholders than image prompts.') -}}
|
| 21 |
+
{%- endif -%}
|
| 22 |
+
{{- image_prompts[state.image_index] -}}
|
| 23 |
+
{%- set state.image_index = state.image_index + 1 -%}
|
| 24 |
+
{%- else -%}
|
| 25 |
+
{{- '<|kimi_image_placeholder|>' -}}
|
| 26 |
+
{%- endif -%}
|
| 27 |
+
{%- endmacro -%}
|
| 28 |
+
|
| 29 |
+
{%- macro render_text(text, state) -%}
|
| 30 |
+
{%- set text = text|string -%}
|
| 31 |
+
{%- if image_prompts is defined and image_prompts is not none and '<|kimi_image_placeholder|>' in text -%}
|
| 32 |
+
{%- set parts = text.split('<|kimi_image_placeholder|>') -%}
|
| 33 |
+
{%- for part in parts -%}
|
| 34 |
+
{{- part -}}
|
| 35 |
+
{%- if not loop.last -%}{{- next_image(state) -}}{%- endif -%}
|
| 36 |
+
{%- endfor -%}
|
| 37 |
+
{%- else -%}
|
| 38 |
+
{{- text -}}
|
| 39 |
+
{%- endif -%}
|
| 40 |
+
{%- endmacro -%}
|
| 41 |
+
|
| 42 |
+
{%- macro render_content(content, state) -%}
|
| 43 |
+
{%- if content is string -%}
|
| 44 |
+
{{- render_text(content, state) -}}
|
| 45 |
+
{%- elif content is not none and content is defined -%}
|
| 46 |
+
{%- for part in content -%}
|
| 47 |
+
{%- if part.type in ['image', 'image_url'] -%}
|
| 48 |
+
{{- next_image(state) -}}
|
| 49 |
+
{%- else -%}
|
| 50 |
+
{{- render_text(part.text, state) -}}
|
| 51 |
+
{%- endif -%}
|
| 52 |
+
{%- endfor -%}
|
| 53 |
+
{%- endif -%}
|
| 54 |
+
{%- endmacro -%}
|
| 55 |
+
|
| 56 |
+
{%- macro internal_system_message(message_type, body) -%}
|
| 57 |
+
{{- open_tag('message', [('role', 'system'), ('type', message_type)]) -}}
|
| 58 |
+
{{- body|trim -}}
|
| 59 |
+
{{- close_tag('message') -}}
|
| 60 |
+
{{- '<|end_of_msg|>' -}}
|
| 61 |
+
{%- endmacro -%}
|
| 62 |
+
|
| 63 |
+
{%- macro render_tool_declare(tool_list, dynamic=false) -%}
|
| 64 |
+
{{- open_tag('message', [('role', 'system'), ('type', 'tool-declare')]) -}}
|
| 65 |
+
{%- if dynamic -%}
|
| 66 |
+
{{- '## New Tools Available\nThe system dynamically extends the toolset via lazy-loading.\nYou have access to all existing and extended tools.\nHere are the specs for the extended tools.\n\n```json\n' -}}
|
| 67 |
+
{%- else -%}
|
| 68 |
+
{{- '# Tools\nHere are the available tools, described in JSONSchema.\n\n```json\n' -}}
|
| 69 |
+
{%- endif -%}
|
| 70 |
+
{{- tool_list|tojson(ensure_ascii=false, separators=(',', ':'), sort_keys=true) -}}
|
| 71 |
+
{{- '\n```' -}}
|
| 72 |
+
{{- close_tag('message') -}}
|
| 73 |
+
{{- '<|end_of_msg|>' -}}
|
| 74 |
+
{%- endmacro -%}
|
| 75 |
+
|
| 76 |
+
{%- macro xtml_type(value) -%}
|
| 77 |
+
{%- if value is boolean -%}boolean
|
| 78 |
+
{%- elif value is none -%}null
|
| 79 |
+
{%- elif value is number -%}number
|
| 80 |
+
{%- elif value is string -%}string
|
| 81 |
+
{%- elif value is mapping -%}object
|
| 82 |
+
{%- else -%}array
|
| 83 |
+
{%- endif -%}
|
| 84 |
+
{%- endmacro -%}
|
| 85 |
+
|
| 86 |
+
{%- macro xtml_value(value) -%}
|
| 87 |
+
{%- if value is string -%}
|
| 88 |
+
{{- value -}}
|
| 89 |
+
{%- else -%}
|
| 90 |
+
{{- value|tojson(ensure_ascii=false) -}}
|
| 91 |
+
{%- endif -%}
|
| 92 |
+
{%- endmacro -%}
|
| 93 |
+
|
| 94 |
+
{%- macro render_assistant(message, state) -%}
|
| 95 |
+
{%- if thinking -%}
|
| 96 |
+
{%- set reasoning_content = message.get('reasoning_content') or message.get('reasoning') -%}
|
| 97 |
+
{{- open_tag('think') -}}
|
| 98 |
+
{%- if reasoning_content is not none and reasoning_content|string|trim -%}
|
| 99 |
+
{{- render_text(reasoning_content, state) -}}
|
| 100 |
+
{%- endif -%}
|
| 101 |
+
{{- close_tag('think') -}}
|
| 102 |
+
{%- endif -%}
|
| 103 |
+
{{- open_tag('response') -}}
|
| 104 |
+
{{- render_content(message.get('content'), state) -}}
|
| 105 |
+
{{- close_tag('response') -}}
|
| 106 |
+
{%- set tool_calls = message.get('tool_calls') -%}
|
| 107 |
+
{%- if tool_calls -%}
|
| 108 |
+
{{- open_tag('tools') -}}
|
| 109 |
+
{%- for tool_call in tool_calls -%}
|
| 110 |
+
{%- if tool_call is not mapping -%}
|
| 111 |
+
{{- raise_exception('Kimi K3 tool calls must be mappings.') -}}
|
| 112 |
+
{%- endif -%}
|
| 113 |
+
{%- set fn = tool_call.function if tool_call.function is defined and tool_call.function is mapping else tool_call -%}
|
| 114 |
+
{%- if fn.get('name') is none -%}
|
| 115 |
+
{{- raise_exception('Kimi K3 tool calls require a function name.') -}}
|
| 116 |
+
{%- endif -%}
|
| 117 |
+
{{- open_tag('call', [('tool', fn.name), ('index', loop.index)]) -}}
|
| 118 |
+
{%- set arguments = fn.get('arguments', {}) -%}
|
| 119 |
+
{%- set json_block = fn.get('_xtml_json_block') -%}
|
| 120 |
+
{%- if json_block is not none -%}
|
| 121 |
+
{{- open_tag('json', [('type', 'object')]) -}}
|
| 122 |
+
{{- render_text(json_block, state) -}}
|
| 123 |
+
{{- close_tag('json') -}}
|
| 124 |
+
{%- elif arguments is mapping -%}
|
| 125 |
+
{%- for key, value in arguments.items() -%}
|
| 126 |
+
{{- open_tag('argument', [('key', key), ('type', xtml_type(value))]) -}}
|
| 127 |
+
{{- render_text(xtml_value(value), state) -}}
|
| 128 |
+
{{- close_tag('argument') -}}
|
| 129 |
+
{%- endfor -%}
|
| 130 |
+
{%- elif arguments is string and arguments|trim -%}
|
| 131 |
+
{{- open_tag('json', [('type', 'object')]) -}}
|
| 132 |
+
{{- render_text(arguments, state) -}}
|
| 133 |
+
{{- close_tag('json') -}}
|
| 134 |
+
{%- elif arguments is not none and arguments is not string -%}
|
| 135 |
+
{{- raise_exception('Kimi K3 tool call arguments must be a mapping or a JSON object string.') -}}
|
| 136 |
+
{%- endif -%}
|
| 137 |
+
{{- close_tag('call') -}}
|
| 138 |
+
{%- endfor -%}
|
| 139 |
+
{{- close_tag('tools') -}}
|
| 140 |
+
{%- endif -%}
|
| 141 |
+
{%- endmacro -%}
|
| 142 |
+
|
| 143 |
+
{%- macro render_tool_message(message, state, resolved_name=none) -%}
|
| 144 |
+
{%- set state.tool_index = state.tool_index + 1 -%}
|
| 145 |
+
{%- if resolved_name is not none -%}
|
| 146 |
+
{%- set tool_name = resolved_name -%}
|
| 147 |
+
{%- elif 'tool' in message -%}
|
| 148 |
+
{%- set tool_name = message.get('tool') -%}
|
| 149 |
+
{%- else -%}
|
| 150 |
+
{%- set tool_name = message.get('name') -%}
|
| 151 |
+
{%- endif -%}
|
| 152 |
+
{%- if tool_name is none and state.tool_calls is not none and state.tool_index <= state.tool_calls|length -%}
|
| 153 |
+
{%- set fallback_call = state.tool_calls[state.tool_index - 1] -%}
|
| 154 |
+
{%- set fallback_fn = fallback_call.function if fallback_call.function is defined and fallback_call.function is mapping else fallback_call -%}
|
| 155 |
+
{%- set tool_name = fallback_fn.name -%}
|
| 156 |
+
{%- endif -%}
|
| 157 |
+
{%- if tool_name is none -%}
|
| 158 |
+
{{- raise_exception('Kimi K3 tool messages need a resolvable tool name: carry `tool`/`name`, or match a preceding assistant tool_call by order.') -}}
|
| 159 |
+
{%- endif -%}
|
| 160 |
+
{{- open_tag('message', [('role', 'tool'), ('tool', tool_name), ('index', state.tool_index)]) -}}
|
| 161 |
+
{{- render_content(message.get('content'), state) -}}
|
| 162 |
+
{{- close_tag('message') -}}
|
| 163 |
+
{{- '<|end_of_msg|>' -}}
|
| 164 |
+
{%- endmacro -%}
|
| 165 |
+
|
| 166 |
+
{%- if thinking is undefined -%}
|
| 167 |
+
{%- set thinking = true -%}
|
| 168 |
+
{%- endif -%}
|
| 169 |
+
{%- if thinking_effort is undefined -%}
|
| 170 |
+
{%- set thinking_effort = 'max' -%}
|
| 171 |
+
{%- endif -%}
|
| 172 |
+
{%- if thinking and thinking_effort is not none and thinking_effort not in ['low', 'high', 'max'] -%}
|
| 173 |
+
{{- raise_exception('Unsupported thinking_effort=' + thinking_effort|string + '; supported values are low, high, and max.') -}}
|
| 174 |
+
{%- endif -%}
|
| 175 |
+
|
| 176 |
+
{%- set state = namespace({'image_index': 0, 'tool_calls': none, 'tool_index': 0, 'response_schema': none}) -%}
|
| 177 |
+
|
| 178 |
+
{%- if tools is defined and tools -%}
|
| 179 |
+
{{- render_tool_declare(tools) -}}
|
| 180 |
+
{%- endif -%}
|
| 181 |
+
|
| 182 |
+
{%- if thinking and thinking_effort in ['low', 'high', 'max'] -%}
|
| 183 |
+
{{- internal_system_message(
|
| 184 |
+
'thinking-effort',
|
| 185 |
+
'`thinking_effort` guides on how much to think in your thinking channel (not including the response channel), supported values include `low`, `medium`, `high`, and `max`.\nNow the system is invoked with `thinking_effort=' + thinking_effort|string + '`.'
|
| 186 |
+
) -}}
|
| 187 |
+
{%- endif -%}
|
| 188 |
+
|
| 189 |
+
{%- for message in messages -%}
|
| 190 |
+
{%- if message is mapping -%}
|
| 191 |
+
{%- if 'role' not in message -%}
|
| 192 |
+
{{- raise_exception('Kimi K3 messages require a role.') -}}
|
| 193 |
+
{%- elif message.role == 'user' -%}
|
| 194 |
+
{%- set attrs = [('role', 'user')] -%}
|
| 195 |
+
{%- if message.get('name') -%}{%- set attrs = attrs + [('name', message.name)] -%}{%- endif -%}
|
| 196 |
+
{{- open_tag('message', attrs) -}}
|
| 197 |
+
{{- render_content(message.get('content'), state) -}}
|
| 198 |
+
{{- close_tag('message') -}}
|
| 199 |
+
{{- '<|end_of_msg|>' -}}
|
| 200 |
+
{%- elif message.role == 'system' and message.get('tools') -%}
|
| 201 |
+
{{- render_tool_declare(message.tools, dynamic=true) -}}
|
| 202 |
+
{%- elif message.role == 'system' -%}
|
| 203 |
+
{%- set attrs = [('role', 'system')] -%}
|
| 204 |
+
{%- if message.get('name') -%}{%- set attrs = attrs + [('name', message.name)] -%}{%- endif -%}
|
| 205 |
+
{{- open_tag('message', attrs) -}}
|
| 206 |
+
{{- render_content(message.get('content'), state) -}}
|
| 207 |
+
{{- close_tag('message') -}}
|
| 208 |
+
{{- '<|end_of_msg|>' -}}
|
| 209 |
+
{%- elif message.role == 'assistant' -%}
|
| 210 |
+
{%- set state.tool_calls = message.get('tool_calls') -%}
|
| 211 |
+
{%- set state.tool_index = 0 -%}
|
| 212 |
+
{%- set attrs = [('role', 'assistant')] -%}
|
| 213 |
+
{%- if message.get('name') -%}{%- set attrs = attrs + [('name', message.name)] -%}{%- endif -%}
|
| 214 |
+
{{- open_tag('message', attrs) -}}
|
| 215 |
+
{{- render_assistant(message, state) -}}
|
| 216 |
+
{{- close_tag('message') -}}
|
| 217 |
+
{{- '<|end_of_msg|>' -}}
|
| 218 |
+
{%- elif message.role == 'tool' and (loop.first or messages[loop.index0 - 1].role != 'tool') -%}
|
| 219 |
+
{%- set run = namespace({'items': [], 'resolved_count': 0}) -%}
|
| 220 |
+
{%- for candidate in messages[loop.index0:] -%}
|
| 221 |
+
{%- if candidate is not mapping or candidate.role != 'tool' -%}{%- break -%}{%- endif -%}
|
| 222 |
+
{%- set run.items = run.items + [candidate] -%}
|
| 223 |
+
{%- set call_id = candidate.get('tool_call_id', candidate.get('id')) -%}
|
| 224 |
+
{%- set match = namespace({'found': false}) -%}
|
| 225 |
+
{%- if call_id is not none and state.tool_calls is not none -%}
|
| 226 |
+
{%- for tool_call in state.tool_calls -%}
|
| 227 |
+
{%- if not match.found and tool_call is mapping and tool_call.get('id') is not none and tool_call.get('id')|string == call_id|string -%}
|
| 228 |
+
{%- set match.found = true -%}
|
| 229 |
+
{%- endif -%}
|
| 230 |
+
{%- endfor -%}
|
| 231 |
+
{%- endif -%}
|
| 232 |
+
{%- if match.found -%}{%- set run.resolved_count = run.resolved_count + 1 -%}{%- endif -%}
|
| 233 |
+
{%- endfor -%}
|
| 234 |
+
{%- if run.items|length > 0 and run.resolved_count == run.items|length -%}
|
| 235 |
+
{%- set emitted = namespace({'ids': []}) -%}
|
| 236 |
+
{%- for tool_call in state.tool_calls -%}
|
| 237 |
+
{%- if tool_call is mapping and tool_call.get('id') is not none and tool_call.get('id')|string not in emitted.ids -%}
|
| 238 |
+
{%- set emitted.ids = emitted.ids + [tool_call.get('id')|string] -%}
|
| 239 |
+
{%- set fn = tool_call.function if tool_call.function is defined and tool_call.function is mapping else tool_call -%}
|
| 240 |
+
{%- for tool_message in run.items -%}
|
| 241 |
+
{%- set result_id = tool_message.get('tool_call_id', tool_message.get('id')) -%}
|
| 242 |
+
{%- if result_id is not none and result_id|string == tool_call.get('id')|string -%}
|
| 243 |
+
{{- render_tool_message(tool_message, state, fn.get('name')) -}}
|
| 244 |
+
{%- endif -%}
|
| 245 |
+
{%- endfor -%}
|
| 246 |
+
{%- endif -%}
|
| 247 |
+
{%- endfor -%}
|
| 248 |
+
{%- else -%}
|
| 249 |
+
{%- for tool_message in run.items -%}
|
| 250 |
+
{{- render_tool_message(tool_message, state) -}}
|
| 251 |
+
{%- endfor -%}
|
| 252 |
+
{%- endif -%}
|
| 253 |
+
{%- endif -%}
|
| 254 |
+
{%- endif -%}
|
| 255 |
+
{%- endfor -%}
|
| 256 |
+
|
| 257 |
+
{%- if tool_choice is defined and tool_choice == 'required' -%}
|
| 258 |
+
{{- internal_system_message('tool-choice', 'The system is invoked with `tool_choice=required`.\nYou MUST call tools in the next message.') -}}
|
| 259 |
+
{%- elif tool_choice is defined and tool_choice == 'none' -%}
|
| 260 |
+
{{- internal_system_message('tool-choice', 'The system is invoked with `tool_choice=none`.\nYou MUST NOT call any tools in the next message.') -}}
|
| 261 |
+
{%- endif -%}
|
| 262 |
+
|
| 263 |
+
{%- if response_schema is defined -%}
|
| 264 |
+
{%- set state.response_schema = response_schema -%}
|
| 265 |
+
{%- elif response_format is defined and response_format is mapping and response_format.get('json_schema') is not none -%}
|
| 266 |
+
{%- set schema_wrapper = response_format.get('json_schema') -%}
|
| 267 |
+
{%- if schema_wrapper is mapping and 'schema' in schema_wrapper -%}
|
| 268 |
+
{%- set state.response_schema = schema_wrapper.get('schema') -%}
|
| 269 |
+
{%- elif schema_wrapper is mapping and 'json_schema' in schema_wrapper -%}
|
| 270 |
+
{%- set state.response_schema = schema_wrapper.get('json_schema') -%}
|
| 271 |
+
{%- else -%}
|
| 272 |
+
{%- set state.response_schema = schema_wrapper -%}
|
| 273 |
+
{%- endif -%}
|
| 274 |
+
{%- endif -%}
|
| 275 |
+
|
| 276 |
+
{%- set response_format_type = none -%}
|
| 277 |
+
{%- if response_format is defined and response_format is mapping -%}
|
| 278 |
+
{%- set response_format_type = response_format.get('type') -%}
|
| 279 |
+
{%- elif response_format is defined -%}
|
| 280 |
+
{%- set response_format_type = response_format -%}
|
| 281 |
+
{%- endif -%}
|
| 282 |
+
{%- if response_format_type == 'json_object' -%}
|
| 283 |
+
{{- internal_system_message(
|
| 284 |
+
'response-format',
|
| 285 |
+
'The system is invoked with `response_format=json_object`.\nYour response must be raw JSON data without markdown code blocks (```json) or any additional formatting.'
|
| 286 |
+
) -}}
|
| 287 |
+
{%- elif response_format_type == 'json_schema' -%}
|
| 288 |
+
{{- internal_system_message(
|
| 289 |
+
'response-format',
|
| 290 |
+
'The system is invoked with `response_format=json_schema`.\nYour response must be raw JSON data without markdown code blocks (```json) or any additional formatting.\nThe JSON data must match the following schema:\n```json\n' + state.response_schema|tojson(ensure_ascii=false, separators=(',', ':'), sort_keys=true) + '\n```'
|
| 291 |
+
) -}}
|
| 292 |
+
{%- endif -%}
|
| 293 |
+
|
| 294 |
+
{%- if add_generation_prompt -%}
|
| 295 |
+
{{- open_tag('message', [('role', 'assistant')]) -}}
|
| 296 |
+
{{- open_tag('think' if thinking else 'response') -}}
|
| 297 |
+
{%- endif -%}
|
| 298 |
+
|
| 299 |
+
{%- if image_prompts is defined and image_prompts is not none and state.image_index != image_prompts|length -%}
|
| 300 |
+
{{- raise_exception('image prompt count ' + image_prompts|length|string + ' != consumed placeholder count ' + state.image_index|string) -}}
|
| 301 |
+
{%- endif -%}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b55c4532c501114da9a8891b77d244fa32eee2ace2bd51abb5dc4fb156f60eb9
|
| 3 |
+
size 19592838
|
tokenizer_config.json
CHANGED
|
@@ -1,134 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"added_tokens_decoder": {
|
| 3 |
-
"163584": {
|
| 4 |
-
"content": "[BOS]",
|
| 5 |
-
"lstrip": false,
|
| 6 |
-
"normalized": false,
|
| 7 |
-
"rstrip": false,
|
| 8 |
-
"single_word": false,
|
| 9 |
-
"special": true
|
| 10 |
-
},
|
| 11 |
-
"163585": {
|
| 12 |
-
"content": "[EOS]",
|
| 13 |
-
"lstrip": false,
|
| 14 |
-
"normalized": false,
|
| 15 |
-
"rstrip": false,
|
| 16 |
-
"single_word": false,
|
| 17 |
-
"special": true
|
| 18 |
-
},
|
| 19 |
-
"163586": {
|
| 20 |
-
"content": "<|end_of_msg|>",
|
| 21 |
-
"lstrip": false,
|
| 22 |
-
"normalized": false,
|
| 23 |
-
"rstrip": false,
|
| 24 |
-
"single_word": false,
|
| 25 |
-
"special": true
|
| 26 |
-
},
|
| 27 |
-
"163587": {
|
| 28 |
-
"content": "<|open|>",
|
| 29 |
-
"lstrip": false,
|
| 30 |
-
"normalized": false,
|
| 31 |
-
"rstrip": false,
|
| 32 |
-
"single_word": false,
|
| 33 |
-
"special": false
|
| 34 |
-
},
|
| 35 |
-
"163588": {
|
| 36 |
-
"content": "<|close|>",
|
| 37 |
-
"lstrip": false,
|
| 38 |
-
"normalized": false,
|
| 39 |
-
"rstrip": false,
|
| 40 |
-
"single_word": false,
|
| 41 |
-
"special": false
|
| 42 |
-
},
|
| 43 |
-
"163589": {
|
| 44 |
-
"content": "<|sep|>",
|
| 45 |
-
"lstrip": false,
|
| 46 |
-
"normalized": false,
|
| 47 |
-
"rstrip": false,
|
| 48 |
-
"single_word": false,
|
| 49 |
-
"special": false
|
| 50 |
-
},
|
| 51 |
-
"163590": {
|
| 52 |
-
"content": "[start_header_id]",
|
| 53 |
-
"lstrip": false,
|
| 54 |
-
"normalized": false,
|
| 55 |
-
"rstrip": false,
|
| 56 |
-
"single_word": false,
|
| 57 |
-
"special": true
|
| 58 |
-
},
|
| 59 |
-
"163591": {
|
| 60 |
-
"content": "[end_header_id]",
|
| 61 |
-
"lstrip": false,
|
| 62 |
-
"normalized": false,
|
| 63 |
-
"rstrip": false,
|
| 64 |
-
"single_word": false,
|
| 65 |
-
"special": true
|
| 66 |
-
},
|
| 67 |
-
"163593": {
|
| 68 |
-
"content": "[EOT]",
|
| 69 |
-
"lstrip": false,
|
| 70 |
-
"normalized": false,
|
| 71 |
-
"rstrip": false,
|
| 72 |
-
"single_word": false,
|
| 73 |
-
"special": true
|
| 74 |
-
},
|
| 75 |
-
"163602": {
|
| 76 |
-
"content": "<|media_begin|>",
|
| 77 |
-
"lstrip": false,
|
| 78 |
-
"normalized": false,
|
| 79 |
-
"rstrip": false,
|
| 80 |
-
"single_word": false,
|
| 81 |
-
"special": true
|
| 82 |
-
},
|
| 83 |
-
"163603": {
|
| 84 |
-
"content": "<|media_content|>",
|
| 85 |
-
"lstrip": false,
|
| 86 |
-
"normalized": false,
|
| 87 |
-
"rstrip": false,
|
| 88 |
-
"single_word": false,
|
| 89 |
-
"special": true
|
| 90 |
-
},
|
| 91 |
-
"163604": {
|
| 92 |
-
"content": "<|media_end|>",
|
| 93 |
-
"lstrip": false,
|
| 94 |
-
"normalized": false,
|
| 95 |
-
"rstrip": false,
|
| 96 |
-
"single_word": false,
|
| 97 |
-
"special": true
|
| 98 |
-
},
|
| 99 |
-
"163605": {
|
| 100 |
-
"content": "<|media_pad|>",
|
| 101 |
-
"lstrip": false,
|
| 102 |
-
"normalized": false,
|
| 103 |
-
"rstrip": false,
|
| 104 |
-
"single_word": false,
|
| 105 |
-
"special": true
|
| 106 |
-
},
|
| 107 |
-
"163649": {
|
| 108 |
-
"content": "<osagent_mode>",
|
| 109 |
-
"lstrip": false,
|
| 110 |
-
"normalized": false,
|
| 111 |
-
"rstrip": false,
|
| 112 |
-
"single_word": false,
|
| 113 |
-
"special": true
|
| 114 |
-
},
|
| 115 |
-
"163838": {
|
| 116 |
-
"content": "[UNK]",
|
| 117 |
-
"lstrip": false,
|
| 118 |
-
"normalized": false,
|
| 119 |
-
"rstrip": false,
|
| 120 |
-
"single_word": false,
|
| 121 |
-
"special": true
|
| 122 |
-
},
|
| 123 |
-
"163839": {
|
| 124 |
-
"content": "[PAD]",
|
| 125 |
-
"lstrip": false,
|
| 126 |
-
"normalized": false,
|
| 127 |
-
"rstrip": false,
|
| 128 |
-
"single_word": false,
|
| 129 |
-
"special": true
|
| 130 |
-
}
|
| 131 |
-
},
|
| 132 |
"additional_special_tokens": [
|
| 133 |
"<|end_of_msg|>",
|
| 134 |
"[start_header_id]",
|
|
@@ -140,18 +10,12 @@
|
|
| 140 |
"<|media_pad|>",
|
| 141 |
"<osagent_mode>"
|
| 142 |
],
|
|
|
|
| 143 |
"bos_token": "[BOS]",
|
| 144 |
"clean_up_tokenization_spaces": false,
|
| 145 |
"eos_token": "[EOS]",
|
| 146 |
-
"extra_special_tokens": {},
|
| 147 |
"model_max_length": 1000000000000000019884624838656,
|
| 148 |
"pad_token": "[PAD]",
|
| 149 |
-
"tokeniz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| 11 |
"<osagent_mode>"
|
| 12 |
],
|
| 13 |
+
"backend": "tokenizers",
|
| 14 |
"bos_token": "[BOS]",
|
| 15 |
"clean_up_tokenization_spaces": false,
|
| 16 |
"eos_token": "[EOS]",
|
|
|
|
| 17 |
"model_max_length": 1000000000000000019884624838656,
|
| 18 |
"pad_token": "[PAD]",
|
| 19 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 20 |
+
"unk_token": "[UNK]"
|
| 21 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|