samarthputhraya opened a new pull request, #1499:
URL: https://github.com/apache/flink-agents/pull/1499

   Linked issue: #1478
   
   ### Purpose of change
   
   The Azure OpenAI setups exposed `max_tokens`, but the two languages sent it 
differently: Java sent `max_completion_tokens`, while Python sent `max_tokens`. 
Reasoning deployments reject `max_tokens`: Microsoft's [API 
reference](https://learn.microsoft.com/en-us/rest/api/microsoft-foundry/azureopenai/chat)
 marks it deprecated and "not compatible with o1 series models". Both setups 
now take `max_completion_tokens` in Java, Python and YAML, and send it under 
that name. As agreed on #1478, a deployment that only accepts the older field 
can leave the typed setting unset and pass `max_tokens` through 
`additional_kwargs`.
   
   ### Behavioral Semantics
   
   | Configuration                                                       | Sent 
                                                                        |
   | ------------------------------------------------------------------- | 
---------------------------------------------------------------------------- |
   | `max_completion_tokens: N`                                          | 
`max_completion_tokens: N`                                                   |
   | nothing set                                                         | 
neither field                                                                |
   | `additional_kwargs: {max_tokens: N}`                                | 
`max_tokens: N`, as given, not renamed                                       |
   | `additional_kwargs: {max_completion_tokens: N}`                     | 
rejected as a reserved typed field, like `temperature`                       |
   | `max_completion_tokens` and `additional_kwargs.max_tokens` together | 
both, as configured (the docs say not to)                                    |
   | the old `max_tokens: N` setting                                     | 
Python: `ValidationError` at construction (`extra="forbid"`); Java: not read |
   | `max_completion_tokens` of 0 or less                                | 
rejected at construction                                                     |
   
   - The old typed setting has no alias, matching the Chat Completions rename 
in #1470.
   - In both connections the reserved `additional_kwargs` keys swap 
`max_tokens` for `max_completion_tokens`. The typed field keeps its collision 
check, and `max_tokens` becomes a passthrough.
   
   ### Tests
   
   - Java (JDK 17): `AzureOpenAIChatModelSetupTest` sends one call from the 
setup's parameters through a loopback endpoint, then parses the body with 
Jackson's duplicate-member detection on. It covers the limit set, the limit 
unset, the `max_tokens` passthrough, and `max_completion_tokens` in 
`additional_kwargs` being rejected. It also checks validation at 0 and -5, and 
that the old argument is not read. The module's 240 tests pass on top of 
current `main`, and Spotless is clean.
   - Python 3.12: `test_azure_openai_token_limit.py` captures the HTTP body 
through `httpx.MockTransport`, with a JSON hook that fails on a repeated 
member. It covers the same cases, plus `max_tokens` rejected at construction 
and a setup loaded from YAML. The Azure tests: 85 passed, 2 live tests skipped. 
Across `chat_models` and `api` with `-m "not integration"`, this branch and 
`main` fail the same 17 tests and hit the same 15 collection errors here, all 
from optional modules not installed locally (`dashscope`, `ibm_watsonx_ai`, 
`importlib_resources`, part of `anthropic`). Ruff is clean.
   - Nothing was run against Azure.
   
   ### API
   
   Yes. The Azure OpenAI setup's `max_tokens` becomes `max_completion_tokens` 
in Java, Python and YAML, with no alias, under the beta compatibility policy. 
`additional_kwargs` now accepts `max_tokens` and reserves 
`max_completion_tokens`.
   
   ### Documentation
   
   - [ ] `doc-needed`
   - [ ] `doc-not-needed`
   - [x] `doc-included`
   
   `providers.md` updates both Azure setup tables and both usage examples, and 
adds a hint:
   
   - Azure accepts `max_completion_tokens` from API version `2024-10-21` and on 
the v1 API. It was added in `2024-09-01-preview` (Microsoft's API version 
lifecycle page), and the `2024-06-01` GA spec doesn't define it.
   - For an older model (the FAQ names `gpt-4` `turbo-2024-04-09`), an older 
API version or a gateway, leave the typed setting unset and pass `max_tokens` 
in `additional_kwargs`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [ ] Yes
   - [ ] No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to