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

Ospp 2024/feat graphic dialogue #791

Conversation

Fleurxxx
Copy link

@Fleurxxx Fleurxxx commented Sep 6, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced image upload functionality within the chat interface, allowing users to select and upload images directly.
    • Added a preview area for uploaded images, with the option to delete them for enhanced user experience.
    • Updated chat message display to include uploaded images alongside text messages.
  • Bug Fixes

    • Improved error handling for image upload failures.
  • Style

    • Enhanced styling for image previews and error icons to improve visibility and alignment.
  • Chores

    • Temporarily disabled the "文心一言:ERNIE-Bot-turbo" AI model option, while retaining the "Kimi:moonshot-v1-8k" model.

@github-actions github-actions bot added the ospp-2024 ospp-2024 label Sep 6, 2024
Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Walkthrough

The changes introduce an image upload feature to the Main.vue component, enabling users to upload images directly within the chat interface. This includes new methods for managing file selection and uploads, along with updates to message display logic to accommodate images. Additionally, the robotSetting.js file has been modified to comment out an AI model option, temporarily removing it from the available choices.

Changes

File Change Summary
.../robot/src/Main.vue Added image upload functionality with new methods for file handling, updated message display logic, and styling changes for image previews. Modified function parameters and added new exported entities.
.../robot/src/js/robotSetting.js Commented out the "文心一言:ERNIE-Bot-turbo" model option, temporarily disabling it from available AI model options.
.../design-core/vite.config.js Changed the origin constant value from 'http://localhost:9090/' to 'http://localhost:7011/' and added a blank line for readability.

Poem

🐰 In the chat where bunnies hop,
New images now make the fun non-stop!
With a click, we share our sights,
Uploading joy in pixel bites.
So let’s celebrate this change today,
With fluffy hearts, we’ll chat and play! 🌼


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

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

Outside diff range, codebase verification and nitpick comments (1)
packages/plugins/robot/src/Main.vue (1)

556-619: CSS for Image Display and Animation

The CSS classes .chat-message-image and .preview-image handle the styling and animation for displayed images. The use of absolute units (px) for dimensions and animations could be improved for responsiveness.

Consider using relative units like em or % for better responsiveness across different screen sizes:

- width: 100px;
- height: 70px;
+ width: 10em;
+ height: 7em;

Also, review the keyframe animations for potential improvements in performance or visual effect.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a1afed7 and e3fa973.

Files selected for processing (2)
  • packages/plugins/robot/src/Main.vue (19 hunks)
  • packages/plugins/robot/src/js/robotSetting.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/plugins/robot/src/js/robotSetting.js

@@ -72,6 +76,7 @@
<svg-icon name="chat-message" class="common-svg"></svg-icon>
</template>
<template #suffix>
<icon-picture class="common-svg upload-image" @click="openFilePicker"></icon-picture>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure Accessibility for Image Upload Icon

The image upload icon (icon-picture) is clickable but lacks accessibility features such as aria-label or role attributes. This could hinder accessibility for users relying on screen readers.

Consider adding aria-label to improve accessibility:

- <icon-picture class="common-svg upload-image" @click="openFilePicker"></icon-picture>
+ <icon-picture class="common-svg upload-image" aria-label="Upload Image" @click="openFilePicker"></icon-picture>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<icon-picture class="common-svg upload-image" @click="openFilePicker"></icon-picture>
<icon-picture class="common-svg upload-image" aria-label="Upload Image" @click="openFilePicker"></icon-picture>

}, 500)
}

const getMessage = (content, role) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance getMessage Function with Default Parameters

The getMessage function now requires a role parameter. To ensure backward compatibility and ease of use, consider providing a default value for the role.

Add a default value for the role parameter in getMessage:

- const getMessage = (content, role) => ({
+ const getMessage = (content, role = 'user') => ({
    role,
    content,
    name: 'John'
  })
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const getMessage = (content, role) => ({
const getMessage = (content, role = 'user') => ({

Comment on lines +304 to +375
const fileInput = ref(null)
const openFilePicker = () => {
if (unref(fileInput)) {
unref(fileInput)?.click()
}
}

const imageUrl = ref('')
const imageContent = ref()
const uploadFile = (file) => {
const formData = new FormData()
const foundationModelData = JSON.stringify({
foundationModel: {
manufacturer: currentModel.manufacturer,
model: currentModel.value,
token: localStorage.getItem(currentModel.modelKey)
}
})
formData.append('foundationModel', foundationModelData)
formData.append('file', file)
http
.post('/app-center/api/ai/files', formData, {
headers: {
'Content-Type': 'multipart/form-data'
},
timeout: 600000
})
.then((res) => {
imageContent.value = res.originalResponse
const reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => {
imageUrl.value = reader.result
}
})
.catch(() => {
Notify({
type: 'error',
message: '上传图片失败',
position: 'top-right',
duration: 5000
})
})
}

const handleFileChange = (event) => {
const files = event.target.files
if (!files.length) {
return
}
const file = files[0]
const validImageTypes = ['image/jpeg', 'image/png', 'image/jpg']
if (!validImageTypes.includes(file.type)) {
alert('请上传有效的图片文件(.jpeg, .png, .jpg)!')
event.target.value = ''
return
}
event.target.value = ''
uploadFile(file)
}

const imageDeleting = ref(false)
const handleDelete = () => {
imageDeleting.value = true
setTimeout(() => {
imageUrl.value = ''
imageContent.value = ''
imageDeleting.value = false
if (unref(fileInput)) {
unref(fileInput).value = ''
}
}, 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

Review Image Upload and Deletion Logic

The methods openFilePicker, handleFileChange, uploadFile, and handleDelete handle the core functionality of image uploading and deletion. Here are some observations and suggestions:

  1. Error Handling in uploadFile: The method catches errors but only displays a notification. It might be beneficial to also reset relevant states or perform additional cleanup.
  2. File Type Validation: The validation for file types is done in handleFileChange. Consider extracting this to a separate method for better modularity and reusability.
  3. Animation Handling in handleDelete: The deletion uses a timeout to manage animations. This could be replaced with more robust animation handling techniques using Vue's transition features.

Refactor the file type validation into a separate method and improve error handling in uploadFile:

+ const isValidImageType = (fileType) => ['image/jpeg', 'image/png', 'image/jpg'].includes(fileType);

- if (!validImageTypes.includes(file.type)) {
+ if (!isValidImageType(file.type)) {
    alert('请上传有效的图片文件(.jpeg, .png, .jpg)!');
    event.target.value = '';
    return;
  }

Consider using Vue's transition for handling animations in handleDelete instead of setTimeout.

Committable suggestion was skipped due to low confidence.

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 e3fa973 and 63cef65.

Files selected for processing (1)
  • packages/design-core/vite.config.js (2 hunks)
Additional comments not posted (2)
packages/design-core/vite.config.js (2)

17-17: Verify the change in the origin constant.

The origin constant has been updated to 'http://localhost:7011/'. Please confirm that this change aligns with the intended development environment settings and that all dependent services are available at this new port.


26-26: Approved: Added blank line for readability.

The addition of a blank line after the alias configuration improves the readability of the configuration file by visually separating different sections.

@Fleurxxx Fleurxxx closed this Sep 6, 2024
@Fleurxxx Fleurxxx deleted the ospp-2024/feat-graphic-dialogue branch September 6, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ospp-2024 ospp-2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant