Instructions to use CohereLabs/North-Mini-Code-1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CohereLabs/North-Mini-Code-1.0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="CohereLabs/North-Mini-Code-1.0") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("CohereLabs/North-Mini-Code-1.0") model = AutoModelForCausalLM.from_pretrained("CohereLabs/North-Mini-Code-1.0", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CohereLabs/North-Mini-Code-1.0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CohereLabs/North-Mini-Code-1.0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CohereLabs/North-Mini-Code-1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/CohereLabs/North-Mini-Code-1.0
- SGLang
How to use CohereLabs/North-Mini-Code-1.0 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 "CohereLabs/North-Mini-Code-1.0" \ --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": "CohereLabs/North-Mini-Code-1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "CohereLabs/North-Mini-Code-1.0" \ --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": "CohereLabs/North-Mini-Code-1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use CohereLabs/North-Mini-Code-1.0 with Docker Model Runner:
docker model run hf.co/CohereLabs/North-Mini-Code-1.0
Chat template: map tool results to tool call positions in one pass
Browse filesWith `regen_tool_call_ids` (the default), `tool_call_id_to_int` loops over every tool call in the conversation for each tool result. Render time grows with the square of the tool calls in the history, so a long agent session passes vLLM's 30 s render timeout.
This builds the mapping once before the message loop: tool calls and tool messages are sorted together by id and paired in one pass, and `format_tool_message` gets the position as an argument. First match wins and an unmatched id renders empty, as on main. A `tool_call_id` that is not a string keeps the loop. It only uses `sort`, `namespace` and list concatenation, so it renders under MiniJinja too.
| Tool calls | main | this PR |
|---:|---:|---:|
| 400 | 0.69 s | 0.03 s |
| 1,600 | 11.0 s | 0.14 s |
| 3,200 | 44 s | 0.34 s |
transformers 5.22.1 with jinja2 3.1.6, one M4 core, one tool call per assistant message.
Output is byte-identical to main on 54,000 randomized conversations (duplicate, unmatched, case-variant and non-string ids, results before their call, `regen_tool_call_ids` off, `documents` set), under jinja2 and under MiniJinja 3.1.0 through its Python binding.
- chat_template.jinja +43 -6
|
@@ -39,8 +39,10 @@ These instructions serve as your defaults, but they can be overridden in subsequ
|
|
| 39 |
"is_error": null
|
| 40 |
}
|
| 41 |
]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}
|
| 42 |
-
{%- macro tool_call_id_to_int(messages, tool_call_id) %}
|
| 43 |
-
{%- if regen_tool_call_ids -%}
|
|
|
|
|
|
|
| 44 |
{%- set counter = namespace(value=0) %}
|
| 45 |
{%- set tool_call_id_seen = namespace(value=false) %}
|
| 46 |
{%- for msg in messages %}
|
|
@@ -58,9 +60,9 @@ These instructions serve as your defaults, but they can be overridden in subsequ
|
|
| 58 |
{{ tool_call_id }}
|
| 59 |
{%- endif -%}
|
| 60 |
{%- endmacro %}
|
| 61 |
-
{%- macro format_tool_message(messages, tool_msg) -%}
|
| 62 |
{#- format tool message #}{
|
| 63 |
-
"tool_call_id": "{{ tool_call_id_to_int(messages, tool_msg.tool_call_id) }}",
|
| 64 |
"results": {
|
| 65 |
{%- if tool_msg.content is mapping or tool_msg.content is string %}
|
| 66 |
|
|
@@ -215,8 +217,43 @@ Your output should adhere to the following json schema:
|
|
| 215 |
{%- if render_developer_instruction -%}
|
| 216 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(developer_instruction) }}<|END_OF_TURN_TOKEN|>
|
| 217 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
{%- for message in messages %}
|
| 219 |
{%- set msg_role_downcased = message.role | lower %}
|
|
|
|
|
|
|
| 220 |
{%- if msg_role_downcased == 'system' and (not (loop.first and initial_instruction_message)) -%}
|
| 221 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(message) }}<|END_OF_TURN_TOKEN|>
|
| 222 |
{%- elif msg_role_downcased == 'user' -%}
|
|
@@ -247,11 +284,11 @@ Your output should adhere to the following json schema:
|
|
| 247 |
{%- endif %}
|
| 248 |
{%- elif msg_role_downcased == 'tool' and message.tool_call_id not in tool_ids_seen.value -%}
|
| 249 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
|
| 250 |
-
{{ format_tool_message(messages, message) }}
|
| 251 |
{%- for msg in messages[loop.index0 + 1:] %}
|
| 252 |
|
| 253 |
{%- if msg.role | lower == 'tool' %},
|
| 254 |
-
{{ format_tool_message(messages, msg) }}
|
| 255 |
{%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}
|
| 256 |
{%- else %}
|
| 257 |
{%- break %}
|
|
|
|
| 39 |
"is_error": null
|
| 40 |
}
|
| 41 |
]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}
|
| 42 |
+
{%- macro tool_call_id_to_int(messages, tool_call_id, hit) %}
|
| 43 |
+
{%- if regen_tool_call_ids and tool_call_id is string -%}
|
| 44 |
+
{{ hit }}
|
| 45 |
+
{%- elif regen_tool_call_ids -%}
|
| 46 |
{%- set counter = namespace(value=0) %}
|
| 47 |
{%- set tool_call_id_seen = namespace(value=false) %}
|
| 48 |
{%- for msg in messages %}
|
|
|
|
| 60 |
{{ tool_call_id }}
|
| 61 |
{%- endif -%}
|
| 62 |
{%- endmacro %}
|
| 63 |
+
{%- macro format_tool_message(messages, tool_msg, hit) -%}
|
| 64 |
{#- format tool message #}{
|
| 65 |
+
"tool_call_id": "{{ tool_call_id_to_int(messages, tool_msg.tool_call_id, hit) }}",
|
| 66 |
"results": {
|
| 67 |
{%- if tool_msg.content is mapping or tool_msg.content is string %}
|
| 68 |
|
|
|
|
| 217 |
{%- if render_developer_instruction -%}
|
| 218 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(developer_instruction) }}<|END_OF_TURN_TOKEN|>
|
| 219 |
{%- endif %}
|
| 220 |
+
{#- tool_call_ints: one entry per tool message, in message order: the position, among all tool calls, of the first
|
| 221 |
+
tool call with the message's tool_call_id, or '' when none has it. Tool calls and tool messages are tagged, sorted
|
| 222 |
+
by id together (stable, so the calls of an id come first and keep their order) and paired in one pass. -#}
|
| 223 |
+
{%- set tl = namespace(items=[], calls=0, n=0) -%}
|
| 224 |
+
{%- for m in messages -%}
|
| 225 |
+
{%- if m.tool_calls -%}
|
| 226 |
+
{%- for tc in m.tool_calls -%}
|
| 227 |
+
{%- if tc.id is string -%}
|
| 228 |
+
{%- set tl.items = tl.items + [{'id': tc.id, 'k': -1, 'n': tl.calls}] -%}
|
| 229 |
+
{%- endif -%}
|
| 230 |
+
{%- set tl.calls = tl.calls + 1 -%}
|
| 231 |
+
{%- endfor -%}
|
| 232 |
+
{%- endif -%}
|
| 233 |
+
{%- endfor -%}
|
| 234 |
+
{%- for m in messages -%}
|
| 235 |
+
{%- if m.role | lower == 'tool' -%}
|
| 236 |
+
{%- set tl.items = tl.items + [{'id': m.tool_call_id if m.tool_call_id is string else '', 'k': tl.n}] -%}
|
| 237 |
+
{%- set tl.n = tl.n + 1 -%}
|
| 238 |
+
{%- endif -%}
|
| 239 |
+
{%- endfor -%}
|
| 240 |
+
{%- set pr = namespace(id=none, n='', hits=[]) -%}
|
| 241 |
+
{%- for it in tl.items | sort(attribute='id', case_sensitive=true) -%}
|
| 242 |
+
{%- if it.k < 0 -%}
|
| 243 |
+
{%- if pr.id is none or pr.id != it.id -%}
|
| 244 |
+
{%- set pr.id = it.id -%}
|
| 245 |
+
{%- set pr.n = it.n -%}
|
| 246 |
+
{%- endif -%}
|
| 247 |
+
{%- else -%}
|
| 248 |
+
{%- set pr.hits = pr.hits + [{'k': it.k, 'n': pr.n if pr.id is not none and pr.id == it.id else ''}] -%}
|
| 249 |
+
{%- endif -%}
|
| 250 |
+
{%- endfor -%}
|
| 251 |
+
{%- set tool_call_ints = pr.hits | sort(attribute='k') -%}
|
| 252 |
+
{%- set tl.n = 0 -%}
|
| 253 |
{%- for message in messages %}
|
| 254 |
{%- set msg_role_downcased = message.role | lower %}
|
| 255 |
+
{%- set tool_ord = tl.n %}
|
| 256 |
+
{%- if msg_role_downcased == 'tool' %}{%- set tl.n = tl.n + 1 %}{%- endif %}
|
| 257 |
{%- if msg_role_downcased == 'system' and (not (loop.first and initial_instruction_message)) -%}
|
| 258 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(message) }}<|END_OF_TURN_TOKEN|>
|
| 259 |
{%- elif msg_role_downcased == 'user' -%}
|
|
|
|
| 284 |
{%- endif %}
|
| 285 |
{%- elif msg_role_downcased == 'tool' and message.tool_call_id not in tool_ids_seen.value -%}
|
| 286 |
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
|
| 287 |
+
{{ format_tool_message(messages, message, tool_call_ints[tool_ord].n) }}
|
| 288 |
{%- for msg in messages[loop.index0 + 1:] %}
|
| 289 |
|
| 290 |
{%- if msg.role | lower == 'tool' %},
|
| 291 |
+
{{ format_tool_message(messages, msg, tool_call_ints[tool_ord + 1 + loop.index0].n) }}
|
| 292 |
{%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}
|
| 293 |
{%- else %}
|
| 294 |
{%- break %}
|