File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1717 SentencePieceTokenizer ,
1818)
1919from mistral_common .tokens .tokenizers .tekken import Tekkenizer
20+ from pydantic import ValidationError
2021
2122from vllm .entrypoints .chat_utils import ChatCompletionMessageParam
2223from vllm .entrypoints .openai .chat_completion .protocol import ChatCompletionRequest
@@ -64,14 +65,16 @@ def maybe_serialize_tool_calls(request: "MistralChatCompletionRequest"):
6465 # TODO: remove when pydantic v2.11 is released
6566 for i , message in enumerate (request .messages ):
6667 if message .get ("role" ) == "assistant" :
67- tool_calls_validator = message .get ("tool_calls" , ().__iter__ ())
68- validated_tool_calls = []
69- while True :
68+ if (tool_calls_validator := message .get ("tool_calls" , None )) is not None :
7069 try :
71- tool_call = next (tool_calls_validator ) # type: ignore
72- validated_tool_calls .append (tool_call )
73- except StopIteration :
74- break
70+ validated_tool_calls = list (tool_calls_validator )
71+ except ValidationError as e :
72+ raise ValueError (
73+ "Validating messages' `tool_calls` raised an error. "
74+ "Please ensure `tool_calls` are iterable of tool calls."
75+ ) from e
76+ else :
77+ validated_tool_calls = []
7578
7679 request .messages [i ]["tool_calls" ] = validated_tool_calls
7780
You can’t perform that action at this time.
0 commit comments