Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix o1 #5850

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix o1 #5850

wants to merge 2 commits into from

Conversation

code-october
Copy link
Contributor

@code-october code-october commented Nov 21, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

  1. 修复 disableGPT4 未禁用 o1
  2. 官方 o1 支持流式调用了,改用更友好的流式交互

📝 补充信息 | Additional Information

Summary by CodeRabbit

  • New Features

    • Enhanced model filtering to exclude additional model IDs, improving the accuracy of available models.
    • Streamlined request payload construction for API interactions, ensuring consistent handling across different model types.
  • Bug Fixes

    • Improved error handling for unauthorized access and API request failures.
  • Refactor

    • Simplified logic for determining which icons to render based on model types.

Copy link

vercel bot commented Nov 21, 2024

@code-october is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes introduce modifications across several files, primarily focusing on the filtering logic for model IDs in the getModels function and the construction of request payloads in the ChatGPTApi class. Specifically, models with IDs starting with "o1" are now excluded when certain conditions are met. Additionally, the handling of streaming options and error messages has been refined. The rendering logic for icons in the Avatar function has also been updated to reflect these new filtering criteria.

Changes

File Change Summary
app/api/openai.ts Updated getModels function to exclude models with IDs starting with "o1" when config.disableGPT4 is true.
app/client/platforms/openai.ts Modified ChatGPTApi class to streamline requestPayload construction and enhance error handling in the usage method.
app/components/emoji.tsx Altered Avatar function to change icon rendering logic based on updated model filtering criteria.
app/config/server.ts Updated getServerSideConfig to include models starting with "o1" in filtering logic when DISABLE_GPT4 is true.

Possibly related PRs

Suggested labels

help wanted, planned

Suggested reviewers

  • Dogtiti
  • lloydzhou

🐰 In a world of models, both old and new,
We’ve filtered and crafted, it’s true!
With logic refined and icons aligned,
The changes are here, let’s hop and unwind!
Streaming is simpler, errors now clear,
A brighter path forward, let’s all give a cheer! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

🧹 Outside diff range and nitpick comments (3)
app/components/emoji.tsx (1)

40-41: Add a comment explaining the model grouping logic

Consider adding a comment to explain why these specific models (gpt-4, chatgpt-4o, o1) are grouped together for the BlackBotIcon rendering.

+        // Premium/advanced models use the black bot icon
         props.model?.startsWith("gpt-4") ||
         props.model?.startsWith("chatgpt-4o") ||
         props.model?.startsWith("o1") ? (
app/api/openai.ts (1)

17-18: Consider documenting the model filtering logic.

The filtering conditions are becoming complex with multiple model prefixes and exceptions. Consider adding a comment to explain the filtering logic and why certain models are excluded or allowed.

+ // Filter out GPT-4 related models when disabled, except for specific mini variants
  remoteModelRes.data = remoteModelRes.data.filter(
    (m) =>
      !(m.id.startsWith("gpt-4") || m.id.startsWith("chatgpt-4o") || m.id.startsWith("o1")) ||
      m.id.startsWith("gpt-4o-mini"),
  );
app/config/server.ts (1)

132-140: Consider centralizing model prefix definitions.

The model prefix checks ("gpt-4", "chatgpt-4o", "o1") are duplicated in multiple places. Consider extracting these into constants to improve maintainability and reduce the risk of inconsistencies.

Example refactor:

const GPT4_MODEL_PREFIXES = ['gpt-4', 'chatgpt-4o', 'o1'] as const;
const ALLOWED_MINI_MODELS = ['gpt-4o-mini'] as const;

// Usage in filtering logic
customModels += DEFAULT_MODELS.filter(
  (m) =>
    GPT4_MODEL_PREFIXES.some(prefix => m.name.startsWith(prefix)) &&
    !ALLOWED_MINI_MODELS.some(prefix => m.name.startsWith(prefix))
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a2adfbb and ef24d3e.

📒 Files selected for processing (4)
  • app/api/openai.ts (1 hunks)
  • app/client/platforms/openai.ts (2 hunks)
  • app/components/emoji.tsx (1 hunks)
  • app/config/server.ts (1 hunks)
🔇 Additional comments (6)
app/components/emoji.tsx (1)

40-41: Verify model icon mapping consistency across the application

The addition of "o1" to the premium model group (using BlackBotIcon) looks correct, but let's ensure this categorization is consistent with other parts of the application.

✅ Verification successful

Model categorization is consistent across the codebase

The verification confirms that "o1" models are consistently treated as premium/advanced models alongside "gpt-4" and "chatgpt-4o" models across the codebase:

  • In app/config/server.ts: Grouped with GPT-4 models for filtering
  • In app/api/openai.ts: Same premium model grouping logic
  • In app/components/emoji.tsx: Consistent UI treatment with BlackBotIcon
  • In app/client/platforms/openai.ts: Special handling similar to other premium models
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent model categorization across the codebase
# Look for other places where model types are categorized or filtered

# Check for model type categorization patterns
rg -A 3 "startsWith\(['\"]o1" 

# Check for model filtering logic
ast-grep --pattern 'if ($COND.startsWith("o1") || $$$) { $$$ }'

Length of output: 1348

app/api/openai.ts (1)

17-18: LGTM! The change correctly implements the disableGPT4 feature for o1 models.

The modification properly extends the filter to exclude o1 models when GPT4 is disabled, which aligns with the PR objectives.

app/config/server.ts (2)

139-140: LGTM: Default model reset logic properly updated.

The addition of defaultModel.startsWith("o1") maintains consistency with the model filtering logic, ensuring that "o1" models are properly handled when GPT4 is disabled.


132-134: LGTM: Model filtering logic correctly updated.

The addition of m.name.startsWith("o1") properly implements the disabling of "o1" models when GPT4 is disabled, aligning with the PR objectives.

Let's verify that all model prefixes are consistently handled:

✅ Verification successful

Model prefix handling is consistent across the codebase

The verification confirms that the model prefix handling for "gpt-4", "chatgpt-4o", and "o1" models is consistently implemented across all relevant files:

  • app/config/server.ts: Used in model filtering and default model reset
  • app/api/openai.ts: Applied in model availability checks
  • app/components/emoji.tsx: Used for avatar display logic
  • app/client/platforms/openai.ts: Individual model type check
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any inconsistencies in model prefix handling across the codebase

# Search for model prefix checks to ensure consistent handling
rg -A 2 "startsWith\((.*?)(gpt-4|chatgpt-4o|o1)"

Length of output: 1425

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

250-250: Verify streaming support in dependent code

The simplified streaming condition looks good, removing the special case for "o1" models. This change aligns with the PR objective to adopt streaming interaction.

Let's verify the streaming implementation in dependent code:

✅ Verification successful

Streaming implementation is consistent across platforms

The simplified streaming condition in OpenAI's implementation aligns with how streaming is handled across all other platform implementations. The search results show that:

  1. All platforms use a similar shouldStream = !!options.config.stream pattern
  2. OpenAI's special case for DALL-E 3 (!isDalle3) is the only model-specific streaming restriction
  3. No other platform has model-specific streaming conditions that would need updating
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other streaming-related conditions that might need updating
rg -B 3 -A 3 'stream.*=.*false.*o1'

# Search for any streaming-related error handling specific to "o1" models
rg -B 3 -A 3 'catch.*stream.*o1'

Length of output: 72


Script:

#!/bin/bash
# Let's search for any streaming-related code in the codebase
rg -B 3 -A 3 'shouldStream|streaming' app/client/platforms/

# Search for any model-specific streaming conditions
rg -B 3 -A 3 'stream.*model' app/client/platforms/

# Search for any streaming-related error handling
rg -B 3 -A 3 'catch.*stream' app/client/platforms/

Length of output: 11974


Line range hint 227-233: LGTM! Verify hardcoded values for "o1" models

The simplified request payload construction looks good. The hardcoded values for "o1" models (temperature=1, presence_penalty=0, frequency_penalty=0, top_p=1) align with standard defaults.

Let's verify these are the correct default values for "o1" models:

✅ Verification successful

Hardcoded values for "o1" models are correctly implemented

Based on the codebase analysis:

  1. The "o1" model is treated as a special model type alongside GPT-4 and ChatGPT-4
  2. The hardcoded values (temperature=1, presence_penalty=0, frequency_penalty=0, top_p=1) are intentionally set for "o1" models to ensure consistent behavior
  3. The model documentation confirms that temperature values > 1 can cause issues, validating the choice of temperature=1
  4. The special handling of "o1" models is consistently implemented across the codebase, including model filtering and UI display
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other occurrences of these parameters being set differently for "o1" models
rg -A 2 -B 2 'temperature.*=.*1.*presence_penalty.*=.*0.*frequency_penalty.*=.*0.*top_p.*=.*1'

Length of output: 96


Script:

#!/bin/bash
# Let's search for individual parameter settings for "o1" models
echo "Searching for temperature settings..."
rg -B 3 -A 3 'isO1.*temperature'

echo -e "\nSearching for presence_penalty settings..."
rg -B 3 -A 3 'isO1.*presence_penalty'

echo -e "\nSearching for frequency_penalty settings..."
rg -B 3 -A 3 'isO1.*frequency_penalty'

echo -e "\nSearching for top_p settings..."
rg -B 3 -A 3 'isO1.*top_p'

# Let's also check for any model configuration defaults
echo -e "\nSearching for default model configurations..."
rg -B 3 -A 3 'defaultModelConfig|ModelConfig.*=.*{' 

Length of output: 3291


Script:

#!/bin/bash
# Let's search for model configuration defaults with a fixed regex
echo "Searching for model configurations..."
rg -B 3 -A 3 'ModelConfig.*='

# Let's also check for any o1 model related configurations
echo -e "\nSearching for o1 model configurations..."
rg -B 3 -A 3 'isO1.*=' 

# Check for any documentation or comments about o1 models
echo -e "\nSearching for o1 model documentation..."
rg -B 3 -A 3 '"o1"|\'o1\''

Length of output: 2882


Script:

#!/bin/bash
# Let's search for o1 model documentation with fixed quotes
echo "Searching for o1 model documentation..."
rg -B 3 -A 3 '"o1"'

# Let's also check for any model-specific handling
echo -e "\nSearching for model-specific code..."
rg -B 3 -A 3 'startsWith.*"o1"'

# Check for any comments about model parameters
echo -e "\nSearching for model parameter comments..."
rg -B 3 -A 3 'temperature|presence_penalty|frequency_penalty|top_p' -g '*.md'

Length of output: 6633

Comment on lines +17 to 18
!(m.id.startsWith("gpt-4") || m.id.startsWith("chatgpt-4o") || m.id.startsWith("o1")) ||
m.id.startsWith("gpt-4o-mini"),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

The exception logic for mini variants is inconsistent and needs to be updated

Based on the codebase analysis:

  • The o1-mini model exists in the constants and is treated similarly to other GPT-4 class models
  • In app/api/openai.ts, only gpt-4o-mini variants are allowed to bypass the filter
  • In app/config/server.ts, there's a similar pattern where only gpt-4o-mini is excluded from restrictions

The filter should be updated to also exclude o1-mini variants since they are part of the same model class and are defined with the same knowledge cutoff date (2023-10) in the constants.

🔗 Analysis chain

Verify the exception logic for mini variants.

The current implementation allows "gpt-4o-mini" models to bypass the filter. Please verify if this exception should also apply to any mini variants of o1 models.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any usage or documentation of mini variants of o1 models
# Expected: Find references to confirm if mini variants of o1 should be allowed

# Search for o1 model references in the codebase
rg -i "o1.*mini" 

# Search for model configuration or documentation files
fd -e md -e json -e yaml -e yml | xargs rg -i "o1.*mini"

Length of output: 146


Script:

#!/bin/bash
# Let's get more context about the model filtering logic and related constants

# Search for the complete model filtering logic
rg -A 5 -B 5 "gpt-4o-mini|o1-mini"

# Check the constant.ts file content since we found o1-mini references there
cat app/constant.ts

# Look for any other model-related configurations or filters
ast-grep --pattern 'startsWith("o1") || startsWith("gpt")'

Length of output: 17804

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