Skip to content

fix(infer): validate explicit tool choices - #9871

Open
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/unknown-tool-choice
Open

fix(infer): validate explicit tool choices#9871
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/unknown-tool-choice

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

An explicit tool_choice can name a function that is absent from the
request's tools list. ChatCompletionRequestMixin intended to report this
as a ValueError, but next() raised StopIteration before the validation
branch could run.

This change gives next() a None default so the existing, actionable error
is raised:

ValueError: Tool choice 'missing' not found in tools.

Valid explicit choices retain the existing behavior of narrowing tools to
the selected function. Automatic and disabled tool selection are unchanged.

Experiment results

Before:

StopIteration: <empty message>

After:

ValueError: Tool choice 'missing' not found in tools.

Verification:

.venv/bin/python tests/run.py --test_dir tests/infer --pattern test_protocol.py
SUCCESS (Runs=2, success=2)

.venv/bin/pre-commit run --files swift/infer_engine/protocol.py tests/infer/test_protocol.py
All hooks passed

Return the intended validation error when an explicit tool choice does not exist in the request's tools list.

Test: python tests/run.py --test_dir tests/infer --pattern test_protocol.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant