-
Notifications
You must be signed in to change notification settings - Fork 40
Add support for Qwen3-4B-Instruct and add model-template mappings #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
795c156
33e1251
b3f4492
c445ff1
bc26dea
45bfb7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from constant import MODEL_TEMPLATE_MAP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -67,6 +68,25 @@ def register_template( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stop_word="<|im_end|>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| register_template( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template_name="qwen3", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system_format="<|im_start|>system\n{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_format="<|im_start|>user\n{content}<|im_end|>\n<|im_start|>assistant\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assistant_format="{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tool_format = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# Tools\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "You may call one or more functions to assist with the user query.\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "You are provided with function signatures within <tools></tools> XML tags:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "<tools>\n{content}\n</tools>\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function_format="<tool_call>\n{content}\n</tool_call><|im_end|>\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| observation_format="<|im_start|>user\n<tool_response>\n{content}\n</tool_response><|im_end|>\n<|im_start|>assistant\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system="You are a helpful assistant.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stop_word="<|im_end|>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFix unescaped braces in qwen3 tool_format; .format() will crash. The JSON example in tool_format includes bare - tool_format = (
+ tool_format = (
"# Tools\n\n"
"You may call one or more functions to assist with the user query.\n\n"
"You are provided with function signatures within <tools></tools> XML tags:\n"
"<tools>\n{content}\n</tools>\n\n"
"For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n"
- "<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>"
+ "<tool_call>\n{{\"name\": <function-name>, \"arguments\": <args-json-object>}}\n</tool_call>"
),If you want, I can add a quick unit test that formats every template field with 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "---- show src/core/template.py (1-240) ----"
nl -ba src/core/template.py | sed -n '1,240p' || true
echo
echo "---- rg register_template calls ----"
rg -n "register_template\(" || true
echo
echo "---- rg def register_template ----"
rg -n "def register_template" || true
echo
echo "---- rg .format( occurrences (2 lines context) ----"
rg -n --hidden --no-ignore-vcs "\.format\(" -S -g '!**/node_modules/**' -C2 || true
echo
echo "---- rg {content} occurrences (2 lines context) ----"
rg -n --hidden --no-ignore-vcs "\{content\}" -S -C2 -g '!**/node_modules/**' || true
echo
echo "---- rg tool_format occurrences ----"
rg -n "tool_format" -S || trueLength of output: 2408 Escape braces in qwen3 tool_format — fix str.format() crash Unescaped JSON braces in the qwen3 tool_format will be parsed by str.format() and raise a ValueError at runtime (see src/core/dataset.py:49 where .format(...) is called). Fix by doubling the literal braces in the JSON example. File: src/core/template.py (register_template qwen3, ~lines 71-88) - tool_format = (
+ tool_format = (
"# Tools\n\n"
"You may call one or more functions to assist with the user query.\n\n"
"You are provided with function signatures within <tools></tools> XML tags:\n"
"<tools>\n{content}\n</tools>\n\n"
"For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n"
- "<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>"
+ "<tool_call>\n{{\"name\": <function-name>, \"arguments\": <args-json-object>}}\n</tool_call>"
),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| register_template( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template_name="yi", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system_format="<|im_start|>system\n{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -182,3 +202,6 @@ def register_template( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stop_word="<|end|>", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for model_name, template_name in MODEL_TEMPLATE_MAP.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template_dict[model_name] = template_dict[template_name] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+206
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Copy and validate when aliasing templates to avoid KeyError and shared-state bugs.
-for model_name, template_name in MODEL_TEMPLATE_MAP.items():
- template_dict[model_name] = template_dict[template_name]
+missing = []
+for model_name, template_name in MODEL_TEMPLATE_MAP.items():
+ base = template_dict.get(template_name)
+ if base is None:
+ missing.append((model_name, template_name))
+ continue
+ # copy to avoid shared object between aliases
+ template_dict[model_name] = replace(base)
+if missing:
+ raise KeyError(f"MODEL_TEMPLATE_MAP points to unknown template(s): {missing}")Add import (outside the changed hunk) to support replace: -from dataclasses import dataclass
+from dataclasses import dataclass, replace📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use package-relative import to avoid import errors with src/ layout.
Direct
from constant import ...will fail when imported as a package. Prefer a relative import (optionally keep a fallback for ad-hoc scripts).📝 Committable suggestion
🤖 Prompt for AI Agents