Skip to content

Commit 4ad8ce3

Browse files
authored
[tool] Fix tool calling output formatter (#2721)
1 parent 7fbb447 commit 4ad8ce3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

engines/python/setup/djl_python/output_formatter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ def _json_chat_output_formatter(request_output: TextGenerationOutput):
323323
"finish_reason": best_sequence.finish_reason,
324324
}
325325
elif chat_params and chat_params.tools and (
326-
parameters.get("tool_choice") == "auto"
327-
or parameters.get("tool_choice")
328-
is None) and parameters.get("tool_parser"):
326+
chat_params.tool_choice == "auto"
327+
or chat_params.tool_choice is None) and tool_parser:
329328
tool_call_info = tool_parser.extract_tool_calls(generated_text,
330329
request=chat_params)
331330
auto_tools_called = tool_call_info.tools_called
@@ -408,9 +407,9 @@ def _jsonlines_chat_output_formatter(request_output: TextGenerationOutput):
408407
}
409408
}]
410409
delta = {"tool_calls": tool_calls}
411-
elif parameters.get("tools") and (parameters.get("tool_choice") == "auto"
412-
or parameters.get("tool_choice") is None
413-
) and parameters.get("tool_parser"):
410+
elif chat_params and chat_params.tools and (
411+
chat_params.tool_choice == "auto"
412+
or chat_params.tool_choice is None) and tool_parser:
414413
current_text = get_generated_text(best_sequence, request_output)
415414
previous_text = current_text[0:-len(next_token.text)]
416415
current_token_ids = [t.id for t in best_sequence.tokens]

0 commit comments

Comments
 (0)