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

feat: Chat ai setting #4619

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/assets/img/deepSeek.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
299 changes: 198 additions & 101 deletions src/components/Apps/ChatAi/components/ChitChat/ChatMessage.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,71 @@
<template>
<div :class="{'user-role': isUserRole}" class="chat-item">
<div class="avatar">
<el-avatar :src="isUserRole ? userUrl : chatUrl" class="header-avatar" />
</div>
<div class="content">
<div class="operational">
<span class="date">
{{ $moment(item.message.create_time).format('YYYY-MM-DD HH:mm:ss') }}
</span>
<div :class="{ 'user-role': isUserRole }" class="chat-item">
<div class="chart-item-container">
<div class="avatar">
<el-avatar
:src="isUserRole ? userUrl : chatUrl"
class="header-avatar"
/>
</div>
<div class="message">
<div class="message-content">
<span v-if="isSystemError" class="error">
{{ item.message.content }}
</span>
<span v-else class="chat-text">
<MessageText :message="item.message" />
</span>
<div class="content">
<div class="operational">
<div v-if="!item.message.is_reasoning" class="date">
{{
$moment(item.message.create_time).format("YYYY-MM-DD HH:mm:ss")
}}
</div>

<div v-else class="thinking-time">已深度思考</div>
</div>
<div class="action">
<el-tooltip
v-if="isSystemError && isLoading"
:content="$tc('Reconnect')"
:open-delay="500"
placement="top"
>
<svg-icon icon-class="refresh" @click="onRefresh" />
</el-tooltip>
<el-dropdown v-else size="small" @command="handleCommand">
<span class="el-dropdown-link">
<i class="fa fa-ellipsis-v" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="i in dropdownOptions" :key="i.action" :command="i.action">
{{ i.label }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<div :class="item.reasoning ? 'reasoning' : 'message'">
<div class="message-content">
<div v-if="!item.reasoning">
<span v-if="isSystemError" class="error">
{{ item.message.content }}
</span>
<span v-else class="chat-text">
<MessageText :message="item.message" />
</span>
</div>

<div v-else class="thinking-wrapper">
<div class="thinking-content">
<!-- eslint-disable-next-line -->
<div class="divider"></div>
<p>
<MessageText :message="item.reasoning" />
</p>
</div>

<div class="thinking-result">
<MessageText :message="item.result" />
</div>
</div>
</div>
<div class="action">
<el-tooltip
v-if="isSystemError && isLoading"
:content="$tc('Reconnect')"
:open-delay="500"
placement="top"
>
<svg-icon icon-class="refresh" @click="onRefresh" />
</el-tooltip>
<el-dropdown v-else size="small" @command="handleCommand">
<span class="el-dropdown-link">
<i class="fa fa-ellipsis-v" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item
v-for="i in dropdownOptions"
:key="i.action"
:command="i.action"
>
{{ i.label }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</div>
</div>
Expand All @@ -45,7 +74,7 @@

<script>
import MessageText from './MessageText.vue'
import { mapState } from 'vuex'
import { mapGetters, mapState } from 'vuex'
import { copy } from '@/utils/common'
import { useChat } from '../../useChat.js'
import { reconnect } from '@/utils/socket'
Expand All @@ -65,7 +94,6 @@ export default {
},
data() {
return {
chatUrl: require('@/assets/img/chat.png'),
userUrl: '/api/v1/settings/logo/',
dropdownOptions: [
{
Expand All @@ -79,11 +107,21 @@ export default {
...mapState({
isLoading: state => state.chat.loading
}),
...mapGetters([
'publicSettings'
]),
isUserRole() {
return this.item.message?.role === 'user'
},
isSystemError() {
return this.item.type === 'error' && this.item.message?.role === 'assistant'
return (
this.item.type === 'error' && this.item?.role === 'assistant'
)
},
chatUrl() {
return this.publicSettings.CHAT_AI_TYPE === 'gpt'
? require('@/assets/img/chat.png')
: require('@/assets/img/deepSeek.png')
}
},
methods: {
Expand All @@ -94,7 +132,7 @@ export default {
},
handleCommand(value) {
if (value === 'copy') {
copy(this.item.message.content)
copy(this.item.result.content)
}
}
}
Expand All @@ -104,101 +142,160 @@ export default {
<style lang="scss" scoped>
.chat-item {
display: flex;
padding: 16px 14px 0;
padding: 0.5rem;

&:last-child {
padding-bottom: 16px;
}
.chart-item-container {
display: flex;
gap: 0.5rem;

.avatar {
width: 22px;
height: 22px;
margin-top: 2px;
.avatar {
width: 24px;
height: 24px;
margin-top: 2px;

.header-avatar {
width: 100%;
height: 100%;
.header-avatar {
width: 100%;
height: 100%;
border-radius: 50%;

&::v-deep img {
background-color: #e5e5e7;
&::v-deep img {
background-color: #fff;
}
}
}
}

.content {
margin-left: 6px;
overflow: hidden;

.operational {
.content {
display: flex;
justify-content: space-between;
flex-direction: column;
gap: 0.5rem;
overflow: hidden;

.copy {
float: right;
cursor: pointer;
}
}
.operational {
display: flex;
justify-content: space-between;
overflow: hidden;

.message {
display: -webkit-box;
.date {
padding-top: 5px;
}

.message-content {
flex: 1;
padding: 6px 10px;
border-radius: 2px 12px 12px;
background-color: #f0f1f5;
}
.thinking-time {
width: 6rem;
display: flex;
justify-content: center;
padding: 5px 10px;
border-radius: 0.5rem;
background-color: #f5f5f5;
}

.action {
.svg-icon {
transform: translateY(50%);
margin-left: 3px;
.copy {
float: right;
cursor: pointer;
}
}

.el-dropdown {
height: 32px;
line-height: 37px;
font-size: 13px;
.reasoning {
display: flex;
gap: 0.5rem;
align-items: flex-end;

.el-dropdown-link {
i {
padding: 4px 5px;
font-size: 15px;
color: #8d9091;
.message-content .thinking-wrapper {
display: flex;
flex-direction: column;
gap: 0.5rem;

&:hover {
color: #7b8085
.thinking-content {
position: relative;
color: #8b8b8b;

.divider {
position: absolute;
top: 0;
left: 0;
height: 100%;
border-left: 2px solid #e5e5e5;
}

p {
margin: unset;
padding-left: 0.5rem;

::v-deep p {
color: #8b8b8b;
}
}
}
}
}

.error {
color: red;
.message {
display: -webkit-box;

.message-content {
flex: 1;
padding: 6px 10px;
border-radius: 2px 12px 12px;
background-color: #f0f1f5;
}

.action {
.svg-icon {
transform: translateY(50%);
margin-left: 3px;
cursor: pointer;
}

.el-dropdown {
height: 32px;
line-height: 37px;
font-size: 13px;

.el-dropdown-link {
i {
padding: 4px 5px;
font-size: 15px;
color: #8d9091;

&:hover {
color: #7b8085;
}
}
}
}
}

.error {
color: red;
}
}
}
}
}

.user-role {
flex-direction: row-reverse;
&:last-child {
padding-bottom: 16px;
}

.content {
margin-right: 10px;
&.user-role {
flex-direction: row-reverse;

.operational {
.chart-item-container {
flex-direction: row-reverse;
}

.message {
flex-direction: row-reverse;
.content {
margin-right: 10px;

.operational {
flex-direction: row-reverse;
}

.message-content {
background-color: var(--menu-hover);
border-radius: 12px 2px 12px 12px;
.message {
flex-direction: row-reverse;

.message-content {
background-color: var(--menu-hover);
border-radius: 12px 2px 12px 12px;
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

In conclusion, the main difference between old and new version of Vue component seems that it's using different style sheet for Avatar with v-if condition. Additionally, some HTML attributes seem not fully compatible across both versions like "data-" attribute vs class name, and CSS rule usage.

There may also be issues related to the implementation of loading spinner inside tooltip <el-tooltip> (if implemented).

Optimization:

  • Consider moving common styles into shared components file
  • Simplify repetitive code blocks

Potential improvements could include refactoring code logic where unnecessary parts are merged together. This can improve legibility and make it easier to manage similar functionality.

To achieve better performance, consider optimizing rendering times for complex elements through async rendering techniques or memoization strategies.

For security considerations, ensure sensitive information such as API keys is properly encapsulated or stored securely and accessible via secure channels only.

Please note that these guidelines will vary based on specific needs and constraints which we don't have access to here.

If you need further help covering other areas within your project, please do let us know!

Copy link
Member

Choose a reason for hiding this comment

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

There doesn't appear to be significant discrepancies or errors in the provided VueJS template component code snippet. The changes seem minor stylistic enhancements like adjusting text sizes, altering styles for icons and components, and adding extra spacing. However, it would benefit from consistency across all elements for improved readability.

For instance, ensuring consistent styling choices across different elements such as colors, fonts, or layout adjustments could improve UX aesthetics and consistency. Also, some components have padding attributes that might not affect their visual layout but should be reviewed because they can impact rendering performance especially under high load scenarios on mobile devices or other environments where images may take up more memory due to loading animations etc...

It's recommended to thoroughly review your Vue templates with linting tools at least once per coding cycle so that issues of maintainability, clarity or efficiency become apparent early enough rather than during production deployment time which increases costs and complexity to resolve them.

The suggestions above do not apply to the JavaScript file section unless mentioned specific JavaScript logic needs optimization or bug fixings which are beyond my scope here.

Expand Down
12 changes: 11 additions & 1 deletion src/components/Apps/ChatAi/components/ChitChat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ export default {
setLoading(true)
removeLoadingMessageInChat()
this.conversationId = data.id
updateChaMessageContentById(data.message.id, data)

const newFragment = {
message: { id: data.message.id, is_reasoning: data.message.is_reasoning },
reasoning: { content: data.message.is_reasoning ? data.message.content : '' },
result: { content: data.message.is_reasoning ? '' : data.message.content },
role: data.message.role,
type: data.message.type,
create_time: data.message.create_time
}

updateChaMessageContentById(data.message.id, newFragment)
}
if (data.message?.type === 'finish') {
setLoading(false)
Copy link
Member

Choose a reason for hiding this comment

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

This is not a code snippet to compare and analyze. Please provide a specific piece of code you would like me to review here!

Copy link
Member

Choose a reason for hiding this comment

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

To identify any irregularities, issues, or optimizations related to your provided code difference checks between two parts of the conversation history, you'll need further specifics about those details. However, based on the given information:

This is an example of updating a fragment within a dialog with Redux Store state data. A loading flag might have been misconfigured or not accounted for properly; it's unclear without more context.

If one were performing this same function but considering asynchronous updates instead, they could consider using async/await along with promises. Alternatively, checking for consistency across APIs would be beneficial. But as stated earlier, these differences and improvements require specific knowledge about both sections being compared.

For optimization suggestions, remember that readability is key—it improves productivity for developers looking through large chunks of code. Consider reorganizing functions, breaking down complex logic into smaller steps or modules where appropriate, enhancing comment clarity, etc., depending on project requirements and complexity.

Expand Down
Loading