Repository navigation
fix(api): honour max_completion_tokens in Chat Completions requests - #2629
Open
chaitanya0305 wants to merge 1 commit into
Open
chaitanya0305 wants to merge 1 commit into
chaitanya0305 wants to merge 1 commit into
Conversation
OpenAI deprecated max_tokens for max_completion_tokens, and its SDKs and many clients (e.g. langchain-openai) now send only the new name. exo dropped the unknown field, so such requests had no limit: they ran to the default of 32168 tokens and never finished with "length". max_completion_tokens now sets the limit, ahead of max_tokens when both are given. Signed-off-by: Chaitanya Deshpande <dcchaitanyadeshpande@gmail.com>
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.
Motivation
OpenAI deprecated
max_tokensin favour ofmax_completion_tokensin Chat Completions. Its SDKs and many clients now send only the new name; for example,langchain_openai.ChatOpenAI(max_tokens=...)sendsmax_completion_tokens.ChatCompletionRequestdidn't declare the field, so pydantic dropped it. Such a request ran with no limit, up to theMAX_TOKENSdefault of 32168, and never finished with"length".Changes
max_completion_tokenstoChatCompletionRequest.chat_request_to_text_generationtakes it asmax_output_tokens, ahead ofmax_tokenswhen both are given (the newer field is the one current clients mean).docs/api.md.Why It Works
Both names now reach
TextGenerationTaskParams.max_output_tokens. The generators, the context-length check and thelengthfinish reason already read that field.Test Plan
Automated Testing
src/exo/api/tests/test_chat_completions_request.pycoversmax_tokensonly,max_completion_tokensonly, both, and neither. The two cases withmax_completion_tokensfail onmain.ruff check,ruff format --checkandbasedpyrightare clean on the changed files.