【新增】AI:新建对话时,不使用默认角色

This commit is contained in:
YunaiV 2024-05-24 15:39:05 +08:00
parent 8fb54dbb7c
commit 8764c6c471
3 changed files with 62 additions and 25 deletions

View File

@ -12,8 +12,8 @@ export interface ChatConversationVO {
temperature: number // 温度参数 temperature: number // 温度参数
maxTokens: number // 单条回复的最大 Token 数量 maxTokens: number // 单条回复的最大 Token 数量
maxContexts: number // 上下文的最大 Message 数量 maxContexts: number // 上下文的最大 Message 数量
updateTime: number // 更新时间
// 额外字段 // 额外字段
systemMessage?: string // 角色设定
modelName?: string // 模型名字 modelName?: string // 模型名字
roleAvatar?: string // 角色头像 roleAvatar?: string // 角色头像
modelMaxTokens?: string // 模型的单条回复的最大 Token 数量 modelMaxTokens?: string // 模型的单条回复的最大 Token 数量

View File

@ -1,8 +1,7 @@
<template> <template>
<div ref="messageContainer" style="height: 100%;overflow-y: auto;position: relative;"> <div ref="messageContainer" style="height: 100%; overflow-y: auto; position: relative">
<div class="chat-list" v-for="(item, index) in list" :key="index" > <div class="chat-list" v-for="(item, index) in messageList" :key="index">
<!-- 靠左 message --> <!-- 靠左 message -->
<!-- TODO 芋艿类型判断 -->
<div class="left-message message-item" v-if="item.type !== 'user'"> <div class="left-message message-item" v-if="item.type !== 'user'">
<div class="avatar"> <div class="avatar">
<el-avatar :src="item.roleAvatar" /> <el-avatar :src="item.roleAvatar" />
@ -19,7 +18,7 @@
<img class="btn-image" src="@/assets/ai/copy.svg" /> <img class="btn-image" src="@/assets/ai/copy.svg" />
</el-button> </el-button>
<el-button class="btn-cus" link @click="onDelete(item.id)"> <el-button class="btn-cus" link @click="onDelete(item.id)">
<img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px; "/> <img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px" />
</el-button> </el-button>
</div> </div>
</div> </div>
@ -41,7 +40,11 @@
<img class="btn-image" src="@/assets/ai/copy.svg" /> <img class="btn-image" src="@/assets/ai/copy.svg" />
</el-button> </el-button>
<el-button class="btn-cus" link @click="onDelete(item.id)"> <el-button class="btn-cus" link @click="onDelete(item.id)">
<img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px;margin-right: 12px;"/> <img
class="btn-image"
src="@/assets/ai/delete.svg"
style="height: 17px; margin-right: 12px"
/>
</el-button> </el-button>
<el-button class="btn-cus" link @click="onRefresh(item)"> <el-button class="btn-cus" link @click="onRefresh(item)">
<el-icon size="17"><RefreshRight /></el-icon> <el-icon size="17"><RefreshRight /></el-icon>
@ -60,12 +63,13 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {formatDate} from "@/utils/formatTime"; import { formatDate } from '@/utils/formatTime'
import MarkdownView from "@/components/MarkdownView/index.vue"; import MarkdownView from '@/components/MarkdownView/index.vue'
import {ChatMessageApi, ChatMessageVO} from "@/api/ai/chat/message"; import { ChatMessageApi, ChatMessageVO } from '@/api/ai/chat/message'
import {useClipboard} from "@vueuse/core"; import { useClipboard } from '@vueuse/core'
import {PropType} from "vue"; import { PropType } from 'vue'
import {ArrowDownBold, Edit, RefreshRight} from "@element-plus/icons-vue"; import { ArrowDownBold, Edit, RefreshRight } from '@element-plus/icons-vue'
import { ChatConversationVO } from '@/api/ai/chat/conversation'
const { copy } = useClipboard() // copy const { copy } = useClipboard() // copy
// () // ()
@ -74,12 +78,30 @@ const isScrolling = ref(false) //用于判断用户是否在滚动
// props // props
const props = defineProps({ const props = defineProps({
conversation: {
type: Object as PropType<ChatConversationVO>,
required: true
},
list: { list: {
type: Array as PropType<ChatMessageVO[]>, type: Array as PropType<ChatMessageVO[]>,
required: true required: true
} }
}) })
const messageList = computed(() => {
if (props.list && props.list.length > 0) {
return props.list
}
if (props.conversation && props.conversation.systemMessage) {
return [{
id: 0,
type: 'system',
content: props.conversation.systemMessage
}]
}
return []
})
// ============ ============== // ============ ==============
const scrollToBottom = async (isIgnore?: boolean) => { const scrollToBottom = async (isIgnore?: boolean) => {
@ -97,7 +119,7 @@ function handleScroll() {
const scrollTop = scrollContainer.scrollTop const scrollTop = scrollContainer.scrollTop
const scrollHeight = scrollContainer.scrollHeight const scrollHeight = scrollContainer.scrollHeight
const offsetHeight = scrollContainer.offsetHeight const offsetHeight = scrollContainer.offsetHeight
if ((scrollTop + offsetHeight) < (scrollHeight - 100)) { if (scrollTop + offsetHeight < scrollHeight - 100) {
// //
isScrolling.value = true isScrolling.value = true
} else { } else {
@ -191,7 +213,6 @@ onMounted(async () => {
overflow-y: scroll; overflow-y: scroll;
//padding: 0 15px; //padding: 0 15px;
//z-index: -1; //z-index: -1;
} }
// //

View File

@ -36,10 +36,11 @@
<div class="message-container" > <div class="message-container" >
<MessageLoading v-if="listLoading" /> <MessageLoading v-if="listLoading" />
<MessageNewChat v-if="!activeConversation" @on-new-chat="handlerNewChat" /> <MessageNewChat v-if="!activeConversation" @on-new-chat="handlerNewChat" />
<ChatEmpty v-if="!listLoading && list.length === 0 && activeConversation" @on-prompt="doSend"/> <ChatEmpty v-if="!listLoading && messageList.length === 0 && activeConversation" @on-prompt="doSend"/>
<Message v-if="!listLoading && list.length > 0" <Message v-if="!listLoading && messageList.length > 0"
ref="messageRef" ref="messageRef"
:list="list" :conversation="activeConversation"
:list="messageList"
@on-delete-success="handlerMessageDelete" @on-delete-success="handlerMessageDelete"
@on-edit="handlerMessageEdit" @on-edit="handlerMessageEdit"
@on-refresh="handlerMessageRefresh"/> @on-refresh="handlerMessageRefresh"/>
@ -103,13 +104,11 @@ import MessageNewChat from './MessageNewChat.vue'
import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message' import {ChatMessageApi, ChatMessageVO} from '@/api/ai/chat/message'
import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation' import {ChatConversationApi, ChatConversationVO} from '@/api/ai/chat/conversation'
import { getUserProfile, ProfileVO } from '@/api/system/user/profile' import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
import {useClipboard} from '@vueuse/core'
import ChatConversationUpdateForm from "@/views/ai/chat/components/ChatConversationUpdateForm.vue"; import ChatConversationUpdateForm from "@/views/ai/chat/components/ChatConversationUpdateForm.vue";
import {Download, Top} from "@element-plus/icons-vue"; import {Download, Top} from "@element-plus/icons-vue";
const route = useRoute() // const route = useRoute() //
const message = useMessage() // const message = useMessage() //
const {copy} = useClipboard() // copy
// ref // ref
const activeConversationId = ref<string | null>(null) // const activeConversationId = ref<string | null>(null) //
@ -391,6 +390,23 @@ const stopStream = async () => {
// ============== message ================= // ============== message =================
/** 消息列表 */
const messageList = computed(() => {
if (list.value.length > 0) {
return list.value
}
// systemMessage
// TODO add by
if (activeConversation.value?.systemMessage) {
return [{
id: 0,
type: 'system',
content: activeConversation.value.systemMessage
}]
}
return []
})
/** /**
* 获取 - message 列表 * 获取 - message 列表
*/ */