Compare commits

...

2 Commits

Author SHA1 Message Date
Piotr Wilkin
4c4a3e2596 Some renames to make @CISC happy :> 2026-06-14 19:52:23 +02:00
Piotr Wilkin
f2bb114a32 chat: add dedicated Cohere2MoE (North Code) parser 2026-06-14 18:25:19 +02:00
3 changed files with 506 additions and 0 deletions

View File

@@ -1979,6 +1979,146 @@ static common_chat_params common_chat_params_init_deepseek_v3_2(const common_cha
return data;
}
// Cohere2 MoE (a.k.a. "North Code") parser.
//
// The assistant turn is fully marker-wrapped:
// <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
// <|START_THINKING|>{reasoning}<|END_THINKING|>
// then EITHER content: <|START_TEXT|>{content}<|END_TEXT|>
// OR tool calls: <|START_ACTION|>[
// {"tool_call_id": "0", "tool_name": "f", "parameters": {...}}, ...
// ]<|END_ACTION|>
// <|END_OF_TURN_TOKEN|>
//
// The generation prompt forces a leading <|START_THINKING|> (when reasoning is enabled, which is
// the template default), so the model's output continues from *inside* the thinking block. The
// parser literal therefore only covers the stable <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> prefix
// and the reasoning rule consumes the <|START_THINKING|> ... <|END_THINKING|> markers itself,
// regardless of whether they came from the generation prompt or the generated text.
static common_chat_params common_chat_params_init_cohere2moe(const common_chat_template & tmpl,
const autoparser::generation_params & inputs) {
common_chat_params data;
const std::string TURN_START = "<|START_OF_TURN_TOKEN|>";
const std::string TURN_END = "<|END_OF_TURN_TOKEN|>";
const std::string CHATBOT = "<|CHATBOT_TOKEN|>";
const std::string USER = "<|USER_TOKEN|>";
const std::string SYSTEM = "<|SYSTEM_TOKEN|>";
const std::string THINK_START = "<|START_THINKING|>";
const std::string THINK_END = "<|END_THINKING|>";
const std::string TEXT_START = "<|START_TEXT|>";
const std::string TEXT_END = "<|END_TEXT|>";
const std::string ACTION_START = "<|START_ACTION|>";
const std::string ACTION_END = "<|END_ACTION|>";
const std::string RESULT_START = "<|START_TOOL_RESULT|>";
const std::string RESULT_END = "<|END_TOOL_RESULT|>";
// Stable prefix of the generation prompt that precedes the (forced) <|START_THINKING|> marker.
const std::string GEN_PREFIX = TURN_START + CHATBOT;
data.prompt = common_chat_template_direct_apply_impl(tmpl, inputs);
data.generation_prompt = common_chat_template_generation_prompt_impl(tmpl, inputs);
data.format = COMMON_CHAT_FORMAT_PEG_NATIVE;
data.supports_thinking = true;
data.thinking_start_tag = THINK_START;
data.thinking_end_tag = THINK_END;
data.preserved_tokens = {
TURN_START, TURN_END, CHATBOT, USER, SYSTEM,
THINK_START, THINK_END,
TEXT_START, TEXT_END,
ACTION_START, ACTION_END,
RESULT_START, RESULT_END,
};
// Split the rendered prompt into per-role message spans. Tool results are rendered with the
// system token followed by <|START_TOOL_RESULT|>, so the "tool" delimiter must be listed before
// the plain "system" one (it is a strict superset, and the role split tries delimiters in order).
data.message_spans = common_chat_split_by_role(data.prompt, {
{ "assistant", GEN_PREFIX },
{ "user", TURN_START + USER },
{ "tool", TURN_START + SYSTEM + RESULT_START },
{ "system", TURN_START + SYSTEM },
});
auto has_tools = inputs.tools.is_array() && !inputs.tools.empty();
auto extract_reasoning = inputs.reasoning_format != COMMON_REASONING_FORMAT_NONE;
auto include_grammar = has_tools && inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE;
if (inputs.has_continuation()) {
const auto & msg = inputs.continue_msg;
data.generation_prompt = GEN_PREFIX + THINK_START + msg.reasoning_content;
if (inputs.continue_final_message == COMMON_CHAT_CONTINUATION_CONTENT) {
data.generation_prompt += THINK_END + TEXT_START + msg.render_content();
}
data.prompt += data.generation_prompt;
}
auto parser = build_chat_peg_parser([&](common_chat_peg_builder & p) {
auto generation_prompt = p.literal(GEN_PREFIX);
auto end = p.end();
// The thinking block is always present (the generation prompt forces <|START_THINKING|>).
// When extracting reasoning, capture its body; otherwise keep the whole block (markers
// included) inline as content, matching reasoning_format=NONE conventions.
common_peg_parser reasoning = p.eps();
if (extract_reasoning) {
reasoning = p.optional(p.literal(THINK_START) +
p.reasoning(p.until_one_of({ THINK_END, TEXT_START, ACTION_START })) +
p.optional(p.literal(THINK_END)));
} else {
reasoning = p.optional(p.content(p.literal(THINK_START) +
p.until_one_of({ THINK_END, TEXT_START, ACTION_START }) +
p.optional(p.literal(THINK_END))));
}
auto text_content = p.literal(TEXT_START) + p.content(p.until(TEXT_END)) + p.optional(p.literal(TEXT_END));
if (!has_tools || inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_NONE) {
return generation_prompt + reasoning + text_content + p.optional(p.literal(TURN_END)) + end;
}
auto require_tools = inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_REQUIRED;
// <|START_ACTION|>[ {"tool_call_id": "0", "tool_name": "f", "parameters": {...}}, ... ]<|END_ACTION|>
auto tool_calls = p.standard_json_tools(ACTION_START, ACTION_END, inputs.tools, inputs.parallel_tool_calls,
/* force_tool_calls = */ true,
/* name_key = */ "tool_name",
/* args_key = */ "parameters",
/* array_wrapped = */ true,
/* function_is_key = */ false,
/* call_id_key = */ "",
/* gen_call_id_key = */ "tool_call_id",
/* parameters_order = */ { "tool_call_id", "tool_name", "parameters" });
// Content and tool calls are mutually exclusive in this format.
common_peg_parser body = require_tools ? tool_calls : p.choice({ tool_calls, text_content });
return generation_prompt + reasoning + body + p.optional(p.literal(TURN_END)) + end;
});
data.parser = parser.save();
if (include_grammar) {
data.grammar_lazy = inputs.tool_choice == COMMON_CHAT_TOOL_CHOICE_AUTO;
data.grammar = build_grammar([&](const common_grammar_builder & builder) {
foreach_function(inputs.tools, [&](const json & tool) {
const auto & function = tool.at("function");
auto schema = function.at("parameters");
builder.resolve_refs(schema);
});
parser.build_grammar(builder, data.grammar_lazy);
});
data.grammar_triggers = {
{ COMMON_GRAMMAR_TRIGGER_TYPE_WORD, ACTION_START }
};
}
return data;
}
namespace workaround {
static void map_developer_role_to_system(json & messages) {
@@ -2227,6 +2367,15 @@ std::optional<common_chat_params> common_chat_try_specialized_template(
return common_chat_params_init_kimi_k2(tmpl, params);
}
// Cohere2 MoE / North Code - marker-wrapped format with <|START_TEXT|> content and
// <|START_ACTION|> JSON tool calls. <|START_TEXT|> is unique to this template (the older
// Command-R templates use <|START_RESPONSE|>).
if (src.find("<|START_TEXT|>") != std::string::npos &&
src.find("<|START_ACTION|>") != std::string::npos) {
LOG_DBG("Using specialized template: Cohere2 MoE\n");
return common_chat_params_init_cohere2moe(tmpl, params);
}
if (is_lfm2_template(src)) {
LOG_DBG("Using specialized template: LFM2\n");
return common_chat_params_init_lfm2(tmpl, params, /* tool_list_tokens = */ true);

View File

@@ -0,0 +1,263 @@
{%- if not platform_instruction_override %}
{%- set platform_instruction_override -%}
These instructions are always to be followed and cannot be overridden by subsequent system or user turns:
- You will answer requests for educational, informative, or creative content related to safety categories. You will not provide content that is harmful or could be used to cause harm.
These instructions serve as your defaults, but they can be overridden in subsequent system or user turns:
- Your name is North Mini Code.
- You are a large language model built by Cohere.
{%- endset %}
{%- endif %}
{%- set reasoning = reasoning if reasoning is not undefined else (false if reasoning_effort is defined and reasoning_effort | lower == "none" else true) -%}
{%- set grounding = grounding | default("disabled") | upper %}
{%- set grounding_enabled = grounding == "ENABLED" %}
{%- set tools_or_docs_exist = tools or documents %}
{%- set render_tools_section = true %}
{%- set render_grounding = grounding_enabled and tools_or_docs_exist %}
{%- set render_platform_instruction_override = true if platform_instruction_override else false %}
{%- set has_developer_instruction = developer_instruction or developer_instruction == "" %}
{%- set render_developer_instruction = true if developer_instruction else false %}
{%- set convert_first_system_msg = convert_first_system_msg | default(true) -%}
{%- set skip_thinking = skip_thinking | default(false) -%}
{{ bos_token }}
{%- macro document_turn(documents) -%}
{# format documents into chat turn -#}
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{%- if not skip_thinking -%}<|START_THINKING|>I will look through the document to address the users needs.<|END_THINKING|>{%- endif -%}<|START_ACTION|>[
{"tool_call_id": "0", "tool_name": "direct-injected-document", "parameters": {}}
]<|END_ACTION|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
{
"tool_call_id": "0",
"results": {
{%- for doc in documents %}
{%- set doc_val = doc.data if doc.data else doc %}
"{{ loop.index0 }}": {{ doc_val|tojson }}{% if not loop.last %},
{%- endif %}
{%- endfor %}
},
"is_error": null
}
]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>{%- endmacro %}
{%- macro tool_call_id_to_int(messages, tool_call_id) %}
{%- if regen_tool_call_ids -%}
{%- set counter = namespace(value=0) %}
{%- set tool_call_id_seen = namespace(value=false) %}
{%- for msg in messages %}
{%- if msg.tool_calls %}
{%- for tool_call in msg.tool_calls %}
{%- if tool_call.id == tool_call_id and not tool_call_id_seen.value -%}
{{ counter.value }}
{%- set tool_call_id_seen.value = true %}
{%- endif %}
{%- set counter.value = counter.value + 1 %}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- else -%}
{{ tool_call_id }}
{%- endif -%}
{%- endmacro %}
{%- macro format_tool_message(messages, tool_msg) -%}
{#- format tool message #}{
"tool_call_id": "{{ tool_call_id_to_int(messages, tool_msg.tool_call_id) }}",
"results": {
{%- if tool_msg.content is mapping or tool_msg.content is string %}
{% if tool_msg.content is string -%}
{%- set text_wrapper = {"content": tool_msg.content} -%}
{%- else -%}
{%- set text_wrapper = tool_msg.content -%}
{%- endif %}
"0": {{ text_wrapper|tojson }}
{%- else %}
{%- for content in tool_msg.content %}
"{{ loop.index0 }}": {{ print_tool_content(content) }}{% if not loop.last %},{% endif %}
{%- endfor %}
{%- endif %}
},
"is_error": null
}
{%- endmacro -%}
{%- macro print_tool_content(item) %}
{%- if item.type|lower == "text" -%}
{%- set text_wrapper = {"content": item.text} -%}
{{ text_wrapper|tojson }}
{%- elif item.type|lower == "document" and item.document and "data" in item.document -%}
{{ item.document.data|tojson }}
{%- else -%}
{{ item|tojson }}
{%- endif -%}
{%- endmacro %}
{%- macro print_msg(msg) %}
{%- if msg is string -%}
<|START_TEXT|>{{ msg }}<|END_TEXT|>
{%- elif msg.content is string -%}
<|START_TEXT|>{{ msg.content }}<|END_TEXT|>
{%- else %}
{%- set last_was_text = namespace(value=false) %}
{%- for content in msg.content %}
{%- if content.type|lower == "text" -%}
{%- if not last_was_text.value -%}
<|START_TEXT|>
{%- endif -%}
{{ content.text }}
{%- if loop.last -%}
<|END_TEXT|>
{%- endif %}
{%- set last_was_text.value = true -%}
{%- else -%}
{%- if last_was_text.value -%}
<|END_TEXT|>
{%- endif -%}
{%- set last_was_text.value = false -%}
{%- endif -%}
{%- if content.type|lower == "image" -%}
{%- if content.data -%}
{{ content.data }}
{%- else -%}
<|IMG_PATCH|>
{%- endif -%}
{%- endif -%}
{%- endfor %}
{%- endif %}
{%- endmacro %}
{%- macro print_thinking(msg) %}
{%- if msg.reasoning -%}
{{ msg.reasoning }}
{%- elif msg.reasoning_content -%}
{{ msg.reasoning_content }}
{%- elif msg.thinking -%}
{{ msg.thinking }}
{%- elif msg.content and msg.content[0].thinking -%}
{{ msg.content[0].thinking }}
{%- endif %}
{%- endmacro %}
{%- if messages and messages[0]['role']|lower == 'system' and not has_developer_instruction and convert_first_system_msg %}{%- set developer_instruction = messages[0] %}{%- set render_developer_instruction = true %}{%- set initial_instruction_message = true %}{% endif %}
{%- set json_object = true if response_format and response_format.type == "json_object" else false %}
{%- set json_schema = (response_format.json_schema or response_format.schema) if response_format %}
{%- set json_mode = json_object or json_schema %}
{%- set tool_idx = namespace(value=0) %}
{%- set tool_ids_seen = namespace(value=[]) %}
{%- set regen_tool_call_ids = regen_tool_call_ids | default(true) -%}
{%- set sent_documents = namespace(value=false) -%}
{%- if render_tools_section or render_platform_instruction_override or render_grounding or json_mode -%}
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TEXT|>
{%- elif not render_developer_instruction -%}
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
{%- endif %}
{%- set rendered_platform_turn_chunk = false %}
{%- if render_platform_instruction_override -%}
{{ platform_instruction_override }}
{% set rendered_platform_turn_chunk = true %}
{%- else %}
{%- endif %}
{%- if render_grounding -%}
{%- if rendered_platform_turn_chunk %}
{% endif -%}
Note that both your responses and reflections can be grounded. Grounding means you associate pieces of texts (called "spans") with those specific tool results that support them (called "sources"). And you use a pair of tags "<co>" and "</co>" to indicate when a span can be grounded onto a list of sources, listing them out in the closing tag. Sources from the same tool call are grouped together and listed as "{tool_call_id}:[{list of result indices}]", before they are joined together by ",". E.g., "<co>span</co: 0:[1,2],1:[0]>" means that "span" is supported by result 1 and 2 from "tool_call_id=0" as well as result 0 from "tool_call_id=1".
{% set rendered_platform_turn_chunk = true %}
{%- endif %}
{%- if render_tools_section %}
{%- if rendered_platform_turn_chunk %}
{% endif %}
# Available Tools
```json
[
{% if tools_or_docs_exist %}
{%- if documents %}
{"name": "direct-injected-document", "description": "This is a special tool to directly inject user-uploaded documents into the chat as additional context. DO NOT use this tool by yourself!", "parameters": {"type": "object", "properties": {}, "required": []}, "responses": {"200": {"description": "Successfully returned a list of chunked text snippets from the directly uploaded documents.", "content": {"application/json": {"schema": {"type": "array", "items": {"type": "object", "required": ["url", "snippet"], "properties": {"url": {"type": "string", "description": "The url of the uploaded document."}, "snippet": {"type": "string", "description": "The text snippet for the returned document chunk."}}}}}}}}}
{%- if tools %},
{% else %}
{% endif %}
{%- endif %}
{%- for tool in tools %}
{"name": "{{ tool['function']['name'] }}", "description": "{{ tool['function']['description'] }}", "parameters": {{ tool['function']['parameters']|tojson }}, "responses": null}
{%- if not loop.last %},{% endif %}
{% endfor %}
{%- else %}
{% endif %}
]
```
{%- set rendered_platform_turn_chunk = true %}
{%- endif -%}
{%- if json_mode -%}
{%- if rendered_platform_turn_chunk %}
{% endif -%}
When generating JSON objects, do not generate block markers. Generate an object directly without prefixing with ```json. Return only the JSON and nothing else.
{%- if json_schema %}
Your output should adhere to the following json schema:
{{ json_schema }}
{%- endif -%}
{%- set rendered_platform_turn_chunk = true %}
{%- endif %}
{%- if rendered_platform_turn_chunk -%}
<|END_TEXT|><|END_OF_TURN_TOKEN|>
{%- elif not render_developer_instruction -%}
<|END_OF_TURN_TOKEN|>
{%- endif %}
{%- if render_developer_instruction -%}
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(developer_instruction) }}<|END_OF_TURN_TOKEN|>
{%- endif %}
{%- for message in messages %}
{%- set msg_role_downcased = message.role | lower %}
{%- if msg_role_downcased == 'system' and (not (loop.first and initial_instruction_message)) -%}
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ print_msg(message) }}<|END_OF_TURN_TOKEN|>
{%- elif msg_role_downcased == 'user' -%}
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ print_msg(message) }}<|END_OF_TURN_TOKEN|>
{%- if documents and not sent_documents.value %}{%- set sent_documents.value = true %}{% set tool_idx.value = tool_idx.value + 1 %}{{ document_turn(documents) }}{% endif %}
{%- elif msg_role_downcased == 'assistant' or msg_role_downcased == 'chatbot' -%}
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
{%- if message.tool_calls %}
{% if not skip_thinking %}
{% if message.tool_plan -%}
<|START_THINKING|>{{ message.tool_plan }}<|END_THINKING|>
{%- elif message.reasoning or message.reasoning_content or message.thinking or (message.content and message.content[0].type == "thinking") -%}
<|START_THINKING|>{{ print_thinking(message) }}<|END_THINKING|>
{%- endif %}
{%- endif %}<|START_ACTION|>[
{%- for tc in message.tool_calls %}
{"tool_call_id": "{%- if regen_tool_call_ids -%}{{ tool_idx.value }}{%- else -%}{{ tc.id }}{%- endif -%}", "tool_name": "{{ tc['function']['name'] }}", "parameters": {{ tc['function']['arguments']|tojson }}}{% if not loop.last %},{% endif %}
{%- set tool_idx.value = tool_idx.value + 1 %}
{%- endfor %}
]<|END_ACTION|><|END_OF_TURN_TOKEN|>
{%- else -%}
{% if (message.reasoning or message.reasoning_content or message.thinking or (message.content and message.content[0].type == "thinking")) and not skip_thinking -%}
<|START_THINKING|>{{ print_thinking(message) }}<|END_THINKING|>
{%- endif -%}
{{ print_msg(message) }}<|END_OF_TURN_TOKEN|>
{%- endif %}
{%- elif msg_role_downcased == 'tool' and message.tool_call_id not in tool_ids_seen.value -%}
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|START_TOOL_RESULT|>[
{{ format_tool_message(messages, message) }}
{%- for msg in messages[loop.index0 + 1:] %}
{%- if msg.role | lower == 'tool' %},
{{ format_tool_message(messages, msg) }}
{%- set tool_ids_seen.value = tool_ids_seen.value + [msg.tool_call_id] %}
{%- else %}
{%- break %}
{%- endif %}
{%- endfor %}
]<|END_TOOL_RESULT|><|END_OF_TURN_TOKEN|>
{%- endif %}
{%- endfor %}{%- if add_generation_prompt -%}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{% if reasoning %}<|START_THINKING|>{% else %}<|START_THINKING|><|END_THINKING|>{% endif %}{%- endif %}

View File

@@ -2644,6 +2644,100 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
.run();
}
{
// Cohere2 MoE (North Code) - dedicated parser.
// Marker-wrapped format: <|START_THINKING|>...<|END_THINKING|> then either
// <|START_TEXT|>...<|END_TEXT|> (content) or <|START_ACTION|>[json]<|END_ACTION|> (tools).
// The generation prompt forces a leading <|START_THINKING|>, so model output begins inside
// the thinking block: test inputs start with the reasoning body, not the <|START_THINKING|> tag.
auto tst = peg_tester("models/templates/Cohere2MoE.jinja", detailed_debug);
// Content with reasoning, extracted.
tst.test("I'm\nthinking<|END_THINKING|><|START_TEXT|>Hello, world!\nWhat's up?<|END_TEXT|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.expect(message_assist_thoughts)
.run();
// Content with reasoning, reasoning_format=NONE -> thinking kept inline in content (markers preserved).
tst.test("I'm\nthinking<|END_THINKING|><|START_TEXT|>Hello, world!\nWhat's up?<|END_TEXT|>")
.expect(message_assist_thoughts_unparsed_r7b)
.run();
// Content with empty thinking block.
tst.test("<|END_THINKING|><|START_TEXT|>Hello, world!\nWhat's up?<|END_TEXT|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.expect(message_assist)
.run();
// Single tool call with reasoning.
tst.test(
"I'm\nthinking<|END_THINKING|>"
"<|START_ACTION|>[\n"
" {\"tool_call_id\": \"0\", \"tool_name\": \"special_function\", \"parameters\": {\"arg1\": 1}}\n"
"]<|END_ACTION|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.tools({ special_function_tool })
.expect(message_assist_thoughts_call_idx)
.run();
// Single tool call, empty thinking block (no reasoning content).
tst.test(
"<|END_THINKING|>"
"<|START_ACTION|>[\n"
" {\"tool_call_id\": \"0\", \"tool_name\": \"special_function\", \"parameters\": {\"arg1\": 1}}\n"
"]<|END_ACTION|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.tools({ special_function_tool })
.expect(message_assist_call_idx)
.run();
// Tool call with an array argument (todo_list).
tst.test(
"<|END_THINKING|>"
"<|START_ACTION|>[\n"
" {\"tool_call_id\": \"0\", \"tool_name\": \"todo_list\", \"parameters\": {\"todos\": [\"buy milk\", \"walk dog\"]}}\n"
"]<|END_ACTION|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.tools({ todo_list })
.expect(simple_assist_msg("", "", "todo_list", "{\"todos\": [\"buy milk\", \"walk dog\"]}", "0"))
.run();
// Parallel tool calls with reasoning.
tst.test(
"I'm\nthinking<|END_THINKING|>"
"<|START_ACTION|>[\n"
" {\"tool_call_id\": \"0\", \"tool_name\": \"special_function\", \"parameters\": {\"arg1\": 1}},\n"
" {\"tool_call_id\": \"1\", \"tool_name\": \"python\", \"parameters\": {\"code\": \"print('hey')\"}}\n"
"]<|END_ACTION|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.parallel_tool_calls(true)
.tools({ special_function_tool, python_tool })
.expect_reasoning("I'm\nthinking")
.expect_tool_calls({
{ "special_function", R"({"arg1": 1})", "0" },
{ "python", "{\"code\": \"print('hey')\"}", "1" },
})
.run();
// Tools available but the model answers with content instead of calling a tool.
tst.test("I'm\nthinking<|END_THINKING|><|START_TEXT|>Hello, world!\nWhat's up?<|END_TEXT|>")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.tools({ special_function_tool })
.expect(message_assist_thoughts)
.run();
// Partial tool call (streaming): name/id resolved before arguments arrive.
tst.test(
"I'm\nthinking<|END_THINKING|>"
"<|START_ACTION|>[\n"
" {\"tool_call_id\": \"0\", \"tool_name\": \"special_function\", ")
.reasoning_format(COMMON_REASONING_FORMAT_DEEPSEEK)
.tools({ special_function_tool })
.is_partial(true)
.expect(message_assist_thoughts_partial_call)
.run();
}
{
// Google Gemma 2 2B - does not support tool calling
auto tst = peg_tester("models/templates/google-gemma-2-2b-it.jinja");