Skip to content
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

Fix qwen tool template to official format #2988

Merged
merged 3 commits into from
Feb 7, 2025

Conversation

Leoyzen
Copy link
Contributor

@Leoyzen Leoyzen commented Jan 25, 2025

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

当前的 qwen-template(tool)在多个 tools 时,会被解析为如下的格式(例如 13 个工具)

...

## 你可以在回复中插入以下命令以调用这些工具:

✿FUNCTION✿:工具1的名称
✿ARGS✿:工具1的输入
✿RESULT✿:工具1的结果
✿FUNCTION✿:工具2的名称
✿ARGS✿:工具2的输入
✿RESULT✿:工具2的结果
✿FUNCTION✿:工具3的名称
✿ARGS✿:工具3的输入
✿RESULT✿:工具3的结果
✿FUNCTION✿:工具4的名称
✿ARGS✿:工具4的输入
✿RESULT✿:工具4的结果
✿FUNCTION✿:工具5的名称
✿ARGS✿:工具5的输入
✿RESULT✿:工具5的结果
✿FUNCTION✿:工具6的名称
✿ARGS✿:工具6的输入
✿RESULT✿:工具6的结果
✿FUNCTION✿:工具7的名称
✿ARGS✿:工具7的输入
✿RESULT✿:工具7的结果
✿FUNCTION✿:工具8的名称
✿ARGS✿:工具8的输入
✿RESULT✿:工具8的结果
✿FUNCTION✿:工具9的名称
✿ARGS✿:工具9的输入
✿RESULT✿:工具9的结果
✿FUNCTION✿:工具10的名称
✿ARGS✿:工具10的输入
✿RESULT✿:工具10的结果
✿FUNCTION✿:工具11的名称
✿ARGS✿:工具11的输入
✿RESULT✿:工具11的结果
✿FUNCTION✿:工具12的名称
✿ARGS✿:工具12的输入
✿RESULT✿:工具12的结果
✿FUNCTION✿:工具13的名称
✿ARGS✿:工具13的输入
✿RESULT✿:工具13的结果
✿FUNCTION✿:工具14的名称
✿ARGS✿:工具14的输入
✿RESULT✿:工具14的结果

而正确的版本,参考如下链接:

## 你可以在回复中插入以下命令以并行调用N个工具:
 
✿FUNCTION✿: 工具1的名称,必须是[{tool_names}]之一
✿ARGS✿: 工具1的输入
✿FUNCTION✿: 工具2的名称
✿ARGS✿: 工具2的输入
...
✿FUNCTION✿: 工具N的名称
✿ARGS✿: 工具N的输入
✿RESULT✿: 工具1的结果
✿RESULT✿: 工具2的结果
...
✿RESULT✿: 工具N的结果
✿RETURN✿: 根据工具结果进行回复,需将图片用![](url)渲染出来'''

可以看到相比较正确的格式,当前错误有几个:

  1. ✿RESULT✿ 是放在模板最后的
  2. 样例的数量是固定的,和 request中的 tools 数量无关(否则会导致 prefix-caching不能完全发挥作用)
  3. 在第一个工具说明时,会附上所有的工具名称
  4. json.dump处理中文时,会转换为 ascii 格式,导致模型处理中文时出现莫名其妙的问题。需要加入ensure_ascii=False来保证中文等字符的处理。

这个 PR 修正以上错误,和官方版本对齐。

Experiment results

Paste your experiment result here(if needed).

@Leoyzen Leoyzen force-pushed the feature/qwen-tool-template branch from d915e99 to d5f2184 Compare January 26, 2025 08:06
@tastelikefeet tastelikefeet merged commit 3bc2df9 into modelscope:main Feb 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants