Skip to content

fix(api): honour max_completion_tokens in Chat Completions requests - #2629

Open
chaitanya0305 wants to merge 1 commit into
exo-explore:mainfrom
chaitanya0305:fix/chat-max-completion-tokens
Open

chaitanya0305 wants to merge 1 commit into
exo-explore:mainfrom
chaitanya0305:fix/chat-max-completion-tokens

Conversation

@chaitanya0305

Copy link
Copy Markdown

Motivation

OpenAI deprecated max_tokens in favour of max_completion_tokens in Chat Completions. Its SDKs and many clients now send only the new name; for example, langchain_openai.ChatOpenAI(max_tokens=...) sends max_completion_tokens. ChatCompletionRequest didn't declare the field, so pydantic dropped it. Such a request ran with no limit, up to the MAX_TOKENS default of 32168, and never finished with "length".

client.chat.completions.create(model=..., messages=[...], max_completion_tokens=16)
# generates until EOS or 32168 tokens; finish_reason is never "length"

Changes

  • Add max_completion_tokens to ChatCompletionRequest.
  • chat_request_to_text_generation takes it as max_output_tokens, ahead of max_tokens when both are given (the newer field is the one current clients mean).
  • Document the parameter in docs/api.md.

Why It Works

Both names now reach TextGenerationTaskParams.max_output_tokens. The generators, the context-length check and the length finish reason already read that field.

Test Plan

Automated Testing

  • New src/exo/api/tests/test_chat_completions_request.py covers max_tokens only, max_completion_tokens only, both, and neither. The two cases with max_completion_tokens fail on main.
  • ruff check, ruff format --check and basedpyright are clean on the changed files.

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>
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