[data] add minicpm5 template with XML tool calling (#10801)

Co-authored-by: Caldalis <zyk_computer@163.com>
This commit is contained in:
zyk_computer
2026-08-31 13:16:20 +08:00
committed by GitHub
parent 7fcf5b3b13
commit 6f38e73b82
6 changed files with 180 additions and 3 deletions

View File

@@ -150,6 +150,12 @@ class Template:
elements += self.format_prefix.apply()
if system or tools:
tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
if tools and not system:
# Tool prompts that separate themselves from the system message with a
# leading newline would otherwise emit a blank line when there is no
# system message to separate from.
tool_text = tool_text.lstrip("\n")
elements += self.format_system.apply(content=(system + tool_text))
if message["role"] == Role.USER:
@@ -1823,6 +1829,23 @@ register_template(
)
register_template(
name="minicpm5",
format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="minicpm5"),
format_observation=StringFormatter(
slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
),
format_tools=ToolFormatter(tool_format="minicpm5"),
format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
stop_words=["<|im_end|>"],
replace_eos=True,
template_class=ReasoningTemplate,
)
register_template(
name="minimax1",
format_user=StringFormatter(