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

add moonshot api #5156

Merged
merged 3 commits into from
Aug 1, 2024
Merged

add moonshot api #5156

merged 3 commits into from
Aug 1, 2024

Conversation

lloydzhou
Copy link
Contributor

@lloydzhou lloydzhou commented Aug 1, 2024

πŸ’» ε˜ζ›΄η±»εž‹ | Change Type

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

πŸ”€ ε˜ζ›΄θ―΄ζ˜Ž | Description of Change

πŸ“ θ‘₯充俑息 | Additional Information

Summary by CodeRabbit

  • New Features

    • Introduced support for the Moonshot API, enhancing model provider capabilities.
    • Added new server-side route handler for Moonshot API requests, supporting GET and POST methods.
    • Implemented the MoonshotApi class for streamlined chat interactions with the language model.
    • Enhanced configuration options for integrating Moonshot, including environment variables and constants.
  • Bug Fixes

    • Improved error handling and response processing for Moonshot API interactions.
  • Documentation

    • Updated configuration documentation to reflect new Moonshot integration details.

Copy link

vercel bot commented Aug 1, 2024

@lloydzhou is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Aug 1, 2024

Warning

Rate limit exceeded

@lloydzhou has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 46 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between b8bbc37 and 966db1e.

Walkthrough

The recent changes enhance the application by integrating a new model provider, Moonshot, into the authentication and API handling mechanisms. This includes updates across multiple files to support new routes, API interactions, and configuration settings, ensuring robust error handling and management for Moonshot requests. The modifications allow the application to seamlessly interact with Moonshot's functionalities, expanding its versatility and capabilities.

Changes

Files Change Summary
app/api/auth.ts
app/api/moonshot/[...path]/route.ts
app/client/api.ts
app/client/platforms/moonshot.ts
app/config/server.ts
app/constant.ts
app/store/access.ts
Introduced support for the Moonshot model provider, enhancing authentication functions, API routes, and configuration management. New constants and methods were added to manage Moonshot-specific interactions and state, improving overall API handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Auth
    participant MoonshotAPI
    participant Server

    Client->>Auth: Request with ModelProvider.Moonshot
    Auth->>Server: Validate Moonshot API Key
    alt Valid API Key
        Server->>MoonshotAPI: Process Request
        MoonshotAPI-->>Server: Return Response
        Server-->>Auth: Forward Response
        Auth-->>Client: Return Response
    else Invalid API Key
        Auth-->>Client: Return 401 Unauthorized
    end
Loading

πŸ‡ In the meadow, I hop with glee,
New features bloom, as bright as can be!
With Moonshot’s charm, our paths align,
A world of wonders, where models shine.
Through code and dreams, we leap and play,
Celebrating changes, hip-hip-hooray! 🌷✨


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 1, 2024

Your build has completed!

Preview deployment

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 c9eb9f3 and b8bbc37.

Files selected for processing (7)
  • app/api/auth.ts (1 hunks)
  • app/api/moonshot/[...path]/route.ts (1 hunks)
  • app/client/api.ts (6 hunks)
  • app/client/platforms/moonshot.ts (1 hunks)
  • app/config/server.ts (3 hunks)
  • app/constant.ts (7 hunks)
  • app/store/access.ts (4 hunks)
Additional comments not posted (25)
app/api/auth.ts (1)

88-90: LGTM!

The new case for ModelProvider.Moonshot correctly assigns serverConfig.moonshotApiKey to systemApiKey.

app/api/moonshot/[...path]/route.ts (3)

17-41: LGTM!

The handle function correctly handles incoming requests, performs authentication for Moonshot, and proxies the request.


67-153: LGTM!

The request function correctly constructs the request to be proxied to Moonshot, including handling URL construction, setting headers, handling timeouts, and processing the response.


107-136: LGTM!

The isModelAvailableInServer function correctly checks if a given model is available in the server configuration.

app/store/access.ts (4)

42-44: LGTM!

The DEFAULT_MOONSHOT_URL constant correctly constructs the URL for the Moonshot API based on the application's context.


89-92: LGTM!

The DEFAULT_ACCESS_STATE constant correctly includes moonshotUrl and moonshotApiKey for storing Moonshot-specific configuration.


145-147: LGTM!

The isValidMoonshot method correctly checks the validity of the Moonshot API key.


161-161: LGTM!

The isAuthorized method correctly includes the Moonshot API key validation in the overall authorization check.

app/config/server.ts (2)

60-63: LGTM!

The addition of MOONSHOT_URL and MOONSHOT_API_KEY to the ProcessEnv interface is consistent with the existing pattern for other providers.


127-129: LGTM!

The integration of Moonshot-specific configurations in getServerSideConfig is consistent with the existing pattern for other providers.

Also applies to: 176-179

app/client/api.ts (3)

15-15: LGTM!

The addition of the MoonshotApi import statement is straightforward and necessary for the integration of the Moonshot provider.


121-123: LGTM!

The addition of the Moonshot case in the ClientApi constructor is consistent with the existing pattern for other providers.


Line range hint 206-228:
LGTM!

The integration of Moonshot-specific logic in getHeaders and getClientApi is consistent with the existing pattern for other providers.

Also applies to: 278-279

app/client/platforms/moonshot.ts (5)

1-37: LGTM! But clarify the disableListModels property.

The implementation of the MoonshotApi class follows the existing pattern for other providers. However, the disableListModels property is set to true without explanation.

Could you please clarify why disableListModels is set to true?


38-63: LGTM!

The implementation of the path method follows the existing pattern for other providers and correctly constructs the base URL for Moonshot API requests.


65-67: LGTM!

The implementation of the extractMessage method follows the existing pattern for other providers and correctly extracts the message content from the response.


69-240: LGTM!

The implementation of the chat method follows the existing pattern for other providers and correctly handles chat requests and responses, including streaming responses.


241-250: LGTM! But clarify the models method.

The implementation of the usage and models methods follows the existing pattern for other providers. However, the models method returns an empty array, which might need further implementation.

Could you please clarify if the models method is intended to return an empty array, or if further implementation is needed?

app/constant.ts (7)

25-25: LGTM!

The addition of the MOONSHOT_BASE_URL constant is correct.


51-51: LGTM!

The addition of the Moonshot entry to the ApiPath enum is correct.


105-105: LGTM!

The addition of the Moonshot entry to the ServiceProvider enum is correct.


126-126: LGTM!

The addition of the Moonshot entry to the ModelProvider enum is correct.


190-193: LGTM!

The addition of the Moonshot constant with ExampleEndpoint and ChatPath is correct.


301-301: LGTM!

The addition of the moonshotModes array is correct.


367-375: LGTM!

The integration of moonshotModes into the DEFAULT_MODELS export is correct.

@Dogtiti
Copy link
Member

Dogtiti commented Aug 1, 2024

#5094

@Dogtiti Dogtiti merged commit f6a6c51 into ChatGPTNextWeb:main Aug 1, 2024
1 of 2 checks passed
@Issues-translate-bot
Copy link

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


#5094

@lloydzhou lloydzhou deleted the feature/moonshot branch August 5, 2024 07:07
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.

3 participants