From 215bf150a61ed3aafba35df65c95f63c82cc94b2 Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 26 Feb 2025 12:06:21 +0100 Subject: [PATCH] [Bugfix] Handle None parameters in Mistral function calls. (#13786) --- tests/tokenization/test_mistral_tokenizer.py | 35 ++++++++++++++++++- vllm/transformers_utils/tokenizers/mistral.py | 3 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/tokenization/test_mistral_tokenizer.py b/tests/tokenization/test_mistral_tokenizer.py index 03e1f1fa..f1c88028 100644 --- a/tests/tokenization/test_mistral_tokenizer.py +++ b/tests/tokenization/test_mistral_tokenizer.py @@ -41,7 +41,40 @@ from vllm.transformers_utils.tokenizers.mistral import ( ) ], ), - )], + ), + ( + { + "messages": + [{ + "role": "user", + "content": "What is the current local date and time?", + }], + "tools": [{ + "type": "function", + "function": { + "description": "Fetch the current local date and time.", + "name": "get_current_time", + "parameters": None, + }, + }], + }, + ChatCompletionRequest( + messages=[ + UserMessage( + content="What is the current local date and time?") + ], + tools=[ + Tool( + type="function", + function=Function( + name="get_current_time", + description="Fetch the current local date and time.", + parameters={}, + ), + ) + ], + ), + )], ) def test_make_mistral_chat_completion_request(openai_request, expected_mistral_request): diff --git a/vllm/transformers_utils/tokenizers/mistral.py b/vllm/transformers_utils/tokenizers/mistral.py index 4e76f2dc..801597bd 100644 --- a/vllm/transformers_utils/tokenizers/mistral.py +++ b/vllm/transformers_utils/tokenizers/mistral.py @@ -164,7 +164,8 @@ def make_mistral_chat_completion_request( tool["function"] for tool in tools if tool["type"] == "function" ]: - function.setdefault("parameters", {}) + if function.get("parameters") is None: + function["parameters"] = {} from mistral_common.protocol.instruct.request import ChatCompletionRequest return ChatCompletionRequest(messages=messages,