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

in chat list, show model.displayName if it exists + support bytedance's r1 with internet #6220

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

Conversation

bestsanmao
Copy link
Contributor

@bestsanmao bestsanmao commented Feb 13, 2025

  1. 显示消息的模型名时,有displayName就显示displayName (如下图一)
  2. 支持字节跳动的带联网功能的r1(字节默认是ep-开头的接入点,现支持bot-开头的应用,支持联网,如下图二三)
    bot-开头的应用id申请方式可参考这个链接的方案二

image

image

image

fixed #6177

Summary by CodeRabbit

  • New Features
    • Chat messages now display a more user-friendly model name when available, improving clarity in conversations.
    • A fallback mechanism ensures that the original model identifier is shown if no user-friendly name exists, enhancing message consistency.

Copy link

vercel bot commented Feb 13, 2025

@bestsanmao 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 Feb 13, 2025

Walkthrough

This pull request modifies the chat interface by conditionally rendering a model's display name in place of its raw identifier. In the component, the displayed text now checks for a provided friendly name before falling back to the original model. Additionally, the chat message type is enhanced by adding an optional property, and a helper function (getModelDisplayName) is introduced and invoked during message creation to determine the appropriate display name. The API interaction is also updated to accommodate model-specific paths.

Changes

File(s) Description
app/components/chat.tsx Updated rendering logic to display message.modelDisplayName if available, falling back to message.model otherwise.
app/store/chat.ts Extended ChatMessage type with an optional modelDisplayName property; added getModelDisplayName function; modified onUserInput to use it.
app/client/platforms/bytedance.ts Modified chat method to generate chatPath using a model-specific path based on modelConfig.model.
app/constant.ts Changed ChatPath from a static string to a function that returns different paths based on whether the modelName starts with "bot-".
app/utils.ts Updated getTimeoutMSByModel function to include new conditions for models starting with "ep-" or "bot-".
app/components/emoji.tsx Enhanced conditional logic in Avatar function to check for model names starting with "bot-", expanding icon selection criteria.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Chat Component
    participant S as Chat Store
    participant G as getModelDisplayName

    U->>C: Sends chat message
    C->>S: Calls onUserInput(message)
    S->>G: Retrieves model display name
    G-->>S: Returns modelDisplayName (or undefined)
    S->>C: Returns botMessage with modelDisplayName property
    C->>U: Renders message (using modelDisplayName if available)
Loading

Possibly related PRs

Poem

I'm a little rabbit, hopping on a new code trail,
With model names now dressed in a friendlier tale.
I check for a display that sparkles bright,
And if it's absent, default to the original light.
Cheers to small changes that make our app prevail! 🐇
Hop, hop, hop — onward we sail!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
app/store/chat.ts (1)

155-171: Consider memoizing the model display name lookup.

The function works correctly but could benefit from memoization since the model configurations don't change frequently. This would prevent unnecessary recomputation, especially during chat streaming where onUpdate is called frequently.

Consider using React's useMemo or a memoization library:

+import memoize from 'lodash/memoize';
+
-function getModelDisplayName(
+const getModelDisplayName = memoize((
   model: ModelType,
   providerName: ServiceProvider,
-): string | undefined {
+): string | undefined => {
   const configStore = useAppConfig.getState();
   const accessStore = useAccessStore.getState();
   const allModel = collectModelsWithDefaultModel(
     configStore.models,
     [configStore.customModels, accessStore.customModels].join(","),
     accessStore.defaultModel,
   );

   const matchedModel = allModel.find(
     (m) => m.name === model && m.provider?.providerName === providerName,
   );
   return matchedModel ? matchedModel.displayName : undefined;
-}
+});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12863f5 and c15dbf5.

📒 Files selected for processing (2)
  • app/components/chat.tsx (1 hunks)
  • app/store/chat.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/components/chat.tsx
🔇 Additional comments (2)
app/store/chat.ts (2)

63-63: LGTM! Type definition is well-structured.

The optional modelDisplayName property is correctly defined and follows TypeScript conventions.


459-462: LGTM! Display name is correctly set in the bot message.

The implementation properly retrieves and sets the model display name using the appropriate configuration values.

@bestsanmao bestsanmao changed the title in chat list, show model display name if it exists in chat list, show model.displayName if it exists + support bytedance's r1 with internet Feb 14, 2025
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: 0

🧹 Nitpick comments (1)
app/utils.ts (1)

307-309: Consider refactoring the model prefix checks for better maintainability.

While the changes correctly add support for new model types, the growing list of conditions suggests a need for a more maintainable approach.

Consider refactoring to use a configuration array:

+const THINKING_MODEL_PATTERNS = [
+  'dall-e',
+  'dalle',
+  'o1',
+  'o3',
+  'deepseek-r',
+  '-thinking',
+  'ep-',
+  'bot-'
+];

 export function getTimeoutMSByModel(model: string) {
   model = model.toLowerCase();
-  if (
-    model.startsWith("dall-e") ||
-    model.startsWith("dalle") ||
-    model.startsWith("o1") ||
-    model.startsWith("o3") ||
-    model.includes("deepseek-r") ||
-    model.includes("-thinking") ||
-    model.startsWith("ep-") ||
-    model.startsWith("bot-")
-  )
+  if (THINKING_MODEL_PATTERNS.some(pattern => 
+    pattern.endsWith('-') ? model.startsWith(pattern) : model.includes(pattern)
+  ))
     return REQUEST_TIMEOUT_MS_FOR_THINKING;
   return REQUEST_TIMEOUT_MS;
 }

This approach:

  1. Makes it easier to maintain the list of special models
  2. Separates configuration from logic
  3. Makes the pattern matching logic more explicit
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c15dbf5 and e2429d4.

📒 Files selected for processing (4)
  • app/client/platforms/bytedance.ts (1 hunks)
  • app/components/emoji.tsx (1 hunks)
  • app/constant.ts (1 hunks)
  • app/utils.ts (1 hunks)
🔇 Additional comments (4)
app/components/emoji.tsx (1)

85-89: LGTM! Clean extension of model icon handling.

The addition of the "bot-" prefix check alongside existing conditions is well-implemented and maintains consistency with the existing pattern.

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

120-120: LGTM! Proper integration of dynamic chat path.

The update correctly uses the new dynamic ChatPath function, enabling proper routing for different model types.

app/constant.ts (1)

219-225: LGTM! Well-structured dynamic path handling.

The implementation of dynamic chat path selection is clean and follows a clear pattern:

  • Returns "api/v3/bots/chat/completions" for bot models
  • Falls back to "api/v3/chat/completions" for other models
app/utils.ts (1)

299-313: LGTM! Changes support the model display name feature.

The modifications to the timeout handling function appropriately support the new model types, which aligns with the PR's objective of enhancing model display name functionality in the chat list.

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.

[Bug] 使用bytedance模式时,模型展示名称为endpoint
1 participant