wujingjing
2024-07-17 3fd148b35f6109d6295f8dd13dc5d7ea06f864cb
askMore
已修改2个文件
42 ■■■■■ 文件已修改
src/components/chat/Chat.vue 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/chat/model/types.ts 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/chat/Chat.vue
@@ -16,7 +16,7 @@
                        srcset=""
                    />
                    <div class="flex" :class="{ 'w-full': item.role === RoleEnum.assistant }">
                    <div class="inline-flex flex-col" :class="{ 'w-full': item.role === RoleEnum.assistant }">
                        <div class="relative w-full" v-if="item.content?.values">
                            <div
                                class="text-sm rounded-[6px] p-4 leading-relaxed"
@@ -49,7 +49,20 @@
                            </div>
                        </div>
                        <Loding v-else :process="process" />
                        <Loding v-else class="w-12" :process="process" />
                    </div>
                </div>
                <div v-if="showAskMore" class="ml-4 mt-5 text-sm">
                    <div class="text-gray-600 mb-5">你可以继续问我:</div>
                    <div class="space-y-2 inline-flex flex-col">
                        <div
                            v-for="item in computedMessageList.at(-1).content.askMoreList"
                            :key="item.history_id"
                            class="bg-white p-3 hover:bg-[#c5e0ff] hover:text-[#1c86ff] cursor-pointer rounded-lg"
                            @click="askMoreClick(item)"
                        >
                            {{ item.question }}
                        </div>
                    </div>
                </div>
            </div>
@@ -78,6 +91,7 @@
import router from '/@/router';
import { activeChatRoom, activeLLMId, activeRoomId, activeSampleId, activeSectionAId, roomConfig } from '/@/stores/chatRoom';
import { v4 as uuidv4 } from 'uuid';
import _ from 'lodash';
const chatWidth = '75%';
@@ -94,11 +108,19 @@
    return messageList.value.filter((v) => v.role !== RoleEnum.system);
});
const showAskMore = computed(() => {
    if (!computedMessageList.value || computedMessageList.value.length === 0) return false;
    const last = computedMessageList.value.at(-1);
    const isShow = last?.role === RoleEnum.assistant && last?.content?.values && last.content?.askMoreList?.length > 0;
    return isShow;
});
const parseContent = (res) => {
    let content: ChatContent = {
        type: AnswerType.Text,
        values: '发生错误!',
    };
    switch (res.answer_type) {
        case AnswerType.RecordSet:
            content = {
@@ -140,6 +162,7 @@
            };
            break;
    }
    content.askMoreList = _.orderBy(res.context_history, [(item) => Number(item.radio)], ['desc']);
    return content;
};
//#region ====================== 查询进度 ======================
@@ -229,7 +252,7 @@
};
const sendChatMessage = async (content: ChatContent = messageContent.value) => {
    if (!messageContent.value?.values) return;
    if (!content?.values) return;
    if (messageList.value.length === 0) {
        if (activeSampleId.value) {
            currentSampleId = activeSampleId.value;
@@ -276,6 +299,11 @@
    }
};
const askMoreClick = (item) => {
    if (!item.question) return;
    sendChatMessage({ type: AnswerType.Text, values: item.question });
};
onMounted(async () => {
    const res = await QueryHistoryDetail({
        history_group_id: currentRouteId,
src/components/chat/model/types.ts
@@ -33,11 +33,17 @@
};
export type AnswerStateType = typeof AnswerState;
export type ContextHistory = {
    /** @description 数字字符串 */
    ratio:string;
    history_id:string;
    question:string;
}
export type ChatContent = {
    type: AnswerType;
    values: any;
    error?: string;
    askMoreList?:ContextHistory[];
};
export interface ChatMessage {