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

修复自定义模型与预设模型名重复时,无法正确将自定义模型认定为openai渠道的bug #4748

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

Conversation

imaiya
Copy link

@imaiya imaiya commented May 21, 2024

  • 有很多代理站在使用anthropic相关模型时,需要走OpenAi格式和渠道,所以需要使用自定义模型来添加,如果自定义模型名称重复,实际应该覆盖预置模型,而不是以预置模型为准.
  • 自定义模型显示后缀为(*OpenAI),表示当前走的OpenAI格式

Summary by CodeRabbit

  • New Features

    • Updated chat functionality to support expanded view with new styles.
    • Added a new ChatAction prop for expanded state.
  • Bug Fixes

    • Corrected provider assignment for custom models to use "*OpenAI".
  • Style

    • Enhanced chat component styles for better user experience.
  • Chores

    • Updated owner information to "imaiya".
    • Adjusted default configuration flags for preview bubbles and splash screens.

Copy link

vercel bot commented May 21, 2024

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

Your build has completed!

Preview deployment

@imaiya
Copy link
Author

imaiya commented May 21, 2024

Fixes #4492

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Fixes #4492

Copy link

coderabbitai bot commented May 24, 2024

Walkthrough

The recent updates primarily focus on enhancing various aspects of the application's user interface and backend logic. The customProvider function and model table collection were streamlined; CSS styling for chat components was improved to support expanded states; and minor text and constant updates were made in various files. Additionally, configuration defaults were adjusted for UI preview settings. These changes collectively aim to improve functionality and appearance.

Changes

Files Change Summary
app/utils/model.ts Updated customProvider function to default to "*OpenAI", simplified provider assignment.
app/components/chat.module.scss Added styles for expanded chat, adjusted message item image, and send button positioning.
app/components/chat.tsx Added isExpanded prop to ChatAction component and modified structure for ChatActions.
app/components/sidebar.tsx Updated text content to add attribution.
app/constant.ts Changed OWNER constant to "imaiya" and added comma in openaiModels array.
app/store/config.ts Changed default values of sendPreviewBubble and dontShowMaskSplashScreen flags.

Poem

In code lands where changes brew,
*OpenAI now shines anew.
It styles and toggles, icons expand,
Our chat interface feels so grand.
Constants shift, configs switch,
Our app evolves without a hitch. 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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

Outside diff range and nitpick comments (2)
app/utils/model.ts (2)

Line range hint 25-30: Consider replacing forEach with for...of loops for better readability and potential performance benefits in modern JavaScript engines.

- models.forEach((m) => {
+ for (const m of models) {

Also applies to: 33-55, 44-46


Line range hint 65-65: Change the let declaration to const since the variable modelTable is not reassigned, which can help ensure immutability and reduce potential bugs.

- let modelTable = collectModelTable(models, customModels);
+ const modelTable = collectModelTable(models, customModels);
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3866448 and f139d6a.
Files selected for processing (1)
  • app/utils/model.ts (2 hunks)
Additional Context Used
Biome (6)
app/utils/model.ts (6)

25-30: Prefer for...of instead of forEach.


33-55: Prefer for...of instead of forEach.


44-46: Prefer for...of instead of forEach.


45-45: The assignment should not be in an expression.


1-1: All these imports are only used as types.


65-65: This let declares a variable that is only assigned once.

Additional comments not posted (2)
app/utils/model.ts (2)

5-5: The addition of providerName and providerType in customProvider aligns with the PR objectives to distinguish custom models as OpenAI channel models. The providerType field, although not mentioned in the summary, is a logical addition for further categorization.


52-52: Simplifying the provider assignment in collectModelTable to always use customProvider ensures that custom models are prioritized correctly, aligning with the PR objectives.

Copy link

@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: 2

Outside diff range and nitpick comments (6)
app/components/sidebar.tsx (2)

Line range hint 191-198: Add keyboard event handlers to improve accessibility.

+ onKeyUp={handleKeyUp}

Ensure to implement handleKeyUp to handle keyboard interactions for better accessibility.


Line range hint 117-117: Include limit in the dependency array to ensure the hook updates correctly.

- }, [config.sidebarWidth, isMobileScreen, shouldNarrow]);
+ }, [config.sidebarWidth, isMobileScreen, shouldNarrow, limit]);
app/components/chat.tsx (4)

382-382: Clarify the use of data attributes for style control.

Using data attributes (data-expanded) for controlling styles is unusual and might not be clear to all developers. Consider adding a comment explaining this choice or using a more conventional method like conditional class names.


559-559: Ensure consistency in the use of boolean props.

The isExpanded prop is explicitly set to true here, which is fine, but ensure that it is consistently handled across all uses of the ChatAction component to avoid unexpected behaviors.


Line range hint 257-261: Refactor the useEffect to correctly specify dependencies.

The useEffect hook does not correctly specify all its dependencies, which could lead to bugs due to missing updates.

useEffect(() => {
  setSelectIndex(0);
- }, [props.prompts.length]);
+ }, [props.prompts.length, noPrompts, props.onPromptSelect, props.prompts.at]);

Line range hint 474-475: Include all necessary dependencies in the useEffect hook.

The useEffect hook used for showing the upload image button does not include all necessary dependencies, which might lead to unexpected behavior.

useEffect(() => {
  const show = isVisionModel(currentModel);
  setShowUploadImage(show);
  if (!show) {
    props.setAttachImages([]);
    props.setUploading(false);
  }
- }, [chatStore, currentModel, models]);
+ }, [chatStore, currentModel, models, props.setAttachImages, props.setUploading]);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f139d6a and c5925ab.

Files selected for processing (4)
  • app/components/chat.module.scss (3 hunks)
  • app/components/chat.tsx (5 hunks)
  • app/components/sidebar.tsx (1 hunks)
  • app/constant.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • app/constant.ts
Additional context used
Biome
app/components/sidebar.tsx

[error] 191-198: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 117-117: This hook does not specify all of its dependencies: limit (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

app/components/chat.tsx

[error] 182-186: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 302-311: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 324-331: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 368-384: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 385-385: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 387-387: The computed expression can be simplified without the use of a string literal. (lint/complexity/useLiteralKeys)

Unsafe fix: Use a literal key instead.


[error] 668-669: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 1522-1523: Avoid the autoFocus attribute. (lint/a11y/noAutofocus)

Unsafe fix: Remove the autoFocus attribute.


[error] 257-257: This hook specifies more dependencies than necessary: props.prompts.length (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.


[error] 261-261: This hook does not specify all of its dependencies: noPrompts (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 261-261: This hook does not specify all of its dependencies: props.onPromptSelect (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 261-261: This hook does not specify all of its dependencies: props.prompts.at (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 364-364: This hook does not specify all of its dependencies: updateWidth (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 364-364: This hook specifies more dependencies than necessary: props.icon, props.text (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.

This dependency can be removed from the list.


[error] 474-475: This hook does not specify all of its dependencies: props.setAttachImages (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 474-475: This hook does not specify all of its dependencies: props.setUploading (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 736-736: This hook specifies more dependencies than necessary: userInput (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.


[error] 814-815: This hook does not specify all of its dependencies: chatStore.updateCurrentSession (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

Either include it or remove the dependency array


[error] 814-815: This hook does not specify all of its dependencies: config.modelConfig (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

Either include it or remove the dependency array


[error] 1114-1114: This hook does not specify all of its dependencies: session.id (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.

Either include it or remove the dependency array

Additional comments not posted (2)
app/components/sidebar.tsx (1)

161-161: Text change approved. It enhances clarity by specifying the author.

app/components/chat.module.scss (1)

90-96: CSS changes approved. They ensure that elements remain expanded as intended.

@@ -341,6 +341,7 @@ function ChatAction(props: {
text: string;
icon: JSX.Element;
onClick: () => void;
isExpanded?: boolean;
Copy link

Choose a reason for hiding this comment

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

Add keyboard accessibility to the ChatAction component.

The ChatAction component should also respond to keyboard events to ensure accessibility. Consider adding onKeyDown or similar keyboard event handlers.

function ChatAction(props: {
  text: string;
  icon: JSX.Element;
  onClick: () => void;
  isExpanded?: boolean;
}) {
+ onKeyDown={(e) => e.key === 'Enter' && props.onClick()}
  ...
}

Committable suggestion was skipped due to low confidence.

Comment on lines +364 to +366
useEffect(() => {
updateWidth();
}, [props.icon, props.text]);
Copy link

Choose a reason for hiding this comment

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

Ensure updateWidth is included in the dependency array of useEffect.

The updateWidth function is used inside a useEffect but is not included in its dependency array. This might lead to stale closures capturing outdated values.

useEffect(() => {
  updateWidth();
- }, [props.icon, props.text]);
+ }, [props.icon, props.text, updateWidth]);
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.

Suggested change
useEffect(() => {
updateWidth();
}, [props.icon, props.text]);
useEffect(() => {
updateWidth();
}, [props.icon, props.text, updateWidth]);
Tools
Biome

[error] 364-364: This hook does not specify all of its dependencies: updateWidth (lint/correctness/useExhaustiveDependencies)

This dependency is not specified in the hook dependency list.


[error] 364-364: This hook specifies more dependencies than necessary: props.icon, props.text (lint/correctness/useExhaustiveDependencies)

This dependency can be removed from the list.

This dependency can be removed from the list.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c5925ab and 973a3a4.

Files selected for processing (1)
  • app/constant.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/constant.ts

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 973a3a4 and 55f8438.

Files selected for processing (1)
  • app/constant.ts (1 hunks)
Additional comments not posted (1)
app/constant.ts (1)

1-1: Update OWNER constant to reflect current maintainer.

The change from "Yidadaa" to "imaiya" aligns with the PR's objective to recognize contributions and ownership accurately. This update should reflect across all associated URLs and configurations that utilize the OWNER constant.

- 将 sendPreviewBubble 设置为 false,以禁用预览气泡。
- 将 dontShowMaskSplashScreen 设置为 true,以隐藏创建聊天时的闪屏。
Copy link

@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

Outside diff range and nitpick comments (1)
app/store/config.ts (1)

Line range hint 74-74: Replace isNaN with Number.isNaN to avoid type coercion.

The use of isNaN can lead to unexpected behavior due to type coercion. It's safer and more predictable to use Number.isNaN which does not coerce the type.

-  if (isNaN(x)) {
+  if (Number.isNaN(x)) {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 55f8438 and 3cd5418.

Files selected for processing (1)
  • app/store/config.ts (1 hunks)
Additional context used
Biome
app/store/config.ts

[error] 74-74: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead. (lint/suspicious/noGlobalIsNan)

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

Additional comments not posted (1)
app/store/config.ts (1)

37-37: Consider the implications of toggling configuration flags.

The change in sendPreviewBubble from true to false and dontShowMaskSplashScreen from false to true may have significant implications on the user interface and user experience. Ensure that these changes align with the desired behavior in the application's settings and that they have been thoroughly tested.

Also applies to: 43-43

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.

None yet

3 participants