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

[tool] Fix tool calling output format #2720

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def parse_chat_completions_request_vllm(
"sampling_params": sampling_params,
"conversation": conversation,
"request_prompts": request_prompt,
"engine_prompt": engine_prompt
"engine_prompt": engine_prompt,
"tool_parser": tool_parser,
"chat_params": chat_params,
}
return input_text, params

Expand Down Expand Up @@ -136,7 +138,7 @@ def _preprocess_chat(

should_parse_tools = tool_parser is not None and request.tool_choice != "none"
if should_parse_tools:
request = tool_parser(tokenizer).adjust_request(request=request)
request = tool_parser.adjust_request(request=request)

if isinstance(request_prompt, str):
# Hf tokenizer case
Expand Down
7 changes: 4 additions & 3 deletions engines/python/setup/djl_python/output_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ def _json_chat_output_formatter(request_output: TextGenerationOutput):
"logprobs": None,
"finish_reason": best_sequence.finish_reason,
}
elif parameters.get("tools") and (parameters.get("tool_choice") == "auto"
or parameters.get("tool_choice") is None
) and parameters.get("tool_parser"):
elif chat_params and chat_params.tools and (
parameters.get("tool_choice") == "auto"
or parameters.get("tool_choice")
is None) and parameters.get("tool_parser"):
tool_call_info = tool_parser.extract_tool_calls(generated_text,
request=chat_params)
auto_tools_called = tool_call_info.tools_called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def __init__(self, model_id_or_path: str, properties: dict,
try:
self.tool_parser = ToolParserManager.get_tool_parser(
self.vllm_configs.tool_call_parser)
self.tool_parser = self.tool_parser(
self.engine.tokenizer.tokenizer)
except Exception as e:
raise TypeError("Error in tool parser creation.") from e

Expand Down
Loading