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

Feature/support iflytek spark #5181

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

webws
Copy link
Contributor

@webws webws commented Aug 3, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

接入讯飞星火大模型
官方文档:https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html

📝 补充信息 | Additional Information

APIKey(假使APIKey是key123456)和APISecret(假使APISecret是secret123456),则请求头如下

Content-Type: application/json 
Authorization: Bearer key123456:secret123456

验证截图

image image image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced support for the Iflytek API, including configuration options for API key and endpoint in the settings.
    • Enhanced API client capabilities to interact seamlessly with the Iflytek service.
    • Implemented a new API route for handling requests to the Iflytek service.
    • Added comprehensive documentation for the Iflytek API integration in both English and Chinese.
  • Bug Fixes

    • Improved error handling and response management for Iflytek API requests.
  • Documentation

    • Enhanced README files with details on obtaining and using the Iflytek API key.
  • Localization

    • Added new localization entries for the Iflytek API in both English and Chinese.
  • Chores

    • Updated configuration management to support Iflytek API settings.

Copy link

vercel bot commented Aug 3, 2024

@webws 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 Aug 3, 2024

Walkthrough

The recent updates significantly enhance the integration of the IFLYTEK API across various components of the application. Key changes include the introduction of optional configuration parameters, refined documentation for developers, and improved API management features. These enhancements streamline the development process, providing developers with essential tools and information for effectively utilizing the IFLYTEK service.

Changes

Files Change Summary
README.md, README_CN.md Added documentation for optional configuration parameters (IFLYTEK_URL, IFLYTEK_API_KEY, IFLYTEK_API_SECRET).
app/api/auth.ts Introduced support for ModelProvider.Iflytek, facilitating authentication with the IFLYTEK API key.
app/api/iflytek.ts Implemented a new API handler for the IFLYTEK service, including authentication, request forwarding, and error handling.
app/client/api.ts, app/client/platforms/iflytek.ts Integrated the Iflytek model provider into ClientApi and defined the SparkApi class for IFLYTEK API interactions.
app/components/settings.tsx Added configuration inputs for IFLYTEK service settings in the application interface.
app/config/server.ts Introduced new environment variable configurations for managing the IFLYTEK API.
app/constant.ts Added constants and enumerations for the IFLYTEK service provider, enhancing model selection capabilities.
app/locales/cn.ts, app/locales/en.ts Added localization entries for the IFLYTEK API to support user interface configurations.
app/store/access.ts Enhanced access management by adding Iflytek-specific configurations and validation methods.
app/api/[provider]/[...path]/route.ts Added support for routing requests from the Iflytek provider in the existing handle function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Settings
    participant Auth
    participant IflytekAPI
    participant ClientApi

    User->>Settings: Configure Iflytek settings
    Settings->>ClientApi: Update Iflytek configurations
    User->>Auth: Request authentication (IFLYTEK_API_KEY)
    Auth->>IflytekAPI: Authenticate with API key
    IflytekAPI-->>Auth: Success or error
    Auth-->>ClientApi: Pass authentication status
    ClientApi->>IflytekAPI: Make API request
    IflytekAPI-->>ClientApi: Return response
    ClientApi-->>User: Display results
Loading

🐇 In the garden of code, with joy I hop,
New features bloom, the old ways stop.
Iflytek's magic, a key to unlock,
With every change, our skills we stock.
Hoppy updates, so bright and grand,
Together we build, side by side we stand!
🌼✨


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

github-actions bot commented Aug 3, 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, codebase verification and nitpick comments (1)
app/client/platforms/iflytek.ts (1)

38-62: Consider replacing console.log with a proper logging mechanism.

Using console.log for logging can be replaced with a more robust logging mechanism to ensure better control and consistency in log management.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d9e407f and 066ca89.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Additional comments not posted (32)
app/api/auth.ts (1)

91-93: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to auth with ModelProvider.Iflytek are correctly handled.

app/api/iflytek/[...path]/route.ts (2)

17-41: LGTM! Ensure proper error handling and logging.

The handle function is well-structured and correctly implements authentication and request handling.

However, ensure that the error handling and logging are sufficient for debugging and monitoring.


67-153: LGTM! Ensure proper URL construction and request handling.

The request function is well-implemented and correctly handles URL construction and request options.

However, ensure that the URL construction and request handling are correctly implemented and follow best practices.

app/store/access.ts (4)

54-56: LGTM! Consistent with existing API URL definitions.

The addition of DEFAULT_IFLYTEK_URL is consistent with the existing constants for other APIs.


110-113: LGTM! Consistent with existing access state definitions.

The update to DEFAULT_ACCESS_STATE is consistent with the existing structure for other APIs.


169-171: LGTM! Consistent with existing API validation methods.

The addition of isValidIflytek is consistent with the existing methods for other APIs.


187-187: LGTM! Consistent with existing authorization logic.

The integration of isValidIflytek into the isAuthorized method is consistent with the existing validation logic for other APIs.

app/config/server.ts (3)

69-71: LGTM!

The new environment variables for Iflytek API are correctly added and follow the existing pattern.


138-138: LGTM!

The boolean variable isIflytek is correctly introduced to check the presence of the IFLYTEK_API_KEY.


196-198: LGTM!

The iflytekUrl and iflytekApiKey are correctly added to the return object.

README_CN.md (1)

175-176: LGTM!

The documentation for IFLYTEK_API_KEY is clear and follows the existing format for other API keys.

app/client/api.ts (5)

17-17: LGTM!

The import statement for SparkApi is correctly added and follows the existing pattern for other API integrations.


128-130: LGTM!

The new case for ModelProvider.Iflytek is correctly added to the ClientApi constructor.


214-214: LGTM!

The new variable isIflytek is correctly added to the getHeaders function.


228-229: LGTM!

The iflytekApiKey is correctly added to the getConfig function.


293-294: LGTM!

The new case for ServiceProvider.Iflytek is correctly added to the getClientApi function.

app/client/platforms/iflytek.ts (4)

65-67: LGTM!

The method correctly removes the spark- prefix from the model name.


68-70: LGTM!

The method correctly extracts the message content from the response.


238-242: LGTM!

The method correctly returns the usage object.


245-247: LGTM!

The method correctly returns an empty array.

app/constant.ts (7)

29-29: LGTM!

The constant IFLYTEK_BASE_URL is correctly defined.


57-57: LGTM!

The new entry for Iflytek is correctly added to the ApiPath enumeration.


114-114: LGTM!

The new entry for Iflytek is correctly added to the ServiceProvider enumeration.


136-136: LGTM!

The new entry for Iflytek is correctly added to the ModelProvider enumeration.


209-212: LGTM!

The constant Iflytek is correctly defined.


332-338: LGTM!

The constant iflytekModels is correctly defined.


422-430: LGTM!

The updates to include mappings for the Iflytek models are correctly made.

app/locales/cn.ts (1)

434-444: LGTM!

The localization entries for Iflytek are correctly defined.

app/locales/en.ts (2)

417-422: Localization entry for Iflytek API Key looks good.

The titles and placeholders are clear and consistent with other entries.


423-426: Localization entry for Iflytek Endpoint looks good.

The titles and subtitles are clear and consistent with other entries.

README.md (1)

283-285: Documentation for IFLYTEK_API_KEY looks good.

The instructions are clear and provide necessary details on obtaining and using the API key.

app/components/settings.tsx (1)

1176-1213: Configuration component for Iflytek looks good.

The input fields for the endpoint URL and API key are clear and consistent with other configuration components.

app/client/platforms/iflytek.ts Outdated Show resolved Hide resolved
@webws webws force-pushed the feature/support-iflytek-spark branch from 066ca89 to 40adf65 Compare August 3, 2024 14:09
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 066ca89 and 40adf65.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/platforms/iflytek.ts
Files skipped from review as they are similar to previous changes (11)
  • README.md
  • README_CN.md
  • app/api/auth.ts
  • app/api/iflytek/[...path]/route.ts
  • app/client/api.ts
  • app/components/settings.tsx
  • app/config/server.ts
  • app/constant.ts
  • app/locales/cn.ts
  • app/locales/en.ts
  • app/store/access.ts

@webws webws force-pushed the feature/support-iflytek-spark branch from 40adf65 to 4c6d70d Compare August 3, 2024 14:57
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40adf65 and 4c6d70d.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • README.md
Files skipped from review as they are similar to previous changes (11)
  • README_CN.md
  • app/api/auth.ts
  • app/api/iflytek/[...path]/route.ts
  • app/client/api.ts
  • app/client/platforms/iflytek.ts
  • app/components/settings.tsx
  • app/config/server.ts
  • app/constant.ts
  • app/locales/cn.ts
  • app/locales/en.ts
  • app/store/access.ts

README.md Show resolved Hide resolved
app/components/settings.tsx Outdated Show resolved Hide resolved
app/components/settings.tsx Outdated Show resolved Hide resolved
@Dogtiti Dogtiti self-assigned this Aug 3, 2024
@webws webws force-pushed the feature/support-iflytek-spark branch from 4c6d70d to 2c27cab Compare August 3, 2024 15:46
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c6d70d and 2c27cab.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/platforms/iflytek.ts
Files skipped from review as they are similar to previous changes (9)
  • README.md
  • app/api/iflytek/[...path]/route.ts
  • app/client/api.ts
  • app/components/settings.tsx
  • app/config/server.ts
  • app/constant.ts
  • app/locales/cn.ts
  • app/locales/en.ts
  • app/store/access.ts
Additional comments not posted (2)
app/api/auth.ts (1)

91-93: LGTM! The new case for ModelProvider.Iflytek is correctly implemented.

The code correctly assigns the iflytekApiKey to systemApiKey when the modelProvider is ModelProvider.Iflytek.

README_CN.md (1)

175-178: LGTM! The new section for IFLYTEK_API_KEY configuration is well-integrated and clear.

The instructions provide essential guidance for users to configure the IFLYTEK_API_KEY correctly.

@webws webws requested a review from Dogtiti August 3, 2024 15:51
@webws webws force-pushed the feature/support-iflytek-spark branch from 2c27cab to beadcb5 Compare August 3, 2024 16:12
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c27cab and beadcb5.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • README_CN.md
Files skipped from review as they are similar to previous changes (9)
  • README.md
  • app/api/iflytek/[...path]/route.ts
  • app/client/platforms/iflytek.ts
  • app/components/settings.tsx
  • app/config/server.ts
  • app/constant.ts
  • app/locales/cn.ts
  • app/locales/en.ts
  • app/store/access.ts
Additional comments not posted (5)
app/api/auth.ts (1)

91-93: LGTM! Ensure consistency with other model providers.

The new case for ModelProvider.Iflytek correctly assigns the iflytekApiKey to systemApiKey. Ensure that similar handling is applied consistently across other model providers.

app/client/api.ts (4)

17-17: LGTM! Import statement for SparkApi.

The new import statement for SparkApi is necessary for the integration and correctly added.


128-130: LGTM! Ensure consistency with other model providers.

The new case for ModelProvider.Iflytek correctly assigns a new instance of SparkApi to this.llm. Ensure that similar handling is applied consistently across other model providers.


214-215: LGTM! Ensure consistency with other service providers.

The new variable isIflytek and the handling for the Iflytek provider in the getHeaders function are correctly added. Ensure that similar handling is applied consistently across other service providers.

Also applies to: 228-229, 239-239


293-294: LGTM! Ensure consistency with other service providers.

The new case for ServiceProvider.Iflytek correctly returns a new instance of ClientApi for the Iflytek service provider. Ensure that similar handling is applied consistently across other service providers.

README_CN.md Outdated Show resolved Hide resolved
@Dogtiti
Copy link
Member

Dogtiti commented Aug 5, 2024

#5190

另外需要参照这个pr把api route合并
解决多个api route在cf上部署多大的问题

@Issues-translate-bot
Copy link

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


#5190

In addition, you need to refer to this PR to merge the api route.
Solve the problem of how large multiple api routes are deployed on cf

@webws webws force-pushed the feature/support-iflytek-spark branch from beadcb5 to c7e45f2 Compare August 5, 2024 15:57
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between beadcb5 and c7e45f2.

Files selected for processing (12)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/auth.ts (2 hunks)
  • app/api/iflytek/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review as they are similar to previous changes (7)
  • README.md
  • app/api/iflytek/[...path]/route.ts
  • app/client/api.ts
  • app/client/platforms/iflytek.ts
  • app/constant.ts
  • app/locales/en.ts
  • app/store/access.ts
Additional comments not posted (14)
app/api/auth.ts (2)

91-93: Ensure correct concatenation of API key and secret.

The concatenation of serverConfig.iflytekApiKey and serverConfig.iflytekApiSecret appears correct. Ensure that both values are properly set in the configuration.


105-105: Logging system API key.

Ensure that logging the systemApiKey does not expose sensitive information in production environments.

app/config/server.ts (7)

70-70: Declaration of IFLYTEK_URL.

The declaration of IFLYTEK_URL appears correct and follows the existing pattern.


71-71: Declaration of IFLYTEK_API_KEY.

The declaration of IFLYTEK_API_KEY appears correct and follows the existing pattern.


72-72: Declaration of IFLYTEK_API_SECRET.

The declaration of IFLYTEK_API_SECRET appears correct and follows the existing pattern.


139-139: Declaration of isIflytek.

The declaration of isIflytek appears correct and follows the existing pattern.


198-198: Declaration of iflytekUrl.

The declaration of iflytekUrl appears correct and follows the existing pattern.


199-199: Declaration of iflytekApiKey.

The declaration of iflytekApiKey appears correct and follows the existing pattern.


200-200: Declaration of iflytekApiSecret.

The declaration of iflytekApiSecret appears correct and follows the existing pattern.

README_CN.md (3)

176-178: Documentation for IFLYTEK_URL.

The documentation for IFLYTEK_URL appears clear and follows the existing pattern.


180-182: Documentation for IFLYTEK_API_KEY.

The documentation for IFLYTEK_API_KEY appears clear and follows the existing pattern.


184-186: Documentation for IFLYTEK_API_SECRET.

The documentation for IFLYTEK_API_SECRET appears clear and follows the existing pattern.

app/locales/cn.ts (1)

434-449: LGTM! New localization entries are correctly formatted.

The new entries for the Iflytek API provide clear and accurate information for users.

app/components/settings.tsx (1)

1176-1229: LGTM! New configuration component for Iflytek service is correctly implemented.

The new component integrates well with the existing code and provides necessary input fields for the Iflytek service.

However, ensure that the new configuration component is correctly integrated and used in the codebase.

Verification successful

The new configuration component for Iflytek service is correctly integrated and used within the codebase.

The component lflytekConfigComponent is defined and utilized within app/components/settings.tsx, confirming its proper integration.

  • app/components/settings.tsx: Definition and usage of lflytekConfigComponent.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration and usage of the new configuration component.

# Test: Search for the usage of `lflytekConfigComponent`. Expect: Occurrences of the new component in the codebase.
rg --type tsx -A 5 $'lflytekConfigComponent'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the integration and usage of the new configuration component.

# Test: Search for the usage of `lflytekConfigComponent`. Expect: Occurrences of the new component in the codebase.
rg -A 5 'lflytekConfigComponent'

Length of output: 676

@Dogtiti
Copy link
Member

Dogtiti commented Aug 6, 2024

#5190

另外需要参照这个pr把api route合并 解决多个api route在cf上部署多大的问题

@webws 解决一下冲突和这个就可以合了~

@Issues-translate-bot
Copy link

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


#5190

In addition, you need to refer to this PR to merge the api routes to solve the problem of how large multiple api routes are deployed on cf.

@webws Resolve the conflict and it will be combined~

@webws webws force-pushed the feature/support-iflytek-spark branch from c7e45f2 to 6b4606e Compare August 6, 2024 07:31
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c7e45f2 and 6b4606e.

Files selected for processing (13)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/[provider]/[...path]/route.ts (2 hunks)
  • app/api/auth.ts (2 hunks)
  • app/api/iflytek.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (3)
  • README.md
  • README_CN.md
  • app/locales/en.ts
Files skipped from review as they are similar to previous changes (8)
  • app/api/auth.ts
  • app/client/api.ts
  • app/client/platforms/iflytek.ts
  • app/components/settings.tsx
  • app/config/server.ts
  • app/constant.ts
  • app/locales/cn.ts
  • app/store/access.ts
Additional comments not posted (10)
app/api/[provider]/[...path]/route.ts (2)

12-12: Import statement for iflytekHandler looks good.

The import statement correctly follows the format of other handlers.


37-38: Switch case for ApiPath.Iflytek looks good.

The switch case correctly routes requests to the iflytekHandler.

app/api/iflytek.ts (8)

1-12: Import statements look good.

The import statements correctly follow the format of other modules and bring in necessary modules and constants.


18-26: Logging and OPTIONS request handling look good.

The function includes logging and correctly handles OPTIONS requests.


35-41: Request processing and error handling look good.

The function processes the request and includes error handling.


68-92: URL construction and timeout handling look good.

The function correctly constructs the URL and handles timeouts.


108-137: Request filtering logic looks good.

The function includes logic to filter requests based on custom models.


138-154: Response processing looks good.

The function correctly processes the response and handles headers.


94-106: Verify the request options setup.

The request options setup looks correct, but ensure that the headers and other options are correctly set for the iflytek API.

Verification successful

Request options setup is correct.

The headers and other options for the iflytek API are correctly set in the fetchOptions configuration.

  • Headers:
    • Content-Type: "application/json"
    • Authorization: Conditionally set from the request headers.
  • Method: Set to req.method.
  • Body: Set to req.body.
  • Redirect: "manual"
  • Duplex: "half" (with @ts-ignore).
  • Signal: Set to controller.signal.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the request options are correctly set for the `iflytek` API.

# Test: Search for the request options setup. Expect: Correct headers and other options for the `iflytek` API.
rg --type python -A 5 $'fetchOptions'

Length of output: 67


Script:

#!/bin/bash
# Description: Verify that the request options are correctly set for the `iflytek` API.

# Test: Search for the request options setup. Expect: Correct headers and other options for the `iflytek` API.
rg --type ts -A 5 'fetchOptions'

Length of output: 10459


28-33: Verify the authentication logic.

The authentication logic looks correct, but ensure that the auth function works as expected for the iflytek provider.

app/constant.ts Show resolved Hide resolved
@webws webws force-pushed the feature/support-iflytek-spark branch from 6b4606e to ff5626b Compare August 6, 2024 07:48
HyiKi added 3 commits August 6, 2024 15:50
change the summary role from system to user
fix "Messages 中 system 角色必须位于列表的最开始"
@webws webws force-pushed the feature/support-iflytek-spark branch from ff5626b to 9f2a06a Compare August 6, 2024 07:50
@webws webws requested review from Dogtiti and lloydzhou August 6, 2024 08:00
app/api/auth.ts Outdated
@@ -98,7 +102,7 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
}

if (systemApiKey) {
console.log("[Auth] use system api key");
console.log("[Auth] use system api key", systemApiKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

这里不建议直接打印apikey到日志中(鉴于一些运维的经验)

export const GET = handle;
export const POST = handle;

export const runtime = "edge";
Copy link
Contributor

Choose a reason for hiding this comment

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

因为cf的原因,将api合并一起之后,这个文件不需要导出 GET, POST, runtime以及preferredRegion

@webws webws force-pushed the feature/support-iflytek-spark branch from 9f2a06a to 3f2e7df Compare August 6, 2024 08:36
@lloydzhou
Copy link
Contributor

image

please resolve typescript error

@webws webws force-pushed the feature/support-iflytek-spark branch from 3f2e7df to b2c1644 Compare August 6, 2024 09:55
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6b4606e and b2c1644.

Files selected for processing (15)
  • README.md (1 hunks)
  • README_CN.md (1 hunks)
  • app/api/[provider]/[...path]/route.ts (2 hunks)
  • app/api/auth.ts (1 hunks)
  • app/api/iflytek.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/baidu.ts (1 hunks)
  • app/client/platforms/iflytek.ts (1 hunks)
  • app/client/platforms/tencent.ts (1 hunks)
  • app/components/settings.tsx (3 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/access.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • README.md
Files skipped from review as they are similar to previous changes (10)
  • README_CN.md
  • app/api/[provider]/[...path]/route.ts
  • app/api/iflytek.ts
  • app/client/api.ts
  • app/client/platforms/iflytek.ts
  • app/components/settings.tsx
  • app/constant.ts
  • app/locales/cn.ts
  • app/locales/en.ts
  • app/store/access.ts
Additional comments not posted (6)
app/api/auth.ts (1)

91-93: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to auth with ModelProvider.Iflytek are correctly handled.

Verification successful

Function usage with ModelProvider.Iflytek is correctly handled.

The auth function is called with ModelProvider.Iflytek in app/api/iflytek.ts, confirming that the usage is correctly handled.

  • app/api/iflytek.ts: auth(req, ModelProvider.Iflytek);
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `auth` with `ModelProvider.Iflytek`.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'auth($_, ModelProvider.Iflytek)'

Length of output: 53


Script:

#!/bin/bash
# Description: Verify all occurrences of ModelProvider.Iflytek and cross-reference with auth function.

# Search for all occurrences of ModelProvider.Iflytek in the codebase.
rg --type ts 'ModelProvider.Iflytek' -A 5

Length of output: 1065

app/config/server.ts (2)

69-72: LGTM!

The changes correctly add the necessary environment variables for the Iflytek API integration.


Line range hint 139-201:
LGTM!

The changes correctly integrate the Iflytek API configurations into the server configuration.

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

94-96: LGTM! But verify the logic.

The code changes are approved.

However, ensure that the logic for changing the role of messages is correctly implemented and does not introduce any issues.

Verification successful

The logic for changing the role of messages is correctly implemented.

The chat method in app/client/platforms/tencent.ts ensures that only the first message can have the "system" role, as intended.

  • The role of messages is changed to "user" if they are not the first message and their role is "system".
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic for changing the role of messages in the chat method.

# Test: Search for the chat method usage. Expect: Correct implementation of the role change logic.
rg --type ts -A 10 $'chat(options: ChatOptions)'

Length of output: 49


Script:

#!/bin/bash
# Description: Search for the definition of the chat method and its usage in the codebase.

# Step 1: Search for the chat method definition in TypeScript files.
echo "Searching for chat method definition..."
rg --type ts 'chat('

# Step 2: Search for the usage of the chat method in TypeScript files.
echo "Searching for chat method usage..."
rg --type ts 'chat('

Length of output: 335


Script:

#!/bin/bash
# Description: Search for the definition of the chat method and its usage in the codebase.

# Step 1: Search for the chat method definition in TypeScript files.
echo "Searching for chat method definition..."
rg --type ts 'chat\('

# Step 2: Search for the usage of the chat method in TypeScript files.
echo "Searching for chat method usage..."
rg --type ts 'chat\('

Length of output: 1917


Script:

#!/bin/bash
# Description: Extract lines around the chat method in app/client/platforms/tencent.ts to verify the logic.

# Step 1: Extract lines around the chat method in tencent.ts.
echo "Extracting lines around the chat method in tencent.ts..."
rg --type ts -A 20 -B 10 'async chat\(options: ChatOptions\)' app/client/platforms/tencent.ts

Length of output: 1117

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

80-81: Ensure correct role mapping for messages.

The role mapping logic correctly changes "system" roles to "user" roles. This ensures that only "user" or "function" roles are retained for messages at even indices.


87-97: Optimize message array length adjustment.

The logic to adjust the message array when its length is even is well-implemented. It checks if the first message's role is "user" and inserts an "assistant" role message at the second position if true. Otherwise, it unshifts a "user" message. This ensures the message structure adheres to specific role requirements.

app/api/auth.ts Show resolved Hide resolved
@webws webws requested review from Dogtiti and lloydzhou August 6, 2024 10:34
@Dogtiti Dogtiti merged commit 9bbb4f3 into ChatGPTNextWeb:main Aug 6, 2024
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 23, 2024
10 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 4, 2024
10 tasks
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.

5 participants