[Bug]: MiniCPM5 chat template may lose text after <tool_sep> due to loop-local assignments
まだ誰も着手していません。
評価
調査の方向性
まず、参照されている chat_template.jinja を提供された Jinja2 の再現実装でレンダリングし、84、86、112、116、127 行を調べます。ループローカルな代入が processed_content と has_tool_sep にどのような影響を与えるかを確認します。BEFORE と AFTER の両方が、出力された 1 つのツール XML ブロックの前後に残り、意図した動作が確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Is there an existing issue?
- I searched existing issues for
tool_sep,processed_content,chat_template, andjinjaand did not find this problem reported.
Describe the bug
MiniCPM5-2B's chat template appears to use loop-local set assignments to accumulate processed_content for use after the loops. Jinja2 does not propagate these assignments to the enclosing scope.
With assistant content BEFORE<tool_sep>AFTER and one tool call, the rendered prompt loses AFTER. The tool XML is emitted once by the later direct-output branch.
Template: openbmb/MiniCPM5-2B/chat_template.jinja, revision a063f08de1bd09dfc9ae4cf3da35e6064949e533.
To reproduce
Download the unchanged template as chat_template.jinja, then run this script in the same directory. It only requires Jinja2; no model weights or inference are involved.
from pathlib import Path
from jinja2 import Environment
template = Environment(trim_blocks=True, lstrip_blocks=True).from_string(
Path("chat_template.jinja").read_text(encoding="utf-8")
)
for content in ["BEFORE", "BEFORE<tool_sep>AFTER"]:
output = template.render(
bos_token="",
tools=[],
messages=[
{"role": "user", "content": "Question"},
{
"role": "assistant",
"content": content,
"tool_calls": [
{
"function": {
"name": "lookup",
"arguments": {"q": "weather"},
}
}
],
},
],
add_generation_prompt=False,
)
print("Input:", content)
print("Contains AFTER:", "AFTER" in output)
print("Tool XML count:", output.count('<function name="'))
print(repr(output))
Observed output:
Input: BEFORE
Contains AFTER: False
Tool XML count: 1
'<|im_start|>user\nQuestion<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\nBEFORE\n<function name="lookup"><param name="q">weather</param></function><|im_end|>\n'
Input: BEFORE<tool_sep>AFTER
Contains AFTER: False
Tool XML count: 1
'<|im_start|>user\nQuestion<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\nBEFORE\n<function name="lookup"><param name="q">weather</param></function><|im_end|>\n'
Expected behavior
Assuming <tool_sep> marks an in-place tool-call position, I would expect both surrounding text segments to survive, with the tool XML inserted between BEFORE and AFTER. Could you confirm whether this is the intended behavior?
Environment
- Python 3.12.2
- Jinja2 3.1.3
- Direct rendering of the unchanged template with
Environment(trim_blocks=True, lstrip_blocks=True)
Additional context
The assignments at template lines 84, 86, and 112 are inside nested loops. When line 116 reads processed_content, its enclosing value remains content_parts[0]. Jinja documents this assignment-scoping behavior and the use of namespace objects for cross-scope state.
The final tool-output condition at line 127 also reads has_tool_sep, which is not defined anywhere in this template or supplied by this reproducer. The condition is therefore true for the tool-calling messages above. If accumulation is changed to persist across loops, that final output condition should be reviewed together with it so that each tool call is emitted once.
- 主要言語
- Jupyter Notebook
- スター
- 11.1k
- フォーク
- 766
- 平均マージ
- 5時間 3分
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
OpenBMB/MiniCPM のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
feature
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
OpenBMB/MiniCPM の issue をすべて見る
似ている issue
-
area:ai-suggestions bug good first issue P2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
uttrflow/uttrflow-swift#1922 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
triage/confirmed
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
agentscope-ai/agentscope#2876 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
e2b-dev/awesome-ai-agents#1643 ·
メンテナーはふだん 1 日以内に返信
-
Docs never explain image replay cost with native-vision models or the tools.media.models[] opt-outオープンclawsweeper:linked-pr-open clawsweeper:no-new-fix-pr impact:ux-friction issue-rating: 🌊 off-meta tidepool P2
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openclaw/openclaw#159202 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信