Skip to content

Commit 0e8f4f0

Browse files
authored
fix parse tools (#3975)
1 parent 4dd1137 commit 0e8f4f0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

docs/source/Instruction/Agent支持.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ tools = [{
185185

186186
## loss_scale的使用
187187

188-
loss_scale可以对模型输出部分的训练损失权重进行调节。例如在ReACT格式中,可以设置`--loss_scale react`(loss_scale配置文件书写在[这里](https://github.com/modelscope/swift/blob/main/swift/plugin/loss_scale/config/default_loss_scale_config.json)),该参数起到的作用是:
188+
loss_scale可以对模型输出部分的训练损失权重进行调节。例如在ReACT格式中,可以设置`--loss_scale react`(loss_scale配置文件书写在[这里](https://github.com/modelscope/swift/blob/main/swift/plugin/loss_scale/config/react.json)),该参数起到的作用是:
189189

190190
'Thought:'和'Final Answer:'部分权重为1,'Action:'和'Action Input:'部分权重为2,'Observation:'字段本身权重为2,'Observation:'后面的工具调用结果权重为0。
191191

docs/source_en/Instruction/Agent-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ tools = [{
190190

191191
## Usage of loss_scale
192192

193-
`loss_scale` can be used to adjust the training loss weight for the model's output section. For example, in the ReACT format, you can set `--loss_scale react` (the loss_scale configuration file is written [here](https://github.com/modelscope/swift/blob/main/swift/plugin/loss_scale/config/default_loss_scale_config.json)). The role of this parameter is as follows:
193+
`loss_scale` can be used to adjust the training loss weight for the model's output section. For example, in the ReACT format, you can set `--loss_scale react` (the loss_scale configuration file is written [here](https://github.com/modelscope/swift/blob/main/swift/plugin/loss_scale/config/react.json)). The role of this parameter is as follows:
194194

195195
- The weight for the 'Thought:' and 'Final Answer:' sections is 1.
196196
- The weight for the 'Action:' and 'Action Input:' sections is 2.

swift/llm/template/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,14 @@ def _preprocess_function_call(self, inputs: StdTemplateInputs) -> None:
188188
agent_template = self.agent_template
189189
agent_template.template_meta = self.template_meta # for hermes
190190
if inputs.tools:
191-
inputs.tools = [agent_template._parse_json(tool) for tool in inputs.tools]
191+
if isinstance(inputs.tools, str):
192+
inputs.tools = agent_template._parse_json(inputs.tools)
193+
if not isinstance(inputs.tools, (list, tuple)):
194+
inputs.tools = [inputs.tools]
195+
elif isinstance(inputs.tools, (list, tuple)):
196+
inputs.tools = [agent_template._parse_json(tool) for tool in inputs.tools]
197+
else:
198+
raise ValueError(f'inputs.tools: {inputs.tools}')
192199
for i, tool in enumerate(inputs.tools):
193200
inputs.tools[i] = agent_template.wrap_tool(tool)
194201
i = 0

0 commit comments

Comments
 (0)