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 dalle3 model #5173

Merged
merged 5 commits into from
Aug 5, 2024
Merged

add dalle3 model #5173

merged 5 commits into from
Aug 5, 2024

Conversation

lloydzhou
Copy link
Member

@lloydzhou lloydzhou commented Aug 2, 2024

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

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

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

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

Summary by CodeRabbit

  • New Features

    • Introduced image generation support for the DALL-E 3 model in the chat interface.
    • Added a size selection feature for DALL-E 3 image requests, enhancing user experience.
    • Expanded API capabilities with new interfaces for handling DALL-E 3 requests and configuration options.
  • Bug Fixes

    • Improved control flow in chat session handling to ensure DALL-E 3 model requests are processed correctly.

Copy link

vercel bot commented Aug 2, 2024

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

A member of the Team first needs to authorize it.

@lloydzhou lloydzhou requested a review from Dogtiti August 2, 2024 10:02
Copy link
Contributor

coderabbitai bot commented Aug 2, 2024

Walkthrough

The recent changes enhance the ChatGPTApi and related components to support DALL-E 3 image generation. A new interface for DALL-E requests has been introduced, and existing methods have been modified to handle image responses. The chat component now features a size selection for DALL-E 3, improving user interaction. Additionally, utility functions and constants have been updated to better accommodate the new model, ultimately enhancing API functionality and responsiveness.

Changes

Files Change Summary
app/client/platforms/openai.ts, app/store/chat.ts, app/store/config.ts Enhanced handling of DALL-E 3 requests, including a new DalleRequestPayload interface and the isDalle3 utility function for model detection.
app/components/chat.tsx Added a size selector for DALL-E 3, managing size options and integrating user feedback through notifications.
app/typing.ts Introduced a new type DalleSize to define specific size options, expanding the type system for image generation.

Poem

Hop, hop, hooray, what a sight!
DALL-E 3 brings images bright.
With size and style, we choose our way,
In the chat, we play all day!
A world of colors, shapes, and dreams,
Join us now, or so it seems! πŸ‡βœ¨


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

@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 9193a9a and 1c24ca5.

Files ignored due to path filters (1)
  • app/icons/size.svg is excluded by !**/*.svg
Files selected for processing (5)
  • app/client/platforms/openai.ts (5 hunks)
  • app/components/chat.tsx (4 hunks)
  • app/constant.ts (3 hunks)
  • app/store/chat.ts (2 hunks)
  • app/utils.ts (1 hunks)
Additional comments not posted (17)
app/utils.ts (1)

269-271: LGTM!

The isDalle3 function is a straightforward and efficient addition to the utility module.

app/constant.ts (4)

149-149: LGTM!

The addition of ImagePath to OpenaiPath is a straightforward enhancement that aligns with the existing structure.


159-160: LGTM!

The addition of the ImagePath method to the Azure object is well-structured and consistent with the existing ChatPath method.


161-161: LGTM!

The update to ExampleEndpoint in Azure reflects a more generalized and flexible endpoint structure.


263-263: LGTM!

The addition of "dall-e-3" to the openaiModels array is a straightforward enhancement that aligns with the goal of integrating DALL-E 3 image generation capabilities.

app/client/platforms/openai.ts (6)

62-67: LGTM!

The DalleRequestPayload interface is well-defined and includes relevant properties for DALL-E 3 requests.


112-126: LGTM!

The modification to the extractMessage method to handle DALL-E 3 responses is straightforward and enhances the method's functionality.


140-176: LGTM!

The modifications to the chat method are well-structured and ensure appropriate handling of both DALL-E 3 and other models.


181-181: LGTM!

The adjustment to the shouldStream variable handling is logical and ensures appropriate management of streaming based on the model type.


207-215: LGTM!

The update to the path selection for API requests ensures that the correct endpoint is used based on the model type, enhancing the method's functionality.


142-142: LGTM!

The usage of the _isDalle3 function within the chat method is appropriate and ensures correct control flow based on the model type.

app/store/chat.ts (2)

29-29: Import statement for isDalle3 looks good.

The import statement is correctly added and follows the project's import conventions.


545-548: Usage of isDalle3 in summarizeSession method looks good.

The logic correctly integrates the isDalle3 function to skip summarization for the DALL-E 3 model.

app/components/chat.tsx (4)

40-40: Import statement for SizeIcon looks good.

The import statement is correctly added and follows the project's import conventions.


486-489: State and array definitions for size selection look good.

The showSizeSelector state and dalle3Sizes array are correctly defined and used.


634-641: Conditional rendering logic for size selector looks good.

The size selector is correctly rendered based on whether the current model is DALL-E 3.


642-659: Size selection handling logic looks good.

The logic correctly updates the current session's configuration and provides appropriate user feedback through a toast notification.

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 1c24ca5 and 46cb480.

Files selected for processing (5)
  • app/client/api.ts (2 hunks)
  • app/client/platforms/openai.ts (6 hunks)
  • app/components/chat.tsx (4 hunks)
  • app/store/config.ts (2 hunks)
  • app/typing.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/components/chat.tsx
Additional comments not posted (9)
app/typing.ts (1)

11-11: LGTM!

The new type DalleSize is well-defined and provides a structured way to handle specific image sizes.

app/store/config.ts (2)

2-2: LGTM!

The new import statement for DalleSize is correctly added.


64-64: LGTM!

The addition of the size property to the DEFAULT_CONFIG export is correctly typed as DalleSize and provides a default value of "1024x1024".

app/client/api.ts (2)

9-9: LGTM!

The new import statement for DalleRequestPayload is correctly added.


45-45: LGTM!

The addition of the optional size property to the LLMConfig interface is correctly typed as DalleRequestPayload["size"], enhancing the flexibility of the API.

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

63-68: Interface DalleRequestPayload looks good.

The interface is well-defined and correctly includes properties for the model, prompt, number of images, and size.


113-127: Changes to extractMessage function look good.

The function correctly handles DALL-E 3 model responses by returning an image URL when the response contains image data.


141-179: Changes to chat function look good.

The function correctly includes logic to handle DALL-E 3 model requests and constructs a DalleRequestPayload if the model is DALL-E 3. The control flow bifurcation and payload construction logic are correct.


210-218: Changes to path function look good.

The function correctly handles different paths for DALL-E 3 and other models, ensuring the correct endpoint is used based on the model type.

Copy link
Contributor

github-actions bot commented Aug 2, 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 46cb480 and 8c83fe2.

Files selected for processing (1)
  • app/client/platforms/openai.ts (8 hunks)
Additional comments not posted (11)
app/client/platforms/openai.ts (11)

14-18: Imports look good.

The new imports related to image processing (preProcessImageContent, uploadImage, base64Image2Blob) are necessary for handling DALL-E 3 image responses.


20-20: Import for DalleSize looks good.

The import for DalleSize is necessary for defining the size parameter in DALL-E 3 requests.


41-41: Alias import for isDalle3 looks good.

The alias import for isDalle3 is necessary for checking the model type in the chat method.


67-73: New interface DalleRequestPayload looks good.

The interface correctly defines the structure for DALL-E 3 requests, including properties for model, prompt, response_format, n, and size.


117-137: Handling DALL-E 3 image responses in extractMessage looks good.

The method correctly handles DALL-E 3 image responses by checking for image data, uploading base64 images if necessary, and returning the image URL.


151-166: Handling DALL-E 3 requests in chat method looks good.

The method correctly constructs a DalleRequestPayload when the model is DALL-E 3, using the last message's content as the prompt and setting appropriate parameters.


188-191: Conditional addition of max_tokens for vision models looks good.

The method correctly adds the max_tokens parameter for vision models when the model includes "preview".


196-196: Handling shouldStream for DALL-E 3 requests looks good.

The method correctly disables streaming for DALL-E 3 requests.


222-230: Path selection for DALL-E 3 requests looks good.

The method correctly selects the appropriate API path for DALL-E 3 requests based on the model type.


242-242: Increased request timeout for DALL-E 3 requests looks good.

The method correctly doubles the request timeout for DALL-E 3 requests due to the slower processing time.


373-373: Calling extractMessage for non-streaming requests looks good.

The method correctly calls extractMessage to handle the response for non-streaming requests.

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 8c83fe2 and 4a8e85c.

Files selected for processing (1)
  • app/client/platforms/openai.ts (8 hunks)
Additional comments not posted (5)
app/client/platforms/openai.ts (5)

14-18: New imports approved.

The new imports from "@/app/utils/chat" and "@/app/typing" are necessary for the added functionalities and are correctly used in the code.

Also applies to: 20-20


67-73: New interface DalleRequestPayload approved.

The interface correctly defines the structure for DALL-E 3 model requests with all necessary properties.


117-138: Changes to extractMessage method approved.

The method correctly handles DALL-E 3 model responses, including image URL extraction and base64 image conversion.


Line range hint 196-242:
Changes to fetch request in chat method approved.

The fetch request correctly handles DALL-E 3 specific logic, including timeout adjustments.


151-191: Changes to chat method approved.

The method correctly constructs the request payload for DALL-E 3 and integrates well with the existing structure.

However, ensure that all function calls to chat handle the new DALL-E 3 logic correctly.

@Dogtiti Dogtiti merged commit fec80c6 into ChatGPTNextWeb:main Aug 5, 2024
1 of 2 checks passed
@dustookk
Copy link
Contributor

dustookk commented Aug 8, 2024

Can only one image be returned at a time? Is it possible to return 4 images and then choose one for optimization?

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