Repository navigation
Conversation
With mode ANY and one allowed_function_names entry, Chat Completions requests now send a named function tool_choice instead of "required", matching AnthropicLlm. Fixes google#8100
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
ApigeeLlm(Chat Completions) ignoresFunctionCallingConfig.allowed_function_namesand theVALIDATEDmode #8100Problem:
CompletionsHTTPClient._map_toolsmaps onlyFunctionCallingConfig.mode. Withmode=ANYandallowed_function_names=["lookup_order"], the Chat Completions request carries"tool_choice": "required", so the model may call any declared tool.Solution:
When
mode=ANYhas exactly one allowed name, send the named choice{"type": "function", "function": {"name": ...}}, the same ruleAnthropicLlm._build_tool_choiceuses. Other cases are unchanged ("required"for zero or several names). This PR does not coverVALIDATEDor a multi-name subset (allowed_tools/ filteringtools), which the issue also mentions; that needs a design choice from maintainers.Testing Plan
Unit Tests:
New
test_construct_payload_any_mode_with_allowed_function_names(one name, two names, none). Onmain(59b0dd6) the one-name case fails withassert 'required' == {'function': {'name': 'lookup_order'}, 'type': 'function'}; with the fix:Only that file ran (Python 3.13); the full suite and tox were not run.
pyink --checkandisort --check-onlypass on both files.Manual End-to-End (E2E) Tests:
Not run (no Apigee proxy). The unit test asserts the payload sent to
/chat/completions.Checklist
Additional context
AI-assisted; tests run locally.