Skip to content

Add OpenAI chat-latest support and generalize token handling#969

Open
PeterDaveHello wants to merge 1 commit intoChatGPTBox-dev:masterfrom
PeterDaveHello:add-openai-chat-latest-model
Open

Add OpenAI chat-latest support and generalize token handling#969
PeterDaveHello wants to merge 1 commit intoChatGPTBox-dev:masterfrom
PeterDaveHello:add-openai-chat-latest-model

Conversation

@PeterDaveHello
Copy link
Copy Markdown
Member

@PeterDaveHello PeterDaveHello commented May 9, 2026

Add the chat-latest OpenAI API preset.

Broaden the OpenAI token-parameter helper naming so chat-latest can share the max_completion_tokens path with GPT-5 latest models.

Reference:

Summary by CodeRabbit

  • New Features
    • Added support for OpenAI's Chat latest model, expanding available model options for API interactions.

Review Change Stack

Add the chat-latest OpenAI API preset.

Broaden the OpenAI token-parameter helper naming so chat-latest can
share the max_completion_tokens path with GPT-5 latest models.

Reference:
- https://developers.openai.com/api/docs/models/chat-latest
@PeterDaveHello PeterDaveHello requested a review from Copilot May 9, 2026 17:40
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 793ca296-3e77-46aa-9fa0-f2e018efab19

📥 Commits

Reviewing files that changed from the base of the PR and between c236a4b and 0b8373d.

📒 Files selected for processing (5)
  • src/config/index.mjs
  • src/services/apis/openai-token-params.mjs
  • tests/unit/services/apis/openai-api-compat.test.mjs
  • tests/unit/services/apis/openai-token-params.test.mjs
  • tests/unit/utils/model-name-convert.test.mjs

📝 Walkthrough

Walkthrough

This PR introduces support for a new OpenAI "chat-latest" model by registering it in the config, updating token parameter selection to use max_completion_tokens for this model, and extending tests across model registration, token behavior, and API compatibility validation.

Changes

OpenAI Chat Latest Model Addition

Layer / File(s) Summary
Model Registry Configuration
src/config/index.mjs
Adds chatgptApiChatLatest to chatgptApiModelKeys array and registers it in the Models map with value 'chat-latest' and description 'OpenAI (Chat latest)'.
Token Parameter Selection Logic
src/services/apis/openai-token-params.mjs
Updates OPENAI_MAX_COMPLETION_TOKENS_MODEL_PATTERN regex to match both gpt-5 variants and chat-latest, enabling max_completion_tokens usage for the new model.
Test Data Setup
tests/unit/services/apis/openai-api-compat.test.mjs
Introduces latestCompatModelNames and latestMappedModels constants defining the "OpenAI latest" model set, replacing GPT-5-specific test data.
API Compatibility Tests
tests/unit/services/apis/openai-api-compat.test.mjs
Validates that requests for "chat-latest" use max_completion_tokens, correctly map model values, and handle token parameter precedence and conflict resolution.
Unit Test Coverage
tests/unit/services/apis/openai-token-params.test.mjs, tests/unit/utils/model-name-convert.test.mjs
Adds direct assertions that 'chat-latest' uses max_completion_tokens, lookalike names use max_tokens, and 'chatgptApiChatLatest' converts to 'chat-latest'.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

Review effort 2/5

Suggested reviewers

  • kmk142789

Poem

🐰 A newest model joins the fold,
chat-latest brave and bold,
With tokens complete, the logic's right,
Tests confirm the feature's tight,
Fresh AI power takes its flight! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the two main changes: adding support for OpenAI's chat-latest model and improving token parameter handling logic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add OpenAI chat-latest model support and generalize token handling

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add OpenAI chat-latest model support to configuration
• Generalize token parameter handling for latest models
• Rename pattern and variables to reflect broader applicability
• Expand test coverage for chat-latest model scenarios
Diagram
flowchart LR
  A["chat-latest Model"] --> B["Config Registration"]
  B --> C["Token Parameter Logic"]
  C --> D["max_completion_tokens Pattern"]
  A --> E["Test Coverage"]
  E --> F["Model Compatibility Tests"]
Loading

Grey Divider

File Changes

1. src/config/index.mjs ⚙️ Configuration changes +2/-0

Register chat-latest model in configuration

• Added chatgptApiChatLatest to the chatgptApiModelKeys array
• Registered new model entry with value chat-latest and description OpenAI (Chat latest)
• Positioned between GPT-4 and GPT-5 models in configuration

src/config/index.mjs


2. src/services/apis/openai-token-params.mjs ✨ Enhancement +2/-2

Generalize token parameter pattern for latest models

• Renamed GPT5_CHAT_COMPLETIONS_MODEL_PATTERN to OPENAI_MAX_COMPLETION_TOKENS_MODEL_PATTERN
• Updated regex pattern to match both gpt-5 variants and chat-latest model
• Pattern now uses alternation: /^(?:gpt-5(?:[.-]|$)|chat-latest$)/

src/services/apis/openai-token-params.mjs


3. tests/unit/services/apis/openai-api-compat.test.mjs 🧪 Tests +14/-12

Update test data and descriptions for latest models

• Renamed gpt5LatestCompatModelNames to latestCompatModelNames and added chat-latest entry
• Renamed gpt5LatestMappedModels to latestMappedModels and added `['chatgptApiChatLatest',
 'chat-latest']` mapping
• Updated 6 test descriptions to reference "latest" models instead of "gpt-5" models
• Updated test loops to use renamed variables for broader model coverage

tests/unit/services/apis/openai-api-compat.test.mjs


View more (2)
4. tests/unit/services/apis/openai-token-params.test.mjs 🧪 Tests +9/-0

Add test cases for chat-latest token handling

• Added new test case for chat-latest model using max_completion_tokens
• Added lookalike model test case my-chat-latest to verify it uses max_tokens
• Ensures pattern matching is precise and doesn't match partial model names

tests/unit/services/apis/openai-token-params.test.mjs


5. tests/unit/utils/model-name-convert.test.mjs 🧪 Tests +1/-0

Add model name conversion test for chat-latest

• Added assertion for chatgptApiChatLatest model name conversion to chat-latest
• Positioned test before other latest model assertions for consistency

tests/unit/utils/model-name-convert.test.mjs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented May 9, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the chat-latest OpenAI model by updating the configuration, logic for token parameters, and relevant unit tests. Specifically, it ensures that the chat-latest model uses max_completion_tokens instead of max_tokens and updates naming conventions in tests to be more generic. I have no feedback to provide.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for OpenAI’s chat-latest model in the API presets and extends the existing “use max_completion_tokens” behavior (previously focused on GPT‑5 chat models) so chat-latest follows the same token-parameter path.

Changes:

  • Add a new preset model key/value (chatgptApiChatLatestchat-latest) in config and model-name conversion coverage.
  • Generalize the OpenAI token-parameter matcher to treat chat-latest like GPT‑5.* models for max_completion_tokens.
  • Expand unit tests to validate the new model mapping and token-param selection (including ensuring lookalikes still use max_tokens).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/utils/model-name-convert.test.mjs Adds coverage that the new preset key maps to chat-latest.
tests/unit/services/apis/openai-token-params.test.mjs Adds coverage for chat-latest using max_completion_tokens and ensures lookalikes don’t match.
tests/unit/services/apis/openai-api-compat.test.mjs Extends “latest compat model” cases to include chat-latest and updates naming/loops accordingly.
src/services/apis/openai-token-params.mjs Generalizes the OpenAI model pattern to include chat-latest.
src/config/index.mjs Adds the new chatgptApiChatLatest preset key to the OpenAI API model list and Models map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants