【新增】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 // 温度参数
maxTokens: number // 单条回复的最大 Token 数量
maxContexts: number // 上下文的最大 Message 数量
updateTime: number // 更新时间
// 额外字段
systemMessage?: string // 角色设定
modelName?: string // 模型名字
roleAvatar?: string // 角色头像
modelMaxTokens?: string // 模型的单条回复的最大 Token 数量

View File

@ -1,8 +1,7 @@
<template>
<div ref="messageContainer" style="height: 100%;overflow-y: auto;position: relative;">
<div class="chat-list" v-for="(item, index) in list" :key="index" >
<div ref="messageContainer" style="height: 100%; overflow-y: auto; position: relative">
<div class="chat-list" v-for="(item, index) in messageList" :key="index">
<!-- 靠左 message -->
<!-- TODO 芋艿类型判断 -->
<div class="left-message message-item" v-if="item.type !== 'user'">
<div class="avatar">
<el-avatar :src="item.roleAvatar" />
@ -16,10 +15,10 @@
</div>
<div class="left-btns">
<el-button class="btn-cus" link @click="noCopy(item.content)">
<img class="btn-image" src="@/assets/ai/copy.svg"/>
<img class="btn-image" src="@/assets/ai/copy.svg" />
</el-button>
<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>
</div>
</div>
@ -38,10 +37,14 @@
</div>
<div class="right-btns">
<el-button class="btn-cus" link @click="noCopy(item.content)">
<img class="btn-image" src="@/assets/ai/copy.svg"/>
<img class="btn-image" src="@/assets/ai/copy.svg" />
</el-button>
<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 class="btn-cus" link @click="onRefresh(item)">
<el-icon size="17"><RefreshRight /></el-icon>
@ -60,30 +63,49 @@
</div>
</template>
<script setup lang="ts">
import {formatDate} from "@/utils/formatTime";
import MarkdownView from "@/components/MarkdownView/index.vue";
import {ChatMessageApi, ChatMessageVO} from "@/api/ai/chat/message";
import {useClipboard} from "@vueuse/core";
import {PropType} from "vue";
import {ArrowDownBold, Edit, RefreshRight} from "@element-plus/icons-vue";
import { formatDate } from '@/utils/formatTime'
import MarkdownView from '@/components/MarkdownView/index.vue'
import { ChatMessageApi, ChatMessageVO } from '@/api/ai/chat/message'
import { useClipboard } from '@vueuse/core'
import { PropType } from '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
// ()
const messageContainer: any = ref(null)
const isScrolling = ref(false) //
// props
const props = defineProps({
conversation: {
type: Object as PropType<ChatConversationVO>,
required: true
},
list: {
type: Array as PropType<ChatMessageVO[]>,
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) =>{
await nextTick(() => {
const scrollToBottom = async (isIgnore?: boolean) => {
await nextTick(() => {
//使nexttickdom
if (isIgnore || !isScrolling.value) {
messageContainer.value.scrollTop =
@ -97,7 +119,7 @@ function handleScroll() {
const scrollTop = scrollContainer.scrollTop
const scrollHeight = scrollContainer.scrollHeight
const offsetHeight = scrollContainer.offsetHeight
if ((scrollTop + offsetHeight) < (scrollHeight - 100)) {
if (scrollTop + offsetHeight < scrollHeight - 100) {
//
isScrolling.value = true
} else {
@ -168,7 +190,7 @@ watch(list, async (newValue, oldValue) => {
})
// parent
defineExpose({scrollToBottom, handlerGoTop})
defineExpose({ scrollToBottom, handlerGoTop })
// emits
const emits = defineEmits(['onDeleteSuccess', 'onRefresh', 'onEdit'])
@ -191,7 +213,6 @@ onMounted(async () => {
overflow-y: scroll;
//padding: 0 15px;
//z-index: -1;
}
//

View File

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