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

Custom model names can include the @ symbol by itself. #5769

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

ryanhex53
Copy link
Contributor

@ryanhex53 ryanhex53 commented Nov 5, 2024

To specify the model's provider, append it after the model name using @ as before.

This format supports cases like google vertex ai with a model name like claude-3-5-sonnet@20240620.

For instance, claude-3-5-sonnet@20240620@vertex-ai will be split by split(/@(?!.*@)/) into:

[ 'claude-3-5-sonnet@20240620', 'vertex-ai' ], where the former is the model name and the latter is the custom provider.

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

自定义模型名称现在不支持多个@符号,如果模型名本身有@符号时将变得不可用,比如 google vertex ai 中的模型名 claude-3-5-sonnet@20240620 ,之前的代码会把后面的20240620解析为provider,此提交允许在模型名后再添加@符以指定自定义的provider,如claude-3-5-sonnet@20240620@vertex-ai,这时字符串会被分隔为 ['claude-3-5-sonnet@20240620', 'vertex-ai']`,从而保持功能完好正确。

Summary by CodeRabbit

  • New Features

    • Improved model and provider name extraction across various components to handle cases with multiple "@" symbols.
    • Introduced a new utility function for enhanced parsing logic of model and provider names.
    • Enhanced validation for model configurations to ensure accurate updates.
  • Bug Fixes

    • Resolved issues with incorrect parsing of model names in the ChatActions and ModelConfigList components.
  • Chores

    • Updated migration logic to ensure consistent configuration during data migration.

To specify the model's provider, append it after the model name using `@` as before.

This format supports cases like `google vertex ai` with a model name like `claude-3-5-sonnet@20240620`.

For instance, `claude-3-5-sonnet@20240620@vertex-ai` will be split by `split(/@(?!.*@)/)` into:

`[ 'claude-3-5-sonnet@20240620', 'vertex-ai' ]`, where the former is the model name and the latter is the custom provider.
Copy link

vercel bot commented Nov 5, 2024

@ryanhex53 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 5, 2024

Walkthrough

The pull request introduces modifications across several files to enhance the string manipulation logic for extracting provider names from model names. Specifically, it updates the extraction mechanism to use a function getModelProvider, which encapsulates the logic for accurate parsing. This change improves the handling of model names that may contain multiple "@" symbols, ensuring precise extraction. The overall functionality and control flow of the affected components remain unchanged, with no alterations to exported or public entities.

Changes

File Change Summary
app/api/common.ts Modified requestOpenai function to use getModelProvider for extracting providerName from fullName.
app/components/chat.tsx Updated model selection logic in ChatActions component to utilize getModelProvider for accurate parsing of model strings.
app/components/model-config.tsx Changed ModelConfigList component to use getModelProvider for extracting model and provider names from Select components.
app/store/access.ts Altered fetch method in useAccessStore to use getModelProvider for extracting model and provider names from defaultModel.
app/utils/model.ts Introduced getModelProvider function for extracting model and provider names, replacing direct string splitting logic in relevant functions.
test/model-provider.test.ts Added a test suite for getModelProvider function, validating its behavior with various input scenarios.

Possibly related PRs

Suggested reviewers

  • Dogtiti
  • lloydzhou

Poem

🐇 In the garden of code, we hop and play,
With strings and regex, we find our way.
From models to providers, we split with care,
Ensuring our logic is always fair.
So let’s celebrate changes, both big and small,
For a cleaner codebase, we’ll stand tall! 🌼


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.

@lloydzhou
Copy link
Member

或许可以写一个通用的方法放到utils/chat里面?

@Issues-translate-bot
Copy link

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


Maybe write a general method and put it in utils/chat?

@lloydzhou
Copy link
Member

其实中间有构思过另外一个方案是,将modelName使用encodeURIComponent处理之后在使用@拼接。这样按之前的切分逻辑就不会有问题。
不过在展示和使用modelName的时候,就需要decodeURIComponent之后再使用

@Issues-translate-bot
Copy link

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


In fact, another solution was conceived in the middle, which is to use encodeURIComponent to process modelName and then use @ to splice it. In this way, there will be no problem according to the previous segmentation logic.
However, when displaying and using modelName, you need to use decodeURIComponent afterwards.

Copy link
Contributor

github-actions bot commented Nov 5, 2024

Your build has completed!

Preview deployment

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 (4)
app/utils/model.ts (1)

82-85: LGTM! Consider extracting the regex pattern.

The regex pattern /@(?!.*@)/ correctly handles model names containing @ symbols by splitting on the last occurrence. This fixes the core issue described in the PR.

Consider extracting the repeated regex pattern into a constant at the top of the file:

+const MODEL_PROVIDER_SEPARATOR = /@(?!.*@)/;

This would improve maintainability and ensure consistency across all split operations.

app/api/common.ts (1)

74-74: Consider adding error handling for edge cases.

While the regex pattern works correctly for valid inputs, consider handling edge cases such as:

  • Strings without any @ symbol
  • Multiple consecutive @ symbols
  • Empty strings
-          const [_, providerName] = fullName.split(/@(?!.*@)/);
+          const parts = fullName.split(/@(?!.*@)/);
+          if (parts.length !== 2) {
+            console.warn(`Invalid model name format: ${fullName}`);
+            return;
+          }
+          const [_, providerName] = parts;
+          if (!providerName?.trim()) {
+            console.warn(`Empty provider name in: ${fullName}`);
+            return;
+          }
app/store/access.ts (1)

229-229: Add a comment explaining the regex pattern.

The regex pattern /@(?!.*@)/ uses a negative lookahead to match the last @ symbol. Consider adding a comment to explain this for future maintainability:

+            // Split at the last @ symbol to support model names containing @ (e.g., model@version@provider)
             const [model, providerName] = defaultModel.split(/@(?!.*@)/);
app/components/chat.tsx (1)

648-648: LGTM! The regex pattern correctly handles model names containing @ symbols.

The change to use /@(?!.*@)/ as the split pattern ensures that only the last @ is used as the delimiter, which correctly handles cases like claude-3-5-sonnet@20240620@vertex-ai.

Would you like me to help create unit tests to verify this behavior with various model name formats?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e49fe97 and b844045.

📒 Files selected for processing (5)
  • app/api/common.ts (1 hunks)
  • app/components/chat.tsx (1 hunks)
  • app/components/model-config.tsx (2 hunks)
  • app/store/access.ts (1 hunks)
  • app/utils/model.ts (3 hunks)
🔇 Additional comments (7)
app/utils/model.ts (2)

Line range hint 105-117: LGTM! Provider handling is correct.

The model name splitting logic is consistent with the previous changes, and the provider creation is handled appropriately.


141-144: Verify handling of complex default model names.

The splitting logic is consistent with other changes. However, please verify the behavior when defaultModel contains multiple @ symbols but isn't present in modelTable.

Let's verify the usage of defaultModel throughout the codebase:

✅ Verification successful

Based on the search results, I can now generate the final response since I have enough context about how defaultModel is handled throughout the codebase.

The edge case for multiple @ symbols is properly handled

The codebase already has safeguards against the mentioned edge case:

  • In app/utils/model.ts, there's an explicit check if (defaultModel in modelTable) before setting isDefault
  • The splitting logic in app/store/access.ts uses the same regex pattern /@(?!.*@)/ consistently
  • If defaultModel isn't in modelTable, the code safely skips setting the isDefault flag
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for places where defaultModel is set or used
rg -l 'defaultModel.*=|setDefaultModel' | xargs rg -A 3 'defaultModel.*=|setDefaultModel'

Length of output: 1592

app/api/common.ts (1)

74-74: LGTM! Verify the regex pattern handles all model name formats.

The change from simple split to regex-based split correctly handles model names containing multiple @ symbols. The pattern /@(?!.*@)/ ensures we match only the last @ character, which aligns with the PR objectives.

Let's verify the regex handles various model name formats:

✅ Verification successful

The regex pattern for splitting model names is consistent and working as expected

Based on the verification results:

  1. The regex pattern /@(?!.*@)/ is used consistently across the codebase in both app/utils/model.ts and app/api/common.ts
  2. Testing with various model name formats shows it correctly:
    • Extracts "vertex-ai" from "claude-3-5-sonnet@20240620@vertex-ai"
    • Handles simple "model@provider" format
    • Properly processes multiple @ symbols by always splitting on the last one
    • Safely handles invalid formats (no @ symbol)
    • Correctly manages consecutive @ symbols

The implementation is robust and handles all expected model name formats appropriately.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Create a test file with various model name formats
cat << 'EOF' > test_models.txt
claude-3-5-sonnet@20240620@vertex-ai
basic@provider
model@date@provider@extra
no-at-symbol
multiple@@provider
EOF

# Use grep to test our regex pattern
echo "Testing regex pattern /@(?!.*@)/ against different model formats:"
grep -P '(?<=.*)@(?!.*@).*' test_models.txt

Length of output: 239


Script:

#!/bin/bash
# Let's use a different approach with awk to test the regex pattern's behavior
cat << 'EOF' > test_models.txt
claude-3-5-sonnet@20240620@vertex-ai
basic@provider
model@date@provider@extra
no-at-symbol
multiple@@provider
EOF

# Process each line and split on the last @ symbol
awk -F'@' '{
    if (NF > 1) {
        provider = $NF;
        model = substr($0, 1, length($0) - length(provider) - 1);
        printf "Model: %-40s Provider: %s\n", model, provider;
    } else {
        printf "Invalid format (no @): %s\n", $0;
    }
}' test_models.txt

Length of output: 579


Script:

#!/bin/bash
# Let's check how this pattern is used in the codebase
rg -n "fullName.split" --type ts -A 3 -B 3

Length of output: 1053

app/store/access.ts (1)

229-232: LGTM! The regex pattern correctly handles model names with multiple @ symbols.

The implementation correctly splits model names at the last @ symbol, which allows for model names that contain @ in their version/identifier. For example:

  • "claude-3-5-sonnet@20240620@vertex-ai"["claude-3-5-sonnet@20240620", "vertex-ai"]
  • "model@provider"["model", "provider"]
app/components/model-config.tsx (3)

31-32: LGTM! Improved model name parsing logic.

The new regex pattern /@(?!.*@)/ correctly handles model names containing '@' symbols by splitting on the last occurrence, which aligns with the PR objectives.


251-252: LGTM! Consistent implementation for compress model parsing.

The same regex pattern is correctly applied to the compress model selection, maintaining consistency across the codebase.


31-32: Verify consistent implementation across the codebase.

Let's ensure this parsing logic is consistently implemented across all related files.

Also applies to: 251-252

✅ Verification successful

Based on the search results, I can now generate the final response:

Model parsing implementation is consistent across the codebase ✓

The regex pattern /@(?!.*@)/ is consistently used for model name parsing across all relevant files:

  • app/utils/model.ts: Used in multiple functions
  • app/store/access.ts: Used in default model parsing
  • app/components/model-config.tsx: Current implementation matches
  • app/components/chat.tsx: Used in model selection
  • app/api/common.ts: Used for provider name extraction
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of model name parsing that might need the same update
rg -l '@' --type ts --type tsx | xargs rg 'split.*@'

# Search for test files that should cover this functionality
rg -l 'test|spec' --type ts --type tsx | xargs rg -l 'model.*@'

Length of output: 1271

app/store/access.ts Outdated Show resolved Hide resolved
@lloydzhou lloydzhou added help wanted Extra attention is needed planned planned feature, will support in the future labels Nov 5, 2024
@ryanhex53
Copy link
Contributor Author

其实中间有构思过另外一个方案是,将modelName使用encodeURIComponent处理之后在使用@拼接。这样按之前的切分逻辑就不会有问题。 不过在展示和使用modelName的时候,就需要decodeURIComponent之后再使用

感觉没必要,那样把问题复杂化了。

@Issues-translate-bot
Copy link

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


In fact, another solution was conceived in the middle, which is to use encodeURIComponent to process modelName and then use @ to splice it. In this way, there will be no problem according to the previous segmentation logic. However, when displaying and using modelName, you need to use decodeURIComponent afterwards.

It feels unnecessary and it complicates the issue.

@Dogtiti
Copy link
Member

Dogtiti commented Nov 5, 2024

或许可以写一个通用的方法放到utils/chat里面?

@ryanhex53 可以改一下 加一些单元测试

@Issues-translate-bot
Copy link

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


Maybe you can write a general method and put it in utils/chat?

@ryanhex53 You can change it and add some unit tests

@ryanhex53
Copy link
Contributor Author

或许可以写一个通用的方法放到utils/chat里面?

@ryanhex53 可以改一下 加一些单元测试

可以,我打算放到utils/model里面,但是单元测试我没看到你们有相关的参照

@Issues-translate-bot
Copy link

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


Perhaps you can write a general method and put it in utils/chat?

@ryanhex53 You can change it and add some unit tests

Yes, I plan to put it in utils/model, but I don’t see any relevant reference for unit testing.

@Dogtiti
Copy link
Member

Dogtiti commented Nov 5, 2024

或许可以写一个通用的方法放到utils/chat里面?

@ryanhex53 可以改一下 加一些单元测试

可以,我打算放到utils/model里面,但是单元测试我没看到你们有相关的参照

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/test/sum-module.test.ts 参考一下这个

@Issues-translate-bot
Copy link

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


Perhaps you can write a general method and put it in utils/chat?

@ryanhex53 You can change it and add some unit tests

Yes, I plan to put it in utils/model, but I don’t see any relevant reference for unit testing.

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/test/sum-module.test.ts Refer to this

@ryanhex53
Copy link
Contributor Author

@Dogtiti 已按要求提交,而且加了单元测试

@Issues-translate-bot
Copy link

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


@Dogtiti has submitted it as required and added unit tests

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

🧹 Outside diff range and nitpick comments (7)
test/model-provider.test.ts (4)

4-9: Consider adding more realistic model name examples.

While this test case covers the basic functionality, consider adding tests with real-world model names mentioned in the PR description, such as claude-3-5-sonnet@20240620@vertex-ai.

 test("should return model and provider when input contains '@'", () => {
-    const input = "model@provider";
+    const input = "claude-3-5-sonnet@20240620@vertex-ai";
     const [model, provider] = getModelProvider(input);
-    expect(model).toBe("model");
-    expect(provider).toBe("provider");
+    expect(model).toBe("claude-3-5-sonnet@20240620");
+    expect(provider).toBe("vertex-ai");
   });

11-16: Consider using a realistic model name without provider.

While this test case is valid, using a real model name would make the test more meaningful.

 test("should return model and undefined provider when input does not contain '@'", () => {
-    const input = "model";
+    const input = "claude-3-5-sonnet";
     const [model, provider] = getModelProvider(input);
-    expect(model).toBe("model");
+    expect(model).toBe("claude-3-5-sonnet");
     expect(provider).toBeUndefined();
   });

18-23: Improve test description and use PR example.

This test case covers the main PR objective. Consider making it more explicit and using the example from the PR description.

-  test("should handle multiple '@' characters correctly", () => {
+  test("should handle model names containing '@' with custom provider", () => {
     const input = "model@provider@extra";
     const [model, provider] = getModelProvider(input);
-    expect(model).toBe("model@provider");
-    expect(provider).toBe("extra");
+    expect(model).toBe("claude-3-5-sonnet@20240620");
+    expect(provider).toBe("vertex-ai");
   });

25-31: Consider adding more edge cases.

While testing empty input is good, consider adding tests for other edge cases:

  • Input with only '@'
  • Input ending with '@'
  • Input with multiple consecutive '@@@'
   test("should return empty strings when input is empty", () => {
     const input = "";
     const [model, provider] = getModelProvider(input);
     expect(model).toBe("");
     expect(provider).toBeUndefined();
   });
+
+  test("should handle edge cases with '@' symbol", () => {
+    expect(getModelProvider("@")).toEqual(["", undefined]);
+    expect(getModelProvider("model@")).toEqual(["model", undefined]);
+    expect(getModelProvider("model@@@provider")).toEqual(["model@@", "provider"]);
+  });
app/utils/model.ts (2)

93-96: LGTM! Consistent usage of getModelProvider.

The changes correctly utilize the new utility function for model name parsing.

Consider optimizing provider name handling.

The provider name logic could be simplified to reduce redundancy.

-          let [customModelName, customProviderName] = getModelProvider(name);
-          const provider = customProvider(
-            customProviderName || customModelName,
-          );
+          const [customModelName, customProviderName] = getModelProvider(name);
+          const providerName = customProviderName || "default";
+          const provider = customProvider(providerName);

Also applies to: 116-129


40-43: Consider documenting the model name format in a central location.

The model name format (e.g., gpt-4@OpenAi or claude-3-5-sonnet@20240620@Google) is a critical part of the system's architecture. Consider documenting this format in:

  1. A central constants file
  2. The project's technical documentation
  3. Type definitions with string literals/patterns

This would help maintain consistency across the codebase and make it easier for other developers to understand the expected format.

app/components/model-config.tsx (1)

253-255: Consider refactoring to reduce code duplication.

The implementation is correct but duplicates the parsing logic from the first handler. Consider extracting a common handler function.

Here's a suggested refactoring:

+ const handleModelChange = (
+   value: string,
+   isCompress: boolean,
+   updateConfig: (updater: (config: ModelConfig) => void) => void
+ ) => {
+   const [model, providerName] = getModelProvider(value);
+   updateConfig((config) => {
+     if (isCompress) {
+       config.compressModel = ModalConfigValidator.model(model);
+       config.compressProviderName = providerName as ServiceProvider;
+     } else {
+       config.model = ModalConfigValidator.model(model);
+       config.providerName = providerName as ServiceProvider;
+     }
+   });
+ };

  // In the first Select
- onChange={(e) => {
-   const [model, providerName] = getModelProvider(
-     e.currentTarget.value,
-   );
-   props.updateConfig((config) => {
-     config.model = ModalConfigValidator.model(model);
-     config.providerName = providerName as ServiceProvider;
-   });
- }}
+ onChange={(e) => handleModelChange(e.currentTarget.value, false, props.updateConfig)}

  // In the second Select
- onChange={(e) => {
-   const [model, providerName] = getModelProvider(
-     e.currentTarget.value,
-   );
-   props.updateConfig((config) => {
-     config.compressModel = ModalConfigValidator.model(model);
-     config.compressProviderName = providerName as ServiceProvider;
-   });
- }}
+ onChange={(e) => handleModelChange(e.currentTarget.value, true, props.updateConfig)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b844045 and 8e2484f.

📒 Files selected for processing (6)
  • app/api/common.ts (2 hunks)
  • app/components/chat.tsx (2 hunks)
  • app/components/model-config.tsx (3 hunks)
  • app/store/access.ts (2 hunks)
  • app/utils/model.ts (4 hunks)
  • test/model-provider.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/api/common.ts
  • app/components/chat.tsx
  • app/store/access.ts
🔇 Additional comments (6)
test/model-provider.test.ts (2)

1-3: LGTM! Test suite setup is clean and follows best practices.


1-31: Verify test coverage for getModelProvider function.

Consider running test coverage to ensure all code paths in the getModelProvider function are tested.

✅ Verification successful

Test coverage appears complete for getModelProvider function

The existing test suite adequately covers all code paths in the getModelProvider function implementation. Looking at the source code, the function is simple and straightforward - it splits the input string on the last @ character and returns a tuple. The current tests cover:

  • Input with single @ character
  • Input without @ character
  • Input with multiple @ characters (testing the last @ split behavior)
  • Empty string input

These test cases comprehensively cover all possible scenarios for this function's implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any untested code paths in getModelProvider function
# Note: This assumes Jest is configured with coverage reporting

# Test: Search for the function implementation
ast-grep --pattern $'export function getModelProvider($_) {
  $$$
}'

# Test: Look for any conditional statements that might need testing
rg -A 5 'function getModelProvider' ../app/utils/model.ts

Length of output: 191


Script:

#!/bin/bash
# Let's first locate the correct file path
fd -t f "model.ts"

# Once we find the file, we can examine its contents
fd -t f "model.ts" --exec cat {}

Length of output: 6055

app/utils/model.ts (2)

153-153: LGTM! Consistent usage of getModelProvider.

The change maintains consistency with the new model parsing approach.


40-49: LGTM! The implementation correctly handles multiple @ symbols.

The regex pattern /@(?!.*@)/ effectively splits on the last @ occurrence, which solves the original issue.

Add input validation for edge cases.

Consider adding validation for empty or null input strings to make the function more robust.

 export function getModelProvider(modelWithProvider: string): [string, string?] {
+  if (!modelWithProvider?.trim()) {
+    return [modelWithProvider, undefined];
+  }
   const [model, provider] = modelWithProvider.split(/@(?!.*@)/);
   return [model, provider];
 }

Add unit tests for the new function.

Please add unit tests to verify the behavior with various input patterns:

  • Basic model name without provider
  • Model name with single @
  • Model name with multiple @ symbols
  • Empty/null input strings
app/components/model-config.tsx (2)

10-10: LGTM! Clean import of the new utility function.

The import statement is well-placed and follows the existing import organization pattern.


32-34: Implementation correctly handles model name parsing.

The use of getModelProvider ensures proper parsing of model names containing @ symbols while maintaining validation through ModalConfigValidator.

Let's verify the handling of various model name formats:

@QAbot-zh
Copy link

QAbot-zh commented Nov 5, 2024

以前就提交过类似想法的 pr 😭
#5243

@Issues-translate-bot
Copy link

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


I have submitted a PR with similar ideas before 😭
#5243

@Dogtiti Dogtiti merged commit f3603e5 into ChatGPTNextWeb:main Nov 6, 2024
2 of 3 checks passed
@lloydzhou lloydzhou mentioned this pull request Nov 7, 2024
10 tasks
frostime added a commit to frostime/ChatGPT-Next-Web that referenced this pull request Nov 12, 2024
commit 38fa305
Author: lloydzhou <[email protected]>
Date:   Mon Nov 11 13:26:08 2024 +0800

    update version

commit 289aeec
Merge: f8f6954 7d71da9
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:19:26 2024 +0800

    Merge pull request ChatGPTNextWeb#5786 from ConnectAI-E/feature/realtime-chat

    Feature/realtime chat

commit 7d71da9
Author: lloydzhou <[email protected]>
Date:   Mon Nov 11 13:15:09 2024 +0800

    remove close-24 svg

commit f8f6954
Merge: 6e03f32 64aa760
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:13:09 2024 +0800

    Merge pull request ChatGPTNextWeb#5779 from ConnectAI-E/feature/model/claude35haiku

    add claude35haiku & not support vision

commit 6e03f32
Merge: 108069a 18a6571
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:10:00 2024 +0800

    Merge pull request ChatGPTNextWeb#5795 from JingSyue/main

    fix: built-in plugin dalle3 error ChatGPTNextWeb#5787

commit 18a6571
Author: JingSyue <[email protected]>
Date:   Mon Nov 11 12:59:29 2024 +0800

    Update proxy.ts

    Update proxy.ts

commit 14f444e
Author: Dogtiti <[email protected]>
Date:   Mon Nov 11 11:47:41 2024 +0800

    doc: realtime chat

commit 2b0f2e5
Author: JingSyue <[email protected]>
Date:   Sun Nov 10 10:28:25 2024 +0800

    fix: built-in plugin dalle3 error ChatGPTNextWeb#5787

commit 4629b39
Author: Dogtiti <[email protected]>
Date:   Sat Nov 9 16:22:01 2024 +0800

    chore: comment context history

commit d33e772
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:39:17 2024 +0800

    feat: voice print

commit 89136fb
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:18:39 2024 +0800

    feat: voice print

commit 8b4ca13
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:02:31 2024 +0800

    feat: voice print

commit a4c9eaf
Author: lloydzhou <[email protected]>
Date:   Fri Nov 8 13:43:13 2024 +0800

    do not save empty audio file

commit 50e6310
Author: lloydzhou <[email protected]>
Date:   Fri Nov 8 13:21:40 2024 +0800

    merge code and get analyser data

commit 48a1e8a
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 21:32:47 2024 +0800

    chore: i18n

commit e44ebe3
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 21:28:23 2024 +0800

    feat: realtime config

commit 108069a
Merge: fbb9385 d5bda29
Author: Lloyd Zhou <[email protected]>
Date:   Thu Nov 7 20:06:30 2024 +0800

    Merge pull request ChatGPTNextWeb#5788 from ConnectAI-E/fix-o1-maxtokens

    chore: o1模型使用max_completion_tokens

commit d5bda29
Author: DDMeaqua <[email protected]>
Date:   Thu Nov 7 19:45:27 2024 +0800

    chore: o1模型使用max_completion_tokens

commit 283caba
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 18:57:57 2024 +0800

    stop streaming play after get input audio.

commit b78e5db
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:55:51 2024 +0800

    add temperature config

commit 46c469b
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:47:55 2024 +0800

    add voice config

commit c00ebbe
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:40:03 2024 +0800

    update

commit c526ff8
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:23:20 2024 +0800

    update

commit 0037b0c
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:03:04 2024 +0800

    ts error

commit 6f81bb3
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 16:56:15 2024 +0800

    add context after connected

commit 7bdc45e
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 16:41:24 2024 +0800

    connect realtime model when open panel

commit 88cd3ac
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 12:16:11 2024 +0800

    fix: ts error

commit 4988d2e
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 11:56:58 2024 +0800

    fix: ts error

commit 8deb7a9
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 11:53:01 2024 +0800

    hotfix for update target session

commit db060d7
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 11:45:38 2024 +0800

    upload save record wav file

commit 5226278
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 09:36:22 2024 +0800

    upload save wav file logic

commit cf46d5a
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 01:12:08 2024 +0800

    upload response audio, and update audio_url to session message

commit a494152
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 22:30:02 2024 +0800

    feat: audio to message

commit f6e1f83
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 22:07:33 2024 +0800

    wip

commit d544eea
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 21:14:45 2024 +0800

    feat: realtime chat ui

commit fbb9385
Merge: 6ded4e9 18144c3
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 20:33:51 2024 +0800

    Merge pull request ChatGPTNextWeb#5782 from ConnectAI-E/style/classname

    style: improve classname by clsx

commit 18144c3
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 20:16:38 2024 +0800

    chore: clsx

commit 64aa760
Author: opchips <[email protected]>
Date:   Wed Nov 6 19:18:05 2024 +0800

    update claude rank

commit e0bbb8b
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 16:58:26 2024 +0800

    style: improve classname by clsx

commit 6667ee1
Merge: 3086a2f 6ded4e9
Author: opchips <[email protected]>
Date:   Wed Nov 6 15:08:18 2024 +0800

    merge main

commit 6ded4e9
Merge: f4c9410 85cdcab
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 15:04:46 2024 +0800

    Merge pull request ChatGPTNextWeb#5778 from ConnectAI-E/fix/5436

    fix: botMessage reply date

commit 85cdcab
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 14:53:08 2024 +0800

    fix: botMessage reply date

commit f4c9410
Merge: f526d6f adf7d82
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 14:02:20 2024 +0800

    Merge pull request ChatGPTNextWeb#5776 from ConnectAI-E/feat-glm

    fix: glm chatpath

commit adf7d82
Author: DDMeaqua <[email protected]>
Date:   Wed Nov 6 13:55:57 2024 +0800

    fix: glm chatpath

commit 3086a2f
Author: opchips <[email protected]>
Date:   Wed Nov 6 12:56:24 2024 +0800

    add claude35haiku not vision

commit f526d6f
Merge: f3603e5 106461a
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 11:16:33 2024 +0800

    Merge pull request ChatGPTNextWeb#5774 from ConnectAI-E/feature/update-target-session

    fix: updateCurrentSession => updateTargetSession

commit 106461a
Merge: c4e19db f3603e5
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 11:08:41 2024 +0800

    Merge branch 'main' of https://github.com/ConnectAI-E/ChatGPT-Next-Web into feature/update-target-session

commit c4e19db
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 11:06:18 2024 +0800

    fix: updateCurrentSession => updateTargetSession

commit f3603e5
Merge: 00d6cb2 8e2484f
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 10:49:28 2024 +0800

    Merge pull request ChatGPTNextWeb#5769 from ryanhex53/fix-model-multi@

    Custom model names can include the `@` symbol by itself.

commit 8e2484f
Author: ryanhex53 <[email protected]>
Date:   Tue Nov 5 13:52:54 2024 +0000

    Refactor: Replace all provider split occurrences with getModelProvider utility method

commit 00d6cb2
Author: lloydzhou <[email protected]>
Date:   Tue Nov 5 17:42:55 2024 +0800

    update version

commit b844045
Author: ryanhex53 <[email protected]>
Date:   Tue Nov 5 07:44:12 2024 +0000

    Custom model names can include the `@` symbol by itself.

    To specify the model's provider, append it after the model name using `@` as before.

    This format supports cases like `google vertex ai` with a model name like `claude-3-5-sonnet@20240620`.

    For instance, `claude-3-5-sonnet@20240620@vertex-ai` will be split by `split(/@(?!.*@)/)` into:

    `[ 'claude-3-5-sonnet@20240620', 'vertex-ai' ]`, where the former is the model name and the latter is the custom provider.

commit e49fe97
Merge: 14f7519 e49466f
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 15:07:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5765 from ConnectAI-E/feature/onfinish

    feat: update real 'currentSession'

commit 14f7519
Merge: 820ab54 0ec4233
Author: Dogtiti <[email protected]>
Date:   Tue Nov 5 11:07:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5767 from ConnectAI-E/feat-glm

    chore: update readme

commit 0ec4233
Author: DDMeaqua <[email protected]>
Date:   Tue Nov 5 11:06:20 2024 +0800

    chore: update readme

commit 820ab54
Merge: 0dc4071 a6c1eb2
Author: Dogtiti <[email protected]>
Date:   Tue Nov 5 10:54:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5766 from ConnectAI-E/feature/add-claude-haiku3.5

    Feature/add claude haiku3.5

commit a6c1eb2
Merge: 801dc41 0dc4071
Author: lloydzhou <[email protected]>
Date:   Tue Nov 5 10:23:15 2024 +0800

    add claude 3.5 haiku

commit 0dc4071
Merge: aef535f 4d39497
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 01:10:06 2024 +0800

    Merge pull request ChatGPTNextWeb#5464 from endless-learner/main

    Added 1-click deployment link for Alibaba Cloud.

commit 4d39497
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 01:09:27 2024 +0800

    merge main

commit aef535f
Merge: 686a80e fbb7a1e
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:41:11 2024 +0800

    Merge pull request ChatGPTNextWeb#5753 from ChatGPTNextWeb/feat-bt-doc

    Feat bt doc

commit 686a80e
Merge: 5733e3c 4b93370
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:37:34 2024 +0800

    Merge pull request ChatGPTNextWeb#5764 from ChatGPTNextWeb/dependabot/npm_and_yarn/testing-library/react-16.0.1

    chore(deps-dev): bump @testing-library/react from 16.0.0 to 16.0.1

commit e49466f
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:25:56 2024 +0800

    feat: update real 'currentSession'

commit 4b93370
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Nov 4 10:24:30 2024 +0000

    chore(deps-dev): bump @testing-library/react from 16.0.0 to 16.0.1

    Bumps [@testing-library/react](https://github.com/testing-library/react-testing-library) from 16.0.0 to 16.0.1.
    - [Release notes](https://github.com/testing-library/react-testing-library/releases)
    - [Changelog](https://github.com/testing-library/react-testing-library/blob/main/CHANGELOG.md)
    - [Commits](testing-library/react-testing-library@v16.0.0...v16.0.1)

    ---
    updated-dependencies:
    - dependency-name: "@testing-library/react"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <[email protected]>

commit 5733e3c
Merge: d66bfc6 44fc5b5
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 17:16:44 2024 +0800

    Merge pull request ChatGPTNextWeb#5759 from ConnectAI-E/feature/onfinish

    Feature/onfinish

commit 44fc5b5
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 17:00:45 2024 +0800

    fix: onfinish responseRes

commit 2d3f7c9
Author: Dogtiti <[email protected]>
Date:   Wed Oct 16 15:17:08 2024 +0800

    fix: vision model dalle3

commit fe8cca3
Merge: adf97c6 d66bfc6
Author: GH Action - Upstream Sync <[email protected]>
Date:   Sat Nov 2 01:12:09 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit fbb7a1e
Author: weige <[email protected]>
Date:   Fri Nov 1 18:20:16 2024 +0800

    fix

commit fb2c155
Author: weige <[email protected]>
Date:   Fri Nov 1 17:45:50 2024 +0800

    fix

commit c2c52a1
Author: weige <[email protected]>
Date:   Fri Nov 1 17:35:34 2024 +0800

    fix

commit 106ddc1
Author: weige <[email protected]>
Date:   Fri Nov 1 17:35:09 2024 +0800

    fix

commit 17d5209
Author: weige <[email protected]>
Date:   Fri Nov 1 17:28:20 2024 +0800

    add bt install doc

commit adf97c6
Merge: 7c466c9 0581e37
Author: GH Action - Upstream Sync <[email protected]>
Date:   Fri Nov 1 01:18:59 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit 7c466c9
Merge: b0d28eb a0fa4d7
Author: GH Action - Upstream Sync <[email protected]>
Date:   Thu Oct 31 01:14:28 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit b0d28eb
Merge: 064e964 613d67e
Author: endless-learner <[email protected]>
Date:   Tue Oct 29 14:38:49 2024 -0700

    Merge branch 'main' into main

commit 801dc41
Author: lloydzhou <[email protected]>
Date:   Thu Oct 24 15:28:05 2024 +0800

    add claude-3.5-haiku

commit 064e964
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 23:05:32 2024 -0700

    Updated link to deploy on Alibaba Cloud, readable when not logged in, also, able to choose region.

commit 47fb40d
Merge: 9e18cc2 4c84182
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 23:03:03 2024 -0700

    Merge branch 'ChatGPTNextWeb:main' into main

commit 9e18cc2
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 13:55:00 2024 -0700

    Update README.md

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

commit 03268ce
Author: endless-learner <[email protected]>
Date:   Wed Sep 18 20:38:20 2024 -0700

    Added 1-click deployment link for Alibaba Cloud.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed planned planned feature, will support in the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants