File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -469,12 +469,19 @@ async def _preprocess_chat(
469469
470470 mm_data = await mm_data_future
471471
472- if tool_parser is not None :
472+ # tool parsing is done only if a tool_parser has been set and if
473+ # tool_choice is not "none" (if tool_choice is "none" but a tool_parser
474+ # is set, we want to prevent parsing a tool_call hallucinated by the LLM
475+ should_parse_tools = tool_parser is not None and (hasattr (
476+ request , "tool_choice" ) and request .tool_choice != "none" )
477+
478+ if should_parse_tools :
473479 if not isinstance (request , ChatCompletionRequest ):
474480 msg = "Tool usage is only supported for Chat Completions API"
475481 raise NotImplementedError (msg )
476482
477- request = tool_parser (tokenizer ).adjust_request (request = request )
483+ request = tool_parser (tokenizer ).adjust_request ( # type: ignore
484+ request = request )
478485
479486 if isinstance (request_prompt , str ):
480487 prompt_inputs = self ._tokenize_prompt_input (
You can’t perform that action at this time.
0 commit comments