forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix validation: Only set tool_choice
auto
if at least one tool is p…
…rovided (vllm-project#8568) Signed-off-by: Sumit Dubey <sumit.dubey2@ibm.com>
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
tests/tool_use/test_chat_completion_request_validations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
|
||
from vllm.entrypoints.openai.protocol import ChatCompletionRequest | ||
|
||
|
||
def test_chat_completion_request_with_no_tools(): | ||
# tools key is not present | ||
request = ChatCompletionRequest.model_validate({ | ||
'messages': [{ | ||
'role': 'user', | ||
'content': 'Hello' | ||
}], | ||
'model': | ||
'facebook/opt-125m', | ||
}) | ||
assert request.tool_choice == 'none' | ||
|
||
# tools key is None | ||
request = ChatCompletionRequest.model_validate({ | ||
'messages': [{ | ||
'role': 'user', | ||
'content': 'Hello' | ||
}], | ||
'model': | ||
'facebook/opt-125m', | ||
'tools': | ||
None | ||
}) | ||
assert request.tool_choice == 'none' | ||
|
||
# tools key present but empty | ||
request = ChatCompletionRequest.model_validate({ | ||
'messages': [{ | ||
'role': 'user', | ||
'content': 'Hello' | ||
}], | ||
'model': | ||
'facebook/opt-125m', | ||
'tools': [] | ||
}) | ||
assert request.tool_choice == 'none' | ||
|
||
|
||
def test_chat_completion_request_with_tool_choice_but_no_tools(): | ||
with pytest.raises(ValueError, | ||
match="When using `tool_choice`, `tools` must be set."): | ||
ChatCompletionRequest.model_validate({ | ||
'messages': [{ | ||
'role': 'user', | ||
'content': 'Hello' | ||
}], | ||
'model': | ||
'facebook/opt-125m', | ||
'tool_choice': | ||
'auto' | ||
}) | ||
|
||
with pytest.raises(ValueError, | ||
match="When using `tool_choice`, `tools` must be set."): | ||
ChatCompletionRequest.model_validate({ | ||
'messages': [{ | ||
'role': 'user', | ||
'content': 'Hello' | ||
}], | ||
'model': | ||
'facebook/opt-125m', | ||
'tool_choice': | ||
'auto', | ||
'tools': | ||
None | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters