2025-03-21 17:16:12 +08:00
|
|
|
|
<template>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
<div class="chat-app">
|
|
|
|
|
|
<!-- 历史会话侧边栏 -->
|
|
|
|
|
|
<div class="history-sessions" v-if="sessionIsShow">
|
2025-03-28 21:34:11 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<el-button type="primary" @click="clearCurrent">新会话</el-button>
|
|
|
|
|
|
</div>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
<el-card class="session-card">
|
|
|
|
|
|
<template #header>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<h3>当前会话</h3>
|
|
|
|
|
|
</template>
|
2025-05-12 13:49:08 +08:00
|
|
|
|
<el-tooltip :content=sessionName placement="top">
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li>{{ getShortenedName(sessionName) }}</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</el-tooltip>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</el-card>
|
|
|
|
|
|
<el-card class="session-card2">
|
|
|
|
|
|
<template #header>
|
|
|
|
|
|
<h3>历史会话</h3>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-scrollbar style="height: 400px; scrollbar-width: none">
|
|
|
|
|
|
<ul>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<li v-for="(session, index) in historySessions" :key="index" @click="loadSession(session.ID)">
|
2025-05-12 13:49:08 +08:00
|
|
|
|
<el-tooltip :content="session.Name" placement="top">
|
|
|
|
|
|
<span>{{ getShortenedName(session.Name) }}</span>
|
|
|
|
|
|
</el-tooltip>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
2025-03-28 21:34:11 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<div @click="showSession" style="cursor: pointer">
|
|
|
|
|
|
<el-icon v-if="sessionIsShow">
|
|
|
|
|
|
<Expand />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<el-icon v-else>
|
|
|
|
|
|
<Fold />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 原有的聊天区域 -->
|
|
|
|
|
|
<div class="chat-container">
|
|
|
|
|
|
<!-- 消息列表 -->
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-card class="chat-messages" shadow="never" ref="messagesContainer" v-if="messages.length > 0">
|
|
|
|
|
|
<div v-for="(message, index) in messages" :key="index" :class="['message', message.role]">
|
2025-03-26 18:08:51 +08:00
|
|
|
|
<div class="message-avatar">
|
|
|
|
|
|
<span v-if="message.role === 'assistant'">💬</span>
|
2025-04-11 16:27:25 +08:00
|
|
|
|
<span v-else>🧑🎓</span>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="message-content">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<div v-html="renderMarkdown(message, index)"></div>
|
2025-03-27 16:09:22 +08:00
|
|
|
|
<!-- 添加复制 -->
|
|
|
|
|
|
<div>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-tooltip content="复制" placement="top">
|
|
|
|
|
|
<el-button type="text" :icon="DocumentCopy" @click="copyMessage(message.content)"></el-button>
|
|
|
|
|
|
</el-tooltip>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<!-- <el-button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
:icon="Document"
|
|
|
|
|
|
@click="MessageTextToDoc(message.content)"
|
|
|
|
|
|
></el-button> -->
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-tooltip content="预览、文本创建文件" placement="top">
|
|
|
|
|
|
<el-button type="text" :icon="Document" @click="MessageTextToDoc(message.content)">
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</el-tooltip>
|
2025-03-28 21:34:11 +08:00
|
|
|
|
</div>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<div v-if="loading" class="loading-indicator">Loading...,已回答字符:{{ currentAIMessage.length }}</div>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</el-card>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 输入区域 -->
|
|
|
|
|
|
<el-card class="chat-input" shadow="never">
|
|
|
|
|
|
<el-row :gutter="10">
|
|
|
|
|
|
<el-col :span="20">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-input v-model="inputMessage" type="textarea" style="border: 0" :rows="5" placeholder="输入消息..."
|
|
|
|
|
|
@keyup.enter="sendMessage" />
|
2025-04-01 14:40:20 +08:00
|
|
|
|
<!-- <el-text
|
2025-03-28 21:34:11 +08:00
|
|
|
|
v-model="inputMessage"
|
|
|
|
|
|
aria-placeholder="输入信息...."
|
2025-04-01 14:40:20 +08:00
|
|
|
|
></el-text> -->
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="4" style="text-align: center">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-button @click="sendMessage" type="success" :icon="Check" round :disabled="loading">发送</el-button>
|
2025-04-23 15:11:16 +08:00
|
|
|
|
<el-dropdown trigger="click" class="model-dropdown">
|
|
|
|
|
|
<span class="el-dropdown-link">
|
|
|
|
|
|
<span>模型参数</span>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<ArrowDown />
|
|
|
|
|
|
</el-icon>
|
2025-04-23 15:11:16 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
|
<div class="dropdown-content">
|
|
|
|
|
|
<div class="model-params">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<h4>模型参数
|
|
|
|
|
|
<el-tooltip effect="dark" placement="right" content="建议仅调整 temperature 或 top_p 其中之一,不建议两者都修改">
|
|
|
|
|
|
<el-icon class="tip-icon">
|
|
|
|
|
|
<QuestionFilled />
|
|
|
|
|
|
</el-icon>
|
2025-04-23 15:11:16 +08:00
|
|
|
|
</el-tooltip>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
</h4>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 温度参数 -->
|
|
|
|
|
|
<div class="param-item">
|
|
|
|
|
|
<div class="param-label">
|
|
|
|
|
|
<span>温度 (Temperature)</span>
|
|
|
|
|
|
<el-tooltip effect="dark" placement="right" content="采样温度,控制生成随机性(0: 保守,2: 随机)">
|
|
|
|
|
|
<el-icon class="tip-icon">
|
|
|
|
|
|
<QuestionFilled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-slider v-model="temperature" :min="0" :max="2" :step="0.1" :show-tooltip="false" />
|
|
|
|
|
|
<div class="param-value">{{ temperature }}</div>
|
2025-04-23 15:11:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<!-- Top P 参数 -->
|
|
|
|
|
|
<div class="param-item">
|
|
|
|
|
|
<div class="param-label">
|
|
|
|
|
|
<span>Top P</span>
|
|
|
|
|
|
<el-tooltip effect="dark" placement="right" content="限制候选词范围(0: 严格,1: 宽松)">
|
|
|
|
|
|
<el-icon class="tip-icon">
|
|
|
|
|
|
<QuestionFilled />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-slider v-model="topP" :min="0" :max="1" :step="0.1" :show-tooltip="false" />
|
|
|
|
|
|
<div class="param-value">{{ topP }}</div>
|
2025-04-23 15:11:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</el-col>
|
2025-03-31 13:58:13 +08:00
|
|
|
|
<el-col :span="3" style="text-align: center">
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<el-select v-model="selectModel" placeholder="选择模型" style="width: 320px;">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-option v-for="item in ModelList" :key="item.ID" :label="item.Type + ':' + item.Description"
|
|
|
|
|
|
:value="item.ID"></el-option>
|
2025-03-31 13:58:13 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-col>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<el-col :span="10" style="text-align: center">
|
|
|
|
|
|
<el-tooltip content="文件选择" placement="top">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-button @click="handleSelectFileVisible"><el-icon>
|
|
|
|
|
|
<Files />
|
|
|
|
|
|
</el-icon></el-button>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
</el-tooltip>
|
2025-04-01 14:40:20 +08:00
|
|
|
|
</el-col>
|
2025-04-01 15:45:43 +08:00
|
|
|
|
<!-- <el-col :span="1" style="text-align: center">
|
2025-04-01 14:40:20 +08:00
|
|
|
|
<el-button @click="handleUploadPicture"><el-icon><Picture /></el-icon></el-button>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="1" style="text-align: center">
|
|
|
|
|
|
<el-button><el-icon><VideoCamera /></el-icon></el-button>
|
2025-04-01 15:45:43 +08:00
|
|
|
|
</el-col> -->
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<!-- 已选文件一行显示 -->
|
|
|
|
|
|
<el-col :span="12" style="text-align: center">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-tag v-for="(file, index) in selectedFiles" :key="index" closable @close="removeFile(index)">{{
|
|
|
|
|
|
file.UserFileName }}</el-tag>
|
2025-04-01 16:07:25 +08:00
|
|
|
|
</el-col>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
</el-row>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
2025-04-01 14:40:20 +08:00
|
|
|
|
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<!-- 文件对话框 -->
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-dialog v-model="selectFileVisible" title="从上传文件中选择" width="50%">
|
|
|
|
|
|
<el-input placeholder="搜索文件" v-model="searchFileQuery" prefix-icon="el-icon-search" />
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<el-button @click="uploadMessageFile">上传文件</el-button>
|
|
|
|
|
|
<!-- 文件列表 -->
|
|
|
|
|
|
<div class="file-list">
|
|
|
|
|
|
<el-checkbox-group v-model="selectedFiles">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-checkbox v-for="(item, index) in filteredFiles" :key="index" :label="item">
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<span class="file-icon">
|
|
|
|
|
|
<!-- 根据文件类型展示不同图标 -->
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<i v-if="item.UploadType === 'image'" class="el-icon-picture"></i>
|
|
|
|
|
|
<i v-else-if="item.UploadType === 'file'" class="el-icon-document"></i>
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<!-- 可继续补充其他文件类型图标 -->
|
|
|
|
|
|
</span>
|
|
|
|
|
|
{{ item.UserFileName }}
|
|
|
|
|
|
<!-- <span class="file-time">{{ item.CreatedAt }}</span> -->
|
|
|
|
|
|
</el-checkbox>
|
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- 底部状态栏和按钮 -->
|
|
|
|
|
|
<div class="footer-bar">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<span class="selected-count">已选 {{ selectedFiles.length }} 个文件</span>
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<el-button @click="selectFileVisible = false">取消</el-button>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-button type="primary" @click="handleSelectFileConfirm">确认添加({{ selectedFiles.length }})</el-button>
|
2025-04-01 16:07:25 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- 上传文件对话框 -->
|
|
|
|
|
|
<div>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-dialog title="上传文件" v-model="uploadFileVisible" width="50%" :before-close="handleUploadFileClose">
|
2025-04-01 16:07:25 +08:00
|
|
|
|
<UploadFile></UploadFile>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<!-- 文本创建文件对话 -->
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-dialog title="文本创建文件" v-model="textToDocFileVisible" width="70%" heigth="80vh"
|
2025-05-08 14:16:39 +08:00
|
|
|
|
:before-close="handleMessageTextToDOCClose">
|
|
|
|
|
|
<!-- <textarea v-model="textToDocFileContent"></textarea> -->
|
2025-05-19 19:14:22 +08:00
|
|
|
|
<div ref="vditorRef"></div>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<el-col>
|
|
|
|
|
|
<!-- 提示 -->
|
|
|
|
|
|
<el-input v-model="textToDocFileName" placeholder="输入文件名..." style="width: 30%;">输入文件名</el-input>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<!-- <el-input v-model="textToDocFileName" placeholder="输入文件名..." width="30%">输入文件名</el-input> -->
|
|
|
|
|
|
<el-col>
|
|
|
|
|
|
<el-select v-model="selectFileDocType" placeholder="选择文本类型" style="width: 30%;">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
<el-option label="docx" value="docx"></el-option>
|
|
|
|
|
|
<el-option label="txt" value="txt"></el-option>
|
|
|
|
|
|
<el-option label="md" value="md"></el-option>
|
|
|
|
|
|
</el-select>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
</el-col>
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
|
|
|
|
|
<el-button type="primary" @click="HandleTextToDocFile">确认</el-button>
|
2025-05-08 14:16:39 +08:00
|
|
|
|
<el-button @click="textToDocFileVisible = false">取消</el-button>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
2025-04-01 14:40:20 +08:00
|
|
|
|
</div>
|
2025-03-25 19:51:06 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
2025-03-24 21:44:38 +08:00
|
|
|
|
<script setup lang="ts">
|
2025-09-23 20:35:33 +08:00
|
|
|
|
import { ref, onMounted, onUnmounted, reactive, nextTick, watch } from "vue";
|
2025-04-01 16:07:25 +08:00
|
|
|
|
import { ElCard, ElInput, ElButton, ElDialog } from "element-plus";
|
|
|
|
|
|
import { WSMessage, GenMessage } from "@/types/im";
|
2025-03-25 19:51:06 +08:00
|
|
|
|
import { GetMessageService } from "@/api/im";
|
2025-04-01 14:40:20 +08:00
|
|
|
|
import { FindUserFileService } from "@/api/file";
|
2025-04-01 16:07:25 +08:00
|
|
|
|
import { Model } from "@/types/model";
|
2025-09-23 20:35:33 +08:00
|
|
|
|
import { UserUISettings } from '@/types/user';
|
2025-04-01 16:07:25 +08:00
|
|
|
|
import { File, fileUrl } from "@/types/file";
|
2025-03-26 18:08:51 +08:00
|
|
|
|
import { Session } from "@/types/session";
|
|
|
|
|
|
import { FindSessionService } from "@/api/session";
|
2025-05-08 14:16:39 +08:00
|
|
|
|
import { SetMessageTextToDocService } from "@/api/tool";
|
2025-04-01 16:07:25 +08:00
|
|
|
|
import { ElMessage } from "element-plus";
|
2025-09-23 20:35:33 +08:00
|
|
|
|
import { Check, DocumentCopy, Document, PriceTag } from "@element-plus/icons-vue";
|
2025-04-01 16:07:25 +08:00
|
|
|
|
import MarkdownIt from "markdown-it";
|
|
|
|
|
|
import hljs from "highlight.js";
|
|
|
|
|
|
import UploadFile from "@/components/upload-file.vue";
|
2025-05-20 20:38:36 +08:00
|
|
|
|
import { updateUserUIconfigInfoService } from "@/api/user";
|
2025-03-31 13:58:13 +08:00
|
|
|
|
import { FindModelListByFunctionName } from "@/api/function";
|
2025-03-28 21:34:11 +08:00
|
|
|
|
import markdownItHighlightjs from "markdown-it-highlightjs";
|
|
|
|
|
|
import markdownItKatex from "markdown-it-katex";
|
2025-03-27 18:49:14 +08:00
|
|
|
|
import mermaidPlugin from "@agoose77/markdown-it-mermaid";
|
2025-09-23 20:35:33 +08:00
|
|
|
|
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
2025-03-26 18:08:51 +08:00
|
|
|
|
import "katex/dist/katex.min.css";
|
2025-05-20 20:38:36 +08:00
|
|
|
|
import Vditor from 'vditor';
|
2025-05-08 14:16:39 +08:00
|
|
|
|
import 'vditor/dist/index.css';
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 19:51:06 +08:00
|
|
|
|
interface Message {
|
|
|
|
|
|
role: "user" | "assistant";
|
|
|
|
|
|
content: string;
|
|
|
|
|
|
finished?: boolean;
|
|
|
|
|
|
}
|
2025-04-01 21:31:59 +08:00
|
|
|
|
interface SendImageMessage {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
img_name: string;
|
|
|
|
|
|
img_url: string;
|
2025-04-01 21:31:59 +08:00
|
|
|
|
}
|
2025-04-01 16:07:25 +08:00
|
|
|
|
interface ImageMessage {
|
2025-04-01 21:31:59 +08:00
|
|
|
|
image_content: SendImageMessage[];
|
2025-04-01 14:40:20 +08:00
|
|
|
|
text: string;
|
|
|
|
|
|
}
|
2025-04-07 19:31:41 +08:00
|
|
|
|
interface FileMessage {
|
|
|
|
|
|
file_content: File; //文件内容,文件内容的base64编码
|
|
|
|
|
|
file_type: string | null; //文件类型,文本类型,图片类型等,text_file,img_file等
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface GenerationMessage {
|
|
|
|
|
|
text: string;
|
|
|
|
|
|
file_content: FileMessage[];
|
|
|
|
|
|
}
|
2025-03-26 18:08:51 +08:00
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
const md = new MarkdownIt();
|
2025-03-27 17:33:35 +08:00
|
|
|
|
md.use(markdownItHighlightjs, {
|
2025-03-27 16:09:22 +08:00
|
|
|
|
hljs,
|
|
|
|
|
|
auto: true,
|
2025-03-27 17:33:35 +08:00
|
|
|
|
code: true,
|
|
|
|
|
|
});
|
2025-04-01 21:31:59 +08:00
|
|
|
|
md.renderer.rules.image = function (tokens, idx, options, env, self) {
|
|
|
|
|
|
const token = tokens[idx];
|
|
|
|
|
|
// 设置图片的宽度和高度属性
|
2025-09-23 20:35:33 +08:00
|
|
|
|
token.attrSet('width', '400');
|
|
|
|
|
|
token.attrSet('height', '300');
|
2025-04-01 21:31:59 +08:00
|
|
|
|
return self.renderToken(tokens, idx, options, env, self);
|
|
|
|
|
|
};
|
2025-03-27 18:49:14 +08:00
|
|
|
|
md.use(markdownItKatex);
|
|
|
|
|
|
md.use(mermaidPlugin);
|
|
|
|
|
|
|
|
|
|
|
|
//md.use(markdownItMermaid);
|
2025-03-25 19:51:06 +08:00
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
const historySessions = ref<Session[]>([]);
|
2025-03-25 19:51:06 +08:00
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
const isUserScrolling = ref<boolean>(false);
|
|
|
|
|
|
const messages = reactive([]);
|
|
|
|
|
|
const inputMessage = ref("");
|
|
|
|
|
|
const socket = ref(null);
|
|
|
|
|
|
const currentAIMessage = ref("");
|
|
|
|
|
|
const sessionID = ref(0);
|
|
|
|
|
|
const messagesContainer = ref<HTMLDivElement | null>(null);
|
2025-03-26 18:08:51 +08:00
|
|
|
|
const sessionIsShow = ref(false);
|
|
|
|
|
|
const sessionName = ref("");
|
2025-03-31 13:58:13 +08:00
|
|
|
|
const ModelList = ref<Model[]>([]);
|
|
|
|
|
|
const selectModel = ref(0);
|
2025-04-23 15:11:16 +08:00
|
|
|
|
const temperature = ref(0.8);
|
2025-03-31 19:06:57 +08:00
|
|
|
|
const topP = ref(0.9);
|
2025-04-01 14:40:20 +08:00
|
|
|
|
const selectedFiles = ref<File[]>([]); // 用于存储已选文件
|
|
|
|
|
|
const selectFileVisible = ref(false); // 控制文件选择对话框的显示与隐藏
|
|
|
|
|
|
const searchFileQuery = ref(""); // 用于搜索文件的查询条件
|
|
|
|
|
|
const filteredFiles = ref<File[]>([]); // 用于存储过滤后的文件列表
|
2025-04-01 15:45:43 +08:00
|
|
|
|
const uploadFileVisible = ref(false); // 控制上传文件对话框的显示与隐藏
|
2025-05-08 14:16:39 +08:00
|
|
|
|
const textToDocFileVisible = ref(false); // 控制文本创建文件对话框的显示与隐藏
|
|
|
|
|
|
const selectFileDocType = ref("docx"); // 选择的文本类型
|
|
|
|
|
|
const textToDocFileName = ref(""); // 文本创建文件的名称
|
|
|
|
|
|
const textToDocFileContent = ref(""); // 文本创建文件的内容
|
|
|
|
|
|
const vditor = ref(); // Vditor 实例
|
2025-05-19 19:14:22 +08:00
|
|
|
|
const vditorRef = ref(null);
|
2025-05-20 20:38:36 +08:00
|
|
|
|
const userUIconfigInfo = ref<UserUISettings>({} as UserUISettings); // 用户UI配置
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//监听需要保存的配置
|
|
|
|
|
|
watch(
|
2025-09-23 20:35:33 +08:00
|
|
|
|
[selectModel, temperature, topP, sessionID],
|
|
|
|
|
|
() => { //保存配置
|
2025-05-20 20:38:36 +08:00
|
|
|
|
updateUserUIconfigInfo();
|
2025-09-23 20:35:33 +08:00
|
|
|
|
}
|
2025-05-20 20:38:36 +08:00
|
|
|
|
)
|
2025-05-08 14:16:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const historyMsgHtml = ref([]); // 用于存储历史消息的HTML内容
|
|
|
|
|
|
const wssUrl =
|
|
|
|
|
|
"wss://pm.ljsea.top/im/ai_chat_ws?" +
|
|
|
|
|
|
"token=" +
|
|
|
|
|
|
localStorage.getItem("token");
|
2025-03-25 19:51:06 +08:00
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const renderMarkdown = (message: Message, index: number) => {
|
|
|
|
|
|
if (message.finished == false) {
|
2025-04-13 15:51:15 +08:00
|
|
|
|
//console.log("not finished");
|
|
|
|
|
|
return message.content;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
if (historyMsgHtml.value[index]) {
|
2025-04-13 15:51:15 +08:00
|
|
|
|
//console.log("historyMsgHtml:", historyMsgHtml.value[index]);
|
|
|
|
|
|
//console.log("historyMsgHtml:", index);
|
|
|
|
|
|
//已经渲染过的消息,直接返回
|
|
|
|
|
|
return historyMsgHtml.value[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
//console.log("new finish:");
|
|
|
|
|
|
const html = md.render(message.content);
|
|
|
|
|
|
historyMsgHtml.value.push(html);
|
|
|
|
|
|
return html;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const scrollToBottom = () => {
|
2025-03-26 18:08:51 +08:00
|
|
|
|
let x = document.getElementsByClassName("chat-messages")[0];
|
2025-04-01 14:40:20 +08:00
|
|
|
|
if (!x) return;
|
2025-03-26 18:08:51 +08:00
|
|
|
|
x.scrollTop = x.scrollHeight; //将滚轮置底
|
2025-03-25 19:51:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
const copyCode = (code: string) => {
|
|
|
|
|
|
navigator.clipboard.writeText(code).then(() => {
|
|
|
|
|
|
ElMessage.success("代码已复制到剪贴板");
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2025-04-01 14:40:20 +08:00
|
|
|
|
const removeFile = (index: number) => {
|
|
|
|
|
|
selectedFiles.value.splice(index, 1);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleSelectFileVisible = async () => {
|
|
|
|
|
|
await getFileListData(); // 获取文件列表
|
|
|
|
|
|
console.log("selectedFiles:", selectedFiles.value);
|
2025-04-01 16:07:25 +08:00
|
|
|
|
selectFileVisible.value = true; // 显示对话框
|
2025-04-01 14:40:20 +08:00
|
|
|
|
console.log("handleSelectFileVisible:", selectFileVisible.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-01 16:07:25 +08:00
|
|
|
|
const handleUploadFileClose = async () => {
|
2025-04-01 15:45:43 +08:00
|
|
|
|
uploadFileVisible.value = false; // 关闭上传文件对话框
|
|
|
|
|
|
await getFileListData(); // 获取文件列表
|
|
|
|
|
|
console.log("handleUploadFileClose:", uploadFileVisible.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-08 14:16:39 +08:00
|
|
|
|
const handleMessageTextToDOCClose = async () => {
|
|
|
|
|
|
textToDocFileVisible.value = false; // 关闭文本创建文件对话框
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
const handleUploadPicture = () => {
|
|
|
|
|
|
// 处理上传图片的逻辑
|
|
|
|
|
|
//选择图片并上传
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-01 15:45:43 +08:00
|
|
|
|
const uploadMessageFile = () => {
|
|
|
|
|
|
// 处理上传文件的逻辑
|
|
|
|
|
|
// 这里可以调用上传文件的API
|
|
|
|
|
|
uploadFileVisible.value = true; // 显示上传文件对话框
|
|
|
|
|
|
console.log("上传文件:", selectedFiles.value);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
const handleSelectFileConfirm = () => {
|
|
|
|
|
|
// 处理选中的文件
|
|
|
|
|
|
console.log("选中的文件:", selectedFiles.value);
|
|
|
|
|
|
// 在这里可以进行文件上传或其他操作
|
|
|
|
|
|
selectFileVisible.value = false; // 关闭对话框
|
2025-05-20 20:38:36 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
};
|
2025-03-27 16:09:22 +08:00
|
|
|
|
|
2025-04-27 13:09:57 +08:00
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
const doButtonD = () => {
|
2025-03-28 21:34:11 +08:00
|
|
|
|
const codeBlocks = document.querySelectorAll("pre code");
|
2025-03-27 16:09:22 +08:00
|
|
|
|
codeBlocks.forEach((codeBlock) => {
|
2025-03-27 18:49:14 +08:00
|
|
|
|
//先查看是否已经添加了复制按钮
|
2025-03-28 21:34:11 +08:00
|
|
|
|
if (codeBlock.parentNode.querySelector(".code-controls")) {
|
2025-03-27 18:49:14 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-27 17:33:35 +08:00
|
|
|
|
// 获取代码类型
|
2025-04-08 17:12:56 +08:00
|
|
|
|
const codeType = codeBlock.className.replace("hljs", "");
|
2025-03-27 17:33:35 +08:00
|
|
|
|
// 创建代码类型显示元素
|
2025-03-28 21:34:11 +08:00
|
|
|
|
const codeTypeElement = document.createElement("span");
|
|
|
|
|
|
codeTypeElement.textContent = codeType.split("-")[1];
|
2025-03-27 17:33:35 +08:00
|
|
|
|
codeTypeElement.setAttribute("background-color", "rgba(0, 0, 0, 0.1)");
|
|
|
|
|
|
codeTypeElement.setAttribute("padding", "3px 6px");
|
|
|
|
|
|
codeTypeElement.setAttribute("border-radius", "4px");
|
|
|
|
|
|
codeTypeElement.setAttribute("font-size", "0.9em");
|
|
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
// 创建复制按钮
|
2025-03-28 21:34:11 +08:00
|
|
|
|
const copyButton = document.createElement("button");
|
2025-03-27 17:33:35 +08:00
|
|
|
|
copyButton.setAttribute("background-color", "dodgerblue");
|
|
|
|
|
|
copyButton.setAttribute("display", "flex");
|
|
|
|
|
|
copyButton.setAttribute("align-items", "center");
|
|
|
|
|
|
copyButton.setAttribute("padding", "5px 10px");
|
|
|
|
|
|
copyButton.setAttribute("cursor", "pointer");
|
|
|
|
|
|
copyButton.setAttribute("border-radius", "4px");
|
2025-03-28 21:34:11 +08:00
|
|
|
|
copyButton.textContent = "复制";
|
2025-03-27 17:33:35 +08:00
|
|
|
|
copyButton.classList.add();
|
2025-03-28 21:34:11 +08:00
|
|
|
|
copyButton.addEventListener("click", () => {
|
2025-03-27 16:09:22 +08:00
|
|
|
|
copyCode(codeBlock.textContent);
|
|
|
|
|
|
});
|
2025-03-27 17:33:35 +08:00
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
// 设置代码块父元素的定位,以便按钮定位
|
|
|
|
|
|
const pre = codeBlock.parentNode;
|
2025-03-27 17:33:35 +08:00
|
|
|
|
// pre.style.position = 'relative';
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个容器用于放置代码类型和复制按钮
|
2025-03-28 21:34:11 +08:00
|
|
|
|
const controlsContainer = document.createElement("div");
|
|
|
|
|
|
controlsContainer.classList.add("code-controls");
|
2025-03-27 17:33:35 +08:00
|
|
|
|
controlsContainer.appendChild(codeTypeElement);
|
|
|
|
|
|
controlsContainer.appendChild(copyButton);
|
|
|
|
|
|
|
|
|
|
|
|
// 将容器添加到代码块父元素中
|
|
|
|
|
|
pre.insertBefore(controlsContainer, codeBlock);
|
2025-03-27 16:09:22 +08:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-25 19:51:06 +08:00
|
|
|
|
onMounted(() => {
|
2025-03-26 18:08:51 +08:00
|
|
|
|
// if (typeof window !== 'undefined') {
|
|
|
|
|
|
// // 浏览器环境
|
|
|
|
|
|
// md.use(markdownItMermaid);
|
|
|
|
|
|
// }
|
2025-09-23 20:35:33 +08:00
|
|
|
|
//IMWSConnect();
|
2025-03-25 19:51:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-20 20:38:36 +08:00
|
|
|
|
|
|
|
|
|
|
userUIconfigInfo.value = JSON.parse(
|
|
|
|
|
|
localStorage.getItem("userUIconfigInfo") || "{}"
|
|
|
|
|
|
);
|
2025-05-21 20:00:58 +08:00
|
|
|
|
console.log("userUIconfigInfo:", userUIconfigInfo.value);
|
|
|
|
|
|
messagesContainer.value = document.querySelector(".chat-messages");
|
2025-05-20 20:38:36 +08:00
|
|
|
|
//console.log("userUIconfigInfo:", userUIconfigInfo.value);
|
2025-03-25 19:51:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
if (socket.value) {
|
|
|
|
|
|
socket.value.close();
|
2025-03-22 18:11:38 +08:00
|
|
|
|
}
|
2025-03-25 19:51:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-04-27 13:09:57 +08:00
|
|
|
|
const doReceiveMessage = (event) => {
|
|
|
|
|
|
// 处理接收到的消息
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let msg: WSMessage = JSON.parse(event.data);
|
|
|
|
|
|
const existingMessage = messages.find(
|
|
|
|
|
|
(msg) => msg.role === "assistant" && !msg.finished
|
|
|
|
|
|
);
|
|
|
|
|
|
if (existingMessage) {
|
|
|
|
|
|
// 追加内容
|
|
|
|
|
|
existingMessage.content += msg.msg.msg.response;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 新消息
|
|
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "assistant",
|
|
|
|
|
|
content: msg.msg.msg.response,
|
|
|
|
|
|
finished: false,
|
2025-04-27 13:09:57 +08:00
|
|
|
|
});
|
2025-09-23 20:35:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sessionID.value = msg.session_id;
|
|
|
|
|
|
currentAIMessage.value += msg.msg.msg.response;
|
|
|
|
|
|
if (msg.msg.msg.done) {
|
|
|
|
|
|
const assistantMessage = messages[messages.length - 1];
|
|
|
|
|
|
assistantMessage.finished = true;
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
currentAIMessage.value = "";
|
|
|
|
|
|
doButtonD();
|
|
|
|
|
|
}
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
scrollToBottom(); // 新增滚动调用
|
|
|
|
|
|
});
|
2025-04-27 13:09:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const doReceiveMessageSSE = (event) => {
|
|
|
|
|
|
// 处理接收到的消息
|
|
|
|
|
|
let msg: WSMessage = JSON.parse(event.data.replace("data: ", ""));
|
|
|
|
|
|
const existingMessage = messages.find(
|
|
|
|
|
|
(msg) => msg.role === "assistant" && !msg.finished
|
|
|
|
|
|
);
|
|
|
|
|
|
if (existingMessage) {
|
|
|
|
|
|
// 追加内容
|
|
|
|
|
|
existingMessage.content += msg.msg.msg.response;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 新消息
|
|
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "assistant",
|
|
|
|
|
|
content: msg.msg.msg.response,
|
|
|
|
|
|
finished: false,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sessionID.value = msg.session_id;
|
|
|
|
|
|
currentAIMessage.value += msg.msg.msg.response;
|
|
|
|
|
|
if (msg.msg.msg.done) {
|
|
|
|
|
|
const assistantMessage = messages[messages.length - 1];
|
|
|
|
|
|
assistantMessage.finished = true;
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
currentAIMessage.value = "";
|
|
|
|
|
|
doButtonD();
|
|
|
|
|
|
}
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
scrollToBottom(); // 新增滚动调用
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-05-20 20:38:36 +08:00
|
|
|
|
const updateUserUIconfigInfo = () => {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
//将配置保存到数据库
|
|
|
|
|
|
let req: UserUISettings = JSON.parse(localStorage.getItem("userUIconfigInfo") || "{}");
|
|
|
|
|
|
if (req.user_id == 0) {
|
|
|
|
|
|
req.user_id = parseInt(localStorage.getItem("user_id") || "0");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
req.gen_ai_function.model_id = selectModel.value;
|
|
|
|
|
|
req.gen_ai_function.temperature = temperature.value;
|
|
|
|
|
|
req.gen_ai_function.top_p = topP.value;
|
|
|
|
|
|
req.gen_ai_function.session_id = sessionID.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
updateUserUIconfigInfoService(req, localStorage.getItem("token")).then((res) => {
|
|
|
|
|
|
if (res["code"] === 0) {
|
|
|
|
|
|
console.log("保存成功");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("保存失败");
|
2025-05-20 20:38:36 +08:00
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
});
|
2025-05-20 20:38:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-21 20:00:58 +08:00
|
|
|
|
const sendMessage = async () => {
|
|
|
|
|
|
//测试ws是否连接断开
|
2025-09-23 20:35:33 +08:00
|
|
|
|
// if (socket.value == null) {
|
|
|
|
|
|
// await IMWSConnect();
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
if (loading.value === true) {
|
2025-05-21 20:00:58 +08:00
|
|
|
|
ElMessage.warning("正在等待AI回复,请稍后再试");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
await nextTick();
|
2025-09-23 20:35:33 +08:00
|
|
|
|
sendMessageWithFileUseSSE();
|
|
|
|
|
|
//sendMessageWithFile();
|
2025-04-07 19:31:41 +08:00
|
|
|
|
return;
|
2025-03-26 18:08:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const sendMessageWithFileUseSSE = async () => {
|
|
|
|
|
|
checkTokenIsValidAndRefresh();
|
|
|
|
|
|
let url = "https://pm.ljsea.top/im/chat_completion";
|
|
|
|
|
|
let headers = { "token": localStorage.getItem("token") };
|
|
|
|
|
|
if (inputMessage.value.trim() === "") {
|
|
|
|
|
|
ElMessage.warning("消息不能为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let end_msg = {
|
|
|
|
|
|
msg: inputMessage.value,
|
|
|
|
|
|
type: "null",
|
|
|
|
|
|
function: "gen-ai-chat",
|
|
|
|
|
|
session_id: sessionID.value,
|
|
|
|
|
|
model_id: selectModel.value,
|
|
|
|
|
|
temperature: temperature.value,
|
|
|
|
|
|
top_p: topP.value,
|
|
|
|
|
|
};
|
|
|
|
|
|
if (selectedFiles.value.length > 0) {
|
|
|
|
|
|
// 处理选中的文件
|
|
|
|
|
|
console.log("选中的文件:", selectedFiles.value);
|
|
|
|
|
|
let file_contents = []
|
|
|
|
|
|
let file_type = ""
|
|
|
|
|
|
for (let i = 0; i < selectedFiles.value.length; i++) {
|
|
|
|
|
|
let file: File = selectedFiles.value[i];
|
|
|
|
|
|
//图片文件:jpg、png、gif、bmp
|
|
|
|
|
|
if (file.UserFileName.endsWith(".jpg") || file.UserFileName.endsWith(".png") || file.UserFileName.endsWith(".gif") || file.UserFileName.endsWith(".bmp")) {
|
|
|
|
|
|
file_type = "image_file"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
file_type = "text_file"
|
|
|
|
|
|
}
|
|
|
|
|
|
let file_msg: FileMessage = {
|
|
|
|
|
|
file_content: file,
|
|
|
|
|
|
file_type: file_type,
|
|
|
|
|
|
};
|
|
|
|
|
|
file_contents.push(file_msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
let msg: GenerationMessage = {
|
|
|
|
|
|
text: inputMessage.value,
|
|
|
|
|
|
file_content: file_contents,
|
|
|
|
|
|
};
|
|
|
|
|
|
let msg_str = JSON.stringify(msg);
|
|
|
|
|
|
end_msg["msg"] = msg_str;
|
|
|
|
|
|
end_msg["is_file"] = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
fetchEventSource(url, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json', // 请求体格式
|
|
|
|
|
|
...headers, // 合并自定义请求头(如Authorization)
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify(end_msg), // 序列化请求体
|
|
|
|
|
|
openWhenHidden: true, // 允许页面隐藏时保持连接
|
|
|
|
|
|
onopen: () => {
|
|
|
|
|
|
console.log('SSE connection established');
|
|
|
|
|
|
},
|
|
|
|
|
|
onmessage: (event) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
doReceiveMessageSSE(event);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.error('Failed to parse SSE data:', e);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onerror: (error) => {
|
|
|
|
|
|
ElMessage.error("发送失败!请刷新页面!");
|
|
|
|
|
|
},
|
|
|
|
|
|
onclose: () => {
|
|
|
|
|
|
console.log('SSE connection closed');
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let pMsgContent = "";
|
|
|
|
|
|
if (end_msg["is_file"]) {
|
|
|
|
|
|
let file_msg: GenerationMessage = JSON.parse(end_msg["msg"]);
|
|
|
|
|
|
//解析成md格式
|
|
|
|
|
|
let file_content = file_msg.file_content
|
|
|
|
|
|
for (let i = 0; i < file_content.length; i++) {
|
|
|
|
|
|
if (file_content[i].file_type == "image_file") {
|
|
|
|
|
|
pMsgContent += `![${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent += `文件:[${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
|
|
|
|
|
}
|
2025-04-07 19:31:41 +08:00
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
pMsgContent = pMsgContent + "输入:" + file_msg.text;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent = end_msg.msg;
|
|
|
|
|
|
}
|
|
|
|
|
|
messages.push({ role: "user", content: pMsgContent, finished: true });
|
|
|
|
|
|
inputMessage.value = "";
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
scrollToBottom(); // 新增滚动调用
|
|
|
|
|
|
});
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
if (sessionID.value == 0) {
|
|
|
|
|
|
sessionName.value = end_msg.msg;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const sendMessageWithFile = async () => {
|
2025-04-07 19:31:41 +08:00
|
|
|
|
if (inputMessage.value.trim() === "") {
|
|
|
|
|
|
ElMessage.warning("消息不能为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let end_msg = {
|
|
|
|
|
|
msg: inputMessage.value,
|
2025-05-12 13:49:08 +08:00
|
|
|
|
type: "null",
|
2025-04-07 19:31:41 +08:00
|
|
|
|
function: "gen-ai-chat",
|
|
|
|
|
|
session_id: sessionID.value,
|
|
|
|
|
|
model_id: selectModel.value,
|
|
|
|
|
|
temperature: temperature.value,
|
|
|
|
|
|
top_p: topP.value,
|
|
|
|
|
|
};
|
|
|
|
|
|
if (selectedFiles.value.length > 0) {
|
|
|
|
|
|
// 处理选中的文件
|
|
|
|
|
|
console.log("选中的文件:", selectedFiles.value);
|
|
|
|
|
|
let file_contents = []
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let file_type = ""
|
2025-04-07 19:31:41 +08:00
|
|
|
|
for (let i = 0; i < selectedFiles.value.length; i++) {
|
|
|
|
|
|
let file: File = selectedFiles.value[i];
|
|
|
|
|
|
//图片文件:jpg、png、gif、bmp
|
|
|
|
|
|
if (file.UserFileName.endsWith(".jpg") || file.UserFileName.endsWith(".png") || file.UserFileName.endsWith(".gif") || file.UserFileName.endsWith(".bmp")) {
|
|
|
|
|
|
file_type = "image_file"
|
2025-09-23 20:35:33 +08:00
|
|
|
|
} else {
|
2025-04-07 19:31:41 +08:00
|
|
|
|
file_type = "text_file"
|
|
|
|
|
|
}
|
|
|
|
|
|
let file_msg: FileMessage = {
|
|
|
|
|
|
file_content: file,
|
|
|
|
|
|
file_type: file_type,
|
|
|
|
|
|
};
|
|
|
|
|
|
file_contents.push(file_msg);
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let msg: GenerationMessage = {
|
2025-04-07 19:31:41 +08:00
|
|
|
|
text: inputMessage.value,
|
|
|
|
|
|
file_content: file_contents,
|
|
|
|
|
|
};
|
|
|
|
|
|
let msg_str = JSON.stringify(msg);
|
|
|
|
|
|
end_msg["msg"] = msg_str;
|
|
|
|
|
|
end_msg["is_file"] = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log("end_msg:", end_msg);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
socket.value.send(JSON.stringify(end_msg));
|
|
|
|
|
|
console.log("send msg:", end_msg);
|
|
|
|
|
|
} catch (e) {
|
2025-05-21 20:00:58 +08:00
|
|
|
|
//ElMessage.error("发送失败!请刷新页面!");
|
|
|
|
|
|
await IMWSConnect();
|
|
|
|
|
|
socket.value.send(JSON.stringify(end_msg));
|
2025-04-07 19:31:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (sessionID.value == 0) {
|
|
|
|
|
|
sessionName.value = inputMessage.value;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let pMsgContent = "";
|
2025-04-07 19:31:41 +08:00
|
|
|
|
if (end_msg["is_file"]) {
|
|
|
|
|
|
let file_msg: GenerationMessage = JSON.parse(end_msg["msg"]);
|
|
|
|
|
|
//解析成md格式
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let file_content = file_msg.file_content
|
2025-04-07 19:31:41 +08:00
|
|
|
|
for (let i = 0; i < file_content.length; i++) {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
if (file_content[i].file_type == "image_file") {
|
|
|
|
|
|
pMsgContent += `![${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent += `文件:[${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
2025-04-07 19:31:41 +08:00
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-07 19:31:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
pMsgContent = pMsgContent + "输入:" + file_msg.text;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent = end_msg.msg;
|
|
|
|
|
|
}
|
|
|
|
|
|
messages.push({ role: "user", content: pMsgContent, finished: true });
|
|
|
|
|
|
inputMessage.value = "";
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
scrollToBottom(); // 新增滚动调用
|
|
|
|
|
|
});
|
|
|
|
|
|
loading.value = true;
|
|
|
|
|
|
if (sessionID.value == 0) {
|
|
|
|
|
|
sessionName.value = end_msg.msg;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const IMWSConnect = async () => {
|
2025-05-21 20:00:58 +08:00
|
|
|
|
let url =
|
|
|
|
|
|
"wss://pm.ljsea.top/im/ai_chat_ws?" +
|
|
|
|
|
|
"token=" +
|
|
|
|
|
|
localStorage.getItem("token");
|
|
|
|
|
|
//获取模型列表
|
|
|
|
|
|
let test_url = "ws://127.0.0.1:8084/im/ai_chat_ws?" + "token=" + localStorage.getItem("token");
|
|
|
|
|
|
//url =test_url;
|
2025-09-23 20:35:33 +08:00
|
|
|
|
socket.value = new WebSocket(url);
|
2025-05-21 20:00:58 +08:00
|
|
|
|
socket.value.onopen = () => {
|
|
|
|
|
|
console.log("WebSocket 连接已建立");
|
|
|
|
|
|
ElMessage.success("连接成功");
|
|
|
|
|
|
};
|
|
|
|
|
|
socket.value.onmessage = (event) => {
|
|
|
|
|
|
doReceiveMessage(event);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
socket.value.onclose = () => {
|
|
|
|
|
|
console.log("WebSocket 连接已关闭");
|
|
|
|
|
|
ElMessage.error("连接已关闭");
|
|
|
|
|
|
//重新连接
|
|
|
|
|
|
//socket.value = new WebSocket(url);
|
|
|
|
|
|
socket.value = null;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
socket.value.onerror = (error) => {
|
|
|
|
|
|
socket.value = null;
|
|
|
|
|
|
console.log("WebSocket 连接发生错误:", error);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
const loadSession = async (session_id: number) => {
|
|
|
|
|
|
sessionID.value = session_id;
|
|
|
|
|
|
messages.length = 0; // 清空消息
|
|
|
|
|
|
sessionName.value = historySessions.value.find(
|
|
|
|
|
|
(session) => session.ID == session_id
|
|
|
|
|
|
)?.Name;
|
|
|
|
|
|
await getMessage(session_id);
|
2025-03-27 16:09:22 +08:00
|
|
|
|
scrollToBottom();
|
2025-03-27 17:33:35 +08:00
|
|
|
|
doButtonD();
|
2025-03-26 18:08:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clearCurrent = () => {
|
|
|
|
|
|
sessionID.value = 0;
|
|
|
|
|
|
messages.length = 0; // 清空消息
|
2025-04-13 15:51:15 +08:00
|
|
|
|
historyMsgHtml.value.length = 0; // 清空历史消息
|
2025-03-26 18:08:51 +08:00
|
|
|
|
sessionName.value = "新会话";
|
2025-05-19 19:14:22 +08:00
|
|
|
|
showSession();
|
2025-03-26 18:08:51 +08:00
|
|
|
|
ElMessage.success("新会话已创建!可以开始聊天了");
|
2025-03-25 19:51:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
const showSession = async () => {
|
|
|
|
|
|
//获取历史会话
|
|
|
|
|
|
let req = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
type: "UserID",
|
2025-04-03 21:51:05 +08:00
|
|
|
|
session_type: 1, //通用会话
|
2025-03-26 18:08:51 +08:00
|
|
|
|
};
|
|
|
|
|
|
let result = await FindSessionService(req);
|
|
|
|
|
|
historySessions.value = result.data;
|
|
|
|
|
|
sessionIsShow.value = !sessionIsShow.value;
|
|
|
|
|
|
};
|
|
|
|
|
|
const getShortenedName = (name: string) => {
|
|
|
|
|
|
if (name.length > 10) {
|
|
|
|
|
|
return name.slice(0, 10) + "...";
|
|
|
|
|
|
}
|
|
|
|
|
|
return name;
|
|
|
|
|
|
};
|
2025-03-25 19:51:06 +08:00
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
const getMessage = async (session_id: number) => {
|
2025-04-13 15:51:15 +08:00
|
|
|
|
historyMsgHtml.value.length = 0; // 清空历史消息
|
2025-04-07 19:31:41 +08:00
|
|
|
|
let result = {};
|
|
|
|
|
|
try {
|
|
|
|
|
|
let req = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
session_id: session_id,
|
|
|
|
|
|
};
|
|
|
|
|
|
result = await GetMessageService(req);
|
|
|
|
|
|
if (result["code"] === 0) {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
// console.log(result["data"]);
|
2025-04-07 19:31:41 +08:00
|
|
|
|
let data = result["data"];
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
|
if (data[i]["Type"] === 3) {
|
|
|
|
|
|
let msg: GenMessage = data[i];
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let pMsgContent = "";
|
2025-04-07 19:31:41 +08:00
|
|
|
|
if (msg.Status == 3) {
|
|
|
|
|
|
let file_msg: GenerationMessage = JSON.parse(msg.Msg);
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let file_content = file_msg.file_content
|
2025-04-07 19:31:41 +08:00
|
|
|
|
for (let i = 0; i < file_content.length; i++) {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
if (file_content[i].file_type == "image_file") {
|
|
|
|
|
|
pMsgContent += `![${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent += `文件:[${file_content[i].file_content.UserFileName}](${fileUrl + file_content[i].file_content.file_store_name})` + "\n\n";
|
|
|
|
|
|
}
|
2025-04-07 19:31:41 +08:00
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
pMsgContent = pMsgContent + file_msg.text;
|
2025-04-07 19:31:41 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
pMsgContent = msg.Msg;
|
|
|
|
|
|
}
|
|
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "user",
|
|
|
|
|
|
content: pMsgContent,
|
|
|
|
|
|
finished: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (data[i]["Type"] === 4) {
|
|
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "assistant",
|
|
|
|
|
|
content: data[i]["Msg"],
|
|
|
|
|
|
finished: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("未知消息类型");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getMessageWithFile = async (session_id: number) => {
|
2025-03-25 19:51:06 +08:00
|
|
|
|
let result = {};
|
|
|
|
|
|
try {
|
|
|
|
|
|
let req = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
2025-03-26 18:08:51 +08:00
|
|
|
|
session_id: session_id,
|
2025-03-25 19:51:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
result = await GetMessageService(req);
|
|
|
|
|
|
if (result["code"] === 0) {
|
|
|
|
|
|
console.log(result["data"]);
|
2025-03-26 18:08:51 +08:00
|
|
|
|
let data = result["data"];
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
|
|
if (data[i]["Type"] === 3) {
|
2025-04-01 16:07:25 +08:00
|
|
|
|
let msg: GenMessage = data[i];
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let pMsgContent = "";
|
2025-04-01 16:07:25 +08:00
|
|
|
|
if (msg.Status == 3) {
|
|
|
|
|
|
let img_msg: ImageMessage = JSON.parse(msg.Msg);
|
2025-04-01 14:40:20 +08:00
|
|
|
|
//解析成md格式
|
2025-09-23 20:35:33 +08:00
|
|
|
|
let img_content = img_msg.image_content
|
2025-04-01 21:31:59 +08:00
|
|
|
|
for (let i = 0; i < img_content.length; i++) {
|
|
|
|
|
|
pMsgContent += `![${img_content[i].img_name}](${img_content[i].img_url})` + "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
pMsgContent = pMsgContent + img_msg.text;
|
2025-04-01 16:07:25 +08:00
|
|
|
|
} else {
|
2025-04-01 14:40:20 +08:00
|
|
|
|
pMsgContent = msg.Msg;
|
|
|
|
|
|
}
|
2025-03-26 18:08:51 +08:00
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "user",
|
2025-04-01 14:40:20 +08:00
|
|
|
|
content: pMsgContent,
|
2025-03-26 18:08:51 +08:00
|
|
|
|
finished: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (data[i]["Type"] === 4) {
|
|
|
|
|
|
messages.push({
|
|
|
|
|
|
role: "assistant",
|
|
|
|
|
|
content: data[i]["Msg"],
|
|
|
|
|
|
finished: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("未知消息类型");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-25 19:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.log(e);
|
2025-03-22 18:11:38 +08:00
|
|
|
|
}
|
2025-03-25 19:51:06 +08:00
|
|
|
|
return {};
|
|
|
|
|
|
};
|
2025-04-07 19:31:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-08 14:16:39 +08:00
|
|
|
|
const MessageTextToDoc = async (content: string) => {
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-05-08 14:16:39 +08:00
|
|
|
|
textToDocFileContent.value = content;
|
2025-05-19 19:14:22 +08:00
|
|
|
|
textToDocFileVisible.value = true;
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
vditor.value = new Vditor(vditorRef.value, {
|
2025-05-08 14:16:39 +08:00
|
|
|
|
mode: 'sv',
|
|
|
|
|
|
height: '600px',
|
|
|
|
|
|
width: '100%',
|
|
|
|
|
|
cache: { enable: false },
|
|
|
|
|
|
value: textToDocFileContent.value,
|
|
|
|
|
|
});
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-05-08 14:16:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-27 16:09:22 +08:00
|
|
|
|
const copyMessage = (content: string) => {
|
2025-03-28 21:34:11 +08:00
|
|
|
|
navigator.clipboard
|
|
|
|
|
|
.writeText(content)
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
ElMessage.success("复制成功");
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
|
ElMessage.error("复制失败: " + error);
|
|
|
|
|
|
});
|
2025-03-27 16:09:22 +08:00
|
|
|
|
};
|
2025-03-31 13:58:13 +08:00
|
|
|
|
|
2025-09-23 20:35:33 +08:00
|
|
|
|
const checkTokenIsValidAndRefresh = () => {
|
|
|
|
|
|
let last_refresh = localStorage.getItem("refresh_time"); //localStorage.setItem("refresh_time", Date.now().toString());
|
|
|
|
|
|
let now = Date.now();
|
|
|
|
|
|
let isValid = false;
|
|
|
|
|
|
if (last_refresh) {
|
|
|
|
|
|
let diff = now - parseInt(last_refresh);
|
|
|
|
|
|
//超过1小时,token过期
|
|
|
|
|
|
if (diff < 60 * 60 * 1000) {
|
|
|
|
|
|
isValid = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
isValid = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isValid == false) {
|
|
|
|
|
|
GetModelListByFunctionName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-31 13:58:13 +08:00
|
|
|
|
const GetModelListByFunctionName = async () => {
|
|
|
|
|
|
let req = {
|
|
|
|
|
|
function: "gen-ai-chat",
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
};
|
2025-04-01 16:07:25 +08:00
|
|
|
|
try {
|
2025-03-31 13:58:13 +08:00
|
|
|
|
let result = await FindModelListByFunctionName(req);
|
|
|
|
|
|
if (result["code"] === 0) {
|
|
|
|
|
|
ModelList.value = result["data"];
|
2025-09-23 20:35:33 +08:00
|
|
|
|
if (userUIconfigInfo.value.gen_ai_function.model_id == 0) {
|
2025-05-19 19:14:22 +08:00
|
|
|
|
selectModel.value = ModelList.value[0].ID;
|
2025-09-23 20:35:33 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
selectModel.value = userUIconfigInfo.value.gen_ai_function.model_id;
|
|
|
|
|
|
temperature.value = userUIconfigInfo.value.gen_ai_function.temperature;
|
|
|
|
|
|
topP.value = userUIconfigInfo.value.gen_ai_function.top_p;
|
|
|
|
|
|
sessionID.value = userUIconfigInfo.value.gen_ai_function.session_id;
|
|
|
|
|
|
if (sessionID.value != 0) {
|
|
|
|
|
|
getMessage(sessionID.value);
|
|
|
|
|
|
}
|
2025-05-19 19:14:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
//console.log("gen_ai_chat_model_id:", gen_ai_chat_model_id);
|
|
|
|
|
|
//console.log("selectModel:", selectModel.value);
|
|
|
|
|
|
// selectModel.value = ModelList.value[0].ID;
|
|
|
|
|
|
//console.log("model_list:", ModelList.value);
|
2025-03-31 13:58:13 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error(result["msg"]);
|
|
|
|
|
|
}
|
2025-04-01 16:07:25 +08:00
|
|
|
|
} catch (e) {
|
2025-03-31 13:58:13 +08:00
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GetModelListByFunctionName();
|
2025-04-01 14:40:20 +08:00
|
|
|
|
|
|
|
|
|
|
const getFileListData = async () => {
|
2025-04-01 16:07:25 +08:00
|
|
|
|
let req = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
type: "all",
|
|
|
|
|
|
};
|
|
|
|
|
|
let result = await FindUserFileService(req);
|
|
|
|
|
|
if (result["code"] === 0) {
|
|
|
|
|
|
filteredFiles.value = result["data"];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error(result["msg"]);
|
|
|
|
|
|
}
|
2025-04-01 14:40:20 +08:00
|
|
|
|
};
|
2025-05-08 14:16:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const HandleTextToDocFile = async () => {
|
|
|
|
|
|
// 处理文本创建文件的逻辑
|
|
|
|
|
|
//console.log("文本创建文件:", textToDocFileName.value, vditor.value.getValue(), selectFileDocType.value);
|
2025-05-08 14:19:10 +08:00
|
|
|
|
if (textToDocFileName.value.trim() === "") {
|
|
|
|
|
|
ElMessage.warning("文件名不能为空");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-05-08 14:16:39 +08:00
|
|
|
|
let req = {
|
|
|
|
|
|
token: localStorage.getItem("token"),
|
|
|
|
|
|
file_name: textToDocFileName.value,
|
|
|
|
|
|
text: vditor.value.getValue(),
|
|
|
|
|
|
file_type: selectFileDocType.value,
|
|
|
|
|
|
};
|
|
|
|
|
|
let result = await SetMessageTextToDocService(req);
|
|
|
|
|
|
if (result["code"] === 0) {
|
|
|
|
|
|
ElMessage.success("文件已加入创建队列,请等待一段时间后可在你的文件中查看!");
|
|
|
|
|
|
textToDocFileVisible.value = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error(result["msg"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-25 19:51:06 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
2025-03-26 18:08:51 +08:00
|
|
|
|
.chat-app {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.history-sessions {
|
|
|
|
|
|
width: 15%;
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
border-right: 1px solid #e1e1e1;
|
|
|
|
|
|
scrollbar-width: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.history-sessions ul {
|
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.history-sessions li {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
border-bottom: 1px solid #e1e1e1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.history-sessions li:hover {
|
|
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 19:51:06 +08:00
|
|
|
|
.chat-container {
|
2025-03-26 18:08:51 +08:00
|
|
|
|
flex: 1;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
padding: 20px;
|
2025-03-28 21:34:11 +08:00
|
|
|
|
height: 100%;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-messages {
|
|
|
|
|
|
flex: 1;
|
2025-09-23 20:35:33 +08:00
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
/* 允许垂直滚动 */
|
|
|
|
|
|
padding: 10px;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
margin-bottom: 20px;
|
2025-03-28 21:34:11 +08:00
|
|
|
|
scrollbar-width: 10px;
|
2025-03-31 19:06:57 +08:00
|
|
|
|
height: 100%;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.messages-wrapper {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2025-09-23 20:35:33 +08:00
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
/* 确保内部可以滚动 */
|
2025-03-25 19:51:06 +08:00
|
|
|
|
height: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
margin-bottom: 15px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message.user {
|
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-avatar {
|
|
|
|
|
|
width: 40px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
line-height: 40px;
|
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message.assistant .message-avatar {
|
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message-content {
|
|
|
|
|
|
background-color: #f0f9eb;
|
|
|
|
|
|
border: 1px solid #e1f3d8;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
padding: 10px 15px;
|
|
|
|
|
|
white-space: pre-wrap;
|
2025-05-03 13:19:03 +08:00
|
|
|
|
max-width: 800px;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.message.assistant .message-content {
|
|
|
|
|
|
background-color: #f3f4f6;
|
|
|
|
|
|
border: 1px solid #dce4eb;
|
2025-05-03 13:19:03 +08:00
|
|
|
|
max-width: 1000px;
|
2025-03-25 19:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading-indicator {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: #999;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chat-input {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.el-input {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2025-03-26 18:08:51 +08:00
|
|
|
|
|
|
|
|
|
|
.session-card {
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
height: 20%;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-03-26 18:08:51 +08:00
|
|
|
|
.session-card2 {
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
height: 70%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.session-card ul {
|
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.session-card li {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
border-bottom: 1px solid #e1e1e1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.session-card li:hover {
|
|
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.scroll-wrapper {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
}
|
2025-03-27 16:09:22 +08:00
|
|
|
|
|
2025-03-27 17:33:35 +08:00
|
|
|
|
.code-controls {
|
2025-03-27 16:09:22 +08:00
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 5px;
|
|
|
|
|
|
right: 5px;
|
2025-03-27 17:33:35 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.copy-code-button {
|
2025-03-28 21:34:11 +08:00
|
|
|
|
background-color: dodgerblue;
|
|
|
|
|
|
color: white;
|
2025-03-27 17:33:35 +08:00
|
|
|
|
width: 30px;
|
|
|
|
|
|
height: 20px;
|
2025-03-28 21:34:11 +08:00
|
|
|
|
border: 0;
|
2025-03-27 17:33:35 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2025-03-27 16:09:22 +08:00
|
|
|
|
}
|
2025-03-27 17:33:35 +08:00
|
|
|
|
|
|
|
|
|
|
.el-icon-copy {
|
|
|
|
|
|
margin-right: 5px;
|
|
|
|
|
|
}
|
2025-04-01 14:40:20 +08:00
|
|
|
|
|
|
|
|
|
|
/* 对话框 */
|
|
|
|
|
|
.file-list {
|
|
|
|
|
|
max-height: 400px;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
border: 1px solid #e4e7ed;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
.file-icon {
|
|
|
|
|
|
margin-right: 5px;
|
|
|
|
|
|
color: #606266;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
.file-time {
|
|
|
|
|
|
float: right;
|
|
|
|
|
|
color: #909399;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
.footer-bar {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
.selected-count {
|
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-01 14:40:20 +08:00
|
|
|
|
.el-icon-document {
|
|
|
|
|
|
color: #409eff;
|
|
|
|
|
|
}
|
2025-04-23 15:11:16 +08:00
|
|
|
|
|
|
|
|
|
|
.model-dropdown {
|
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dropdown-content {
|
|
|
|
|
|
width: 400px;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.model-params {
|
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
}
|
2025-09-23 20:35:33 +08:00
|
|
|
|
|
2025-04-23 15:11:16 +08:00
|
|
|
|
.param-value {
|
|
|
|
|
|
margin-top: 5px;
|
|
|
|
|
|
text-align: right;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.param-item {
|
|
|
|
|
|
margin: 25px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.param-label {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
color: #606266;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tip-icon {
|
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
color: #909399;
|
|
|
|
|
|
cursor: help;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.param-value {
|
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
color: #409eff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 自定义滑块样式 */
|
|
|
|
|
|
:deep(.el-slider__runway) {
|
|
|
|
|
|
height: 6px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.el-slider__button) {
|
|
|
|
|
|
width: 16px;
|
|
|
|
|
|
height: 16px;
|
|
|
|
|
|
}
|
2025-03-25 19:51:06 +08:00
|
|
|
|
</style>
|