Skip to content

Conversation

@DreamRivulet
Copy link
Contributor

@DreamRivulet DreamRivulet commented Aug 9, 2025

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

New Feature:

  • Add support for new model GPT-5
  • Adapt logic for temperature and max_completion_tokens for GPT-5

Summary by CodeRabbit

  • New Features

    • Added support for multiple new GPT-5 models, including vision-capable variants.
    • Enhanced recognition and handling of GPT-5 models in chat and vision features.
  • Bug Fixes

    • Improved parameter handling for GPT-5 models to ensure correct temperature and token limits are applied.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 9, 2025

Walkthrough

Support for GPT-5 models has been added by updating model recognition, vision model regexes, and request payload logic. The code now applies GPT-5-specific handling for temperature and token parameters in chat requests and extends the list of recognized OpenAI models and vision-capable models to include several GPT-5 variants.

Changes

Cohort / File(s) Change Summary
OpenAI Model Handling and Payload Logic
app/client/platforms/openai.ts
Introduces isGpt5 flag to detect GPT-5 models; adjusts temperature logic to treat GPT-5 like O1/O3/O4-mini; for GPT-5, replaces max_tokens with max_completion_tokens in chat payload; vision model token logic excludes GPT-5 and O1/O3.
Model and Vision Regex Constants
app/constant.ts
Adds /gpt-5/ to VISION_MODEL_REGEXES; appends five GPT-5 model strings to openaiModels array.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatClient
    participant ChatGPTApi
    participant OpenAI

    User->>ChatClient: Sends chat request (selects model)
    ChatClient->>ChatGPTApi: Calls chat() with model, temperature, max_tokens
    ChatGPTApi->>ChatGPTApi: Detects model type (O1/O3/O4-mini/GPT-5/other)
    ChatGPTApi->>ChatGPTApi: Adjusts temperature and token params based on model
    ChatGPTApi->>OpenAI: Sends constructed payload
    OpenAI-->>ChatGPTApi: Returns response
    ChatGPTApi-->>ChatClient: Returns processed response
    ChatClient-->>User: Displays result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

planned

Suggested reviewers

  • Dogtiti
  • mayfwl

Poem

🐇
New models hop into the code,
GPT-5 joins the OpenAI road.
Regex and payloads, all in line,
Vision and chat now intertwine.
With tokens and temps set just right,
The code leaps forward, pure delight!
— A rabbit, coding through the night.

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
app/constant.ts (1)

521-526: Add KnowledgeCutOffDate entries for GPT‑5 variants

Without entries, the UI will fall back to the default 2021‑09 cutoff. Add mappings for:

  • gpt-5, gpt-5-chat, gpt-5-chat-2025-01-01-preview, gpt-5-mini, gpt-5-nano.

Once you confirm the official cutoff dates, I can open a follow-up PR to add them. Do you want me to draft it?

app/client/platforms/openai.ts (1)

263-265: Reduce duplication by factoring a single guard for “completion tokens” family

You repeat “!isO1OrO3 && !isGpt5”. Extract a helper boolean to avoid future drift and keep token logic consistent.

Within this block:

-      if (visionModel && !isO1OrO3 && ! isGpt5) {
+      const usesMaxCompletionTokens = isO1OrO3 || isGpt5;
+      if (visionModel && !usesMaxCompletionTokens) {
         requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
       }

Add the helper near the other guards (isDalle3/isO1OrO3/isGpt5) to keep scope tight.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 557a2cc and 38ac502.

📒 Files selected for processing (2)
  • app/client/platforms/openai.ts (3 hunks)
  • app/constant.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-07-31T09:13:27.479Z
Learnt from: Little-LittleProgrammer
PR: ChatGPTNextWeb/NextChat#6588
File: app/components/tts-config.tsx:90-90
Timestamp: 2025-07-31T09:13:27.479Z
Learning: In app/components/tts-config.tsx, the non-null assertion operator (!) on TTS_CONFIGS[props.ttsConfig.engine] is safe because: 1) TTSEngineType is a union type that exactly matches TTS_CONFIGS keys, 2) dropdown options are generated from Object.keys(TTS_CONFIGS) constraining user input, 3) TTS_CONFIGS is typed as Record<TTSEngineType, TTSConfigItem> guaranteeing key-value correspondence.

Applied to files:

  • app/client/platforms/openai.ts
📚 Learning: 2025-07-31T09:13:27.479Z
Learnt from: Little-LittleProgrammer
PR: ChatGPTNextWeb/NextChat#6588
File: app/components/tts-config.tsx:90-90
Timestamp: 2025-07-31T09:13:27.479Z
Learning: In app/components/tts-config.tsx, the non-null assertion operator (!) on TTS_CONFIGS[props.ttsConfig.engine] is safe because the engine values are constrained to keys that exist in TTS_CONFIGS through the dropdown generation (Object.keys(TTS_CONFIGS)) and validation (TTSConfigValidator.engine()).

Applied to files:

  • app/client/platforms/openai.ts
🔇 Additional comments (2)
app/client/platforms/openai.ts (2)

203-203: LGTM: Simple and robust GPT‑5 family detection

startsWith("gpt-5") aligns with the new model IDs added in constants.


242-249: Confirmed GPT-5 uses max_completion_tokens and omits max_tokens
The change to remove max_tokens and set max_completion_tokens for GPT-5 (mirroring o1/o3 models) aligns with the latest OpenAI API. No further adjustments are needed.

Comment on lines +234 to 238
temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
top_p: !isO1OrO3 ? modelConfig.top_p : 1,
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Confirm intent: forcing temperature=1 for GPT‑5

You’re forcing temperature=1 for GPT‑5 (similar to o1/o3/o4-mini) but leaving other sampling params (top_p, penalties) unchanged. Verify this matches GPT‑5 API semantics.

Optionally, extract a single guard to clarify intent:

-        temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
+        // If GPT‑5 requires fixed temperature, keep 1; otherwise pass-through.
+        temperature: (isO1OrO3 || isGpt5) ? 1 : modelConfig.temperature,

🌐 Web query:

For OpenAI GPT-5 chat/completions, should temperature be fixed (e.g., 1 or 0) or is it supported like standard GPT models? Are presence_penalty, frequency_penalty, and top_p supported for GPT-5?

💡 Result:

Yes, OpenAI's GPT-5 model supports the temperature, top_p, presence_penalty, and frequency_penalty parameters in its chat/completions API, similar to previous GPT models. These parameters allow you to control various aspects of the model's output:

  • temperature: Controls the randomness of the model's responses. Lower values (e.g., 0.2) make the output more deterministic, while higher values (e.g., 0.8) increase randomness and creativity. (medium.com)

  • top_p: Also known as nucleus sampling, this parameter determines the cumulative probability threshold for token selection. A value of 0.9 means the model considers the smallest set of tokens whose cumulative probability is at least 90%. (medium.com)

  • presence_penalty: Encourages the model to introduce new topics by penalizing tokens that have already appeared in the text. Positive values increase the likelihood of discussing new topics. (notes.kodekloud.com)

  • frequency_penalty: Reduces the model's tendency to repeat the same tokens by penalizing tokens based on their existing frequency in the text. Positive values decrease the likelihood of repetition. (notes.kodekloud.com)

These parameters are designed to be flexible and can be adjusted to suit your specific application needs. For example, setting temperature to 0.0 and top_p to 0.0 can produce deterministic outputs, while higher values can generate more diverse and creative responses. (notes.kodekloud.com)

It's important to note that while these parameters are supported in GPT-5, the optimal settings may vary depending on your specific use case and desired output characteristics.

Citations:


Remove GPT-5 special-case for temperature

GPT-5 supports temperature, top_p, presence_penalty, and frequency_penalty just like other GPT models. We shouldn’t force temperature = 1 only for GPT-5—let it use modelConfig.temperature unless we have a clear reason to pin it. Please update in app/client/platforms/openai.ts around lines 234–238:

-        temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
+        // Only force temperature=1 for O1/O3; GPT-5 should respect the configured value.
+        temperature: isO1OrO3 ? 1 : modelConfig.temperature,
         presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
         frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
         top_p: !isO1OrO3 ? modelConfig.top_p : 1,

This removes the isGpt5 check so GPT-5 calls remain configurable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
temperature: (!isO1OrO3 && !isGpt5) ? modelConfig.temperature : 1,
presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
top_p: !isO1OrO3 ? modelConfig.top_p : 1,
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
// Only force temperature=1 for O1/O3; GPT-5 should respect the configured value.
temperature: isO1OrO3 ? 1 : modelConfig.temperature,
presence_penalty: !isO1OrO3 ? modelConfig.presence_penalty : 0,
frequency_penalty: !isO1OrO3 ? modelConfig.frequency_penalty : 0,
top_p: !isO1OrO3 ? modelConfig.top_p : 1,
// max_tokens: Math.max(modelConfig.max_tokens, 1024),
🤖 Prompt for AI Agents
In app/client/platforms/openai.ts around lines 234 to 238, remove the
special-case check for GPT-5 in the temperature setting. Update the temperature
assignment to use modelConfig.temperature for all models, including GPT-5, by
eliminating the isGpt5 condition. Ensure presence_penalty, frequency_penalty,
and top_p remain conditional only on isO1OrO3 as before, without affecting GPT-5
handling.

Comment on lines +242 to +247
if (isGpt5) {
// Remove max_tokens if present
delete requestPayload.max_tokens;
// Add max_completion_tokens (or max_completion_tokens if that's what you meant)
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

TS safety and clarity: avoid deleting from a union-typed payload; set max_completion_tokens via a narrowed alias

delete on a union (RequestPayload | DalleRequestPayload) can trip TS checks. Also the comment repeats “max_completion_tokens”.

Apply:

-      if (isGpt5) {
-  	// Remove max_tokens if present
-  	delete requestPayload.max_tokens;
-  	// Add max_completion_tokens (or max_completion_tokens if that's what you meant)
-  	requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
-      } else if (isO1OrO3) {
+      if (isGpt5) {
+        // GPT‑5 uses max_completion_tokens
+        const payload = requestPayload as RequestPayload;
+        payload.max_completion_tokens = modelConfig.max_tokens;
+      } else if (isO1OrO3) {

This avoids delete on a union and fixes the comment.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isGpt5) {
// Remove max_tokens if present
delete requestPayload.max_tokens;
// Add max_completion_tokens (or max_completion_tokens if that's what you meant)
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
if (isGpt5) {
// GPT-5 uses max_completion_tokens
const payload = requestPayload as RequestPayload;
payload.max_completion_tokens = modelConfig.max_tokens;
} else if (isO1OrO3) {
🤖 Prompt for AI Agents
In app/client/platforms/openai.ts around lines 242 to 247, avoid using delete on
a union-typed requestPayload as it causes TypeScript errors. Instead, create a
narrowed alias for the payload type that allows safe modification, then set
max_completion_tokens on that alias. Also, correct the comment to remove the
repeated phrase "max_completion_tokens" for clarity.

Comment on lines +496 to 497
/gpt-5/
];
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Avoid blanket vision classification for all GPT‑5 variants

Using /gpt-5/ will flag nano/mini variants as vision-capable, which may cause image payloads to be sent to text-only models. Narrow the regex.

Apply:

-  /grok-4/i,
-  /gpt-5/
+  /grok-4/i,
+  /gpt-5(?!-(nano|mini))/

If specific GPT‑5 vision SKUs differ, switch to an explicit allowlist instead of a broad regex. Please verify GPT‑5 nano/mini image-input support in current docs.


🌐 Web query:

Which OpenAI GPT-5 model variants support image inputs via the chat/completions API? Specifically, do "gpt-5-mini" and "gpt-5-nano" accept vision (image_url) content?

💡 Result:

GPT-5 Full supports image (vision) inputs via the chat/completions API, but gpt-5-mini and gpt-5-nano are either limited or do not have native support for image (image_url) content as input.

Details and evidence:

  • GPT-5 Full is clearly described in official model documentation and API guides as accepting both text and image inputs for chat/completions, with a 400,000 token context window[3][5]. Multiple sources confirm that the flagship GPT-5 is a multimodal model designed to handle simultaneous text and vision inputs directly in the chat/completions endpoint[3][5][8][9].

  • GPT-5 Mini offers a downsized model for cost and speed, but public technical docs and third-party guides do not confirm vision input support via the chat/completions API. The most detailed API specification and model overview for gpt-5-mini emphasize text processing, large context windows, and quick response times, but do not state it accepts image_url or vision content as input[2][4]. This is also consistent with third-party documentation and community reports[6][10].

  • GPT-5 Nano is even further optimized for edge and real-time text tasks. Official model guides state it processes single images, but only for constrained use cases such as mobile inference—not for general multimodal chat/completions (e.g., not by passing "image_url" in the typical API structure)[2]. This suggests the Nano variant's image handling is not equivalent to the flagship's fully supported multimodal input[2][6].

  • Table summary (based on official and developer sources):

Model Variant Text Input Image Input via Chat/Completions API
gpt-5 (Full) Yes Yes
gpt-5-mini Yes No (not supported or very limited)
gpt-5-nano Yes No (not supported or very limited)
  • Additional Clarification:
    Official OpenAI documentation and reputable blog reviews clarify that GPT-5 supports both text and image (vision) input, but audio and image generation remain covered by specialized models like GPT-4o Audio and GPT Image 1[8]. There is no public evidence that gpt-5-mini and gpt-5-nano offer full multimodal chat/completions support for vision input (image_url)[2][6][8].

Conclusion:
You can use image inputs with GPT-5 Full via the chat/completions API. gpt-5-mini and gpt-5-nano do not natively accept vision (image_url) content as input in the chat/completions endpoint; they are text-specialized models, with only minimal or separate image processing capabilities[2][6][8].

Citations:


Narrow GPT-5 Regex to Exclude Non-Vision Variants
GPT-5 Full accepts image inputs via the chat/completions API, but gpt-5-mini and gpt-5-nano do not. Using a blanket /gpt-5/ will mistakenly flag those text-only variants as vision-capable.

Please update the regex in app/constant.ts (around lines 496–497):

-  /grok-4/i,
-  /gpt-5/
+  /grok-4/i,
+  /gpt-5(?!-(nano|mini))/

If OpenAI introduces new GPT-5 SKUs with vision support in the future, switch to an explicit allowlist for better precision.

🤖 Prompt for AI Agents
In app/constant.ts around lines 496 to 497, the regex /gpt-5/ is too broad and
incorrectly matches GPT-5 variants without vision capabilities like gpt-5-mini
and gpt-5-nano. Update the regex to explicitly match only the GPT-5 variants
that support vision inputs, excluding the non-vision ones. Consider using an
explicit allowlist pattern for the known vision-capable GPT-5 SKUs to ensure
precise matching and easier future updates.

@Leizhenpeng Leizhenpeng merged commit 995bef7 into ChatGPTNextWeb:main Aug 10, 2025
1 of 2 checks passed
@TinyQAQ
Copy link

TinyQAQ commented Aug 31, 2025

when will the azure gpt-5 and gpt-image-1 will support

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.

3 participants