Skip to content

Commit 7fbb447

Browse files
authored
[tool] Fix tool calling output format (#2720)
1 parent 390fc69 commit 7fbb447

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

engines/python/setup/djl_python/chat_completions/vllm_chat_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def parse_chat_completions_request_vllm(
8888
"sampling_params": sampling_params,
8989
"conversation": conversation,
9090
"request_prompts": request_prompt,
91-
"engine_prompt": engine_prompt
91+
"engine_prompt": engine_prompt,
92+
"tool_parser": tool_parser,
93+
"chat_params": chat_params,
9294
}
9395
return input_text, params
9496

@@ -136,7 +138,7 @@ def _preprocess_chat(
136138

137139
should_parse_tools = tool_parser is not None and request.tool_choice != "none"
138140
if should_parse_tools:
139-
request = tool_parser(tokenizer).adjust_request(request=request)
141+
request = tool_parser.adjust_request(request=request)
140142

141143
if isinstance(request_prompt, str):
142144
# Hf tokenizer case

engines/python/setup/djl_python/output_formatter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ def _json_chat_output_formatter(request_output: TextGenerationOutput):
322322
"logprobs": None,
323323
"finish_reason": best_sequence.finish_reason,
324324
}
325-
elif parameters.get("tools") and (parameters.get("tool_choice") == "auto"
326-
or parameters.get("tool_choice") is None
327-
) and parameters.get("tool_parser"):
325+
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"):
328329
tool_call_info = tool_parser.extract_tool_calls(generated_text,
329330
request=chat_params)
330331
auto_tools_called = tool_call_info.tools_called

engines/python/setup/djl_python/rolling_batch/vllm_rolling_batch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def __init__(self, model_id_or_path: str, properties: dict,
5757
try:
5858
self.tool_parser = ToolParserManager.get_tool_parser(
5959
self.vllm_configs.tool_call_parser)
60+
self.tool_parser = self.tool_parser(
61+
self.engine.tokenizer.tokenizer)
6062
except Exception as e:
6163
raise TypeError("Error in tool parser creation.") from e
6264

0 commit comments

Comments
 (0)