添加通用交互部分的之前配置部分保存及设置自动保存
This commit is contained in:
parent
ed6f502b49
commit
7b09c0d95b
|
|
@ -1,5 +1,6 @@
|
||||||
import request from '@/utils/request2';
|
import request from '@/utils/request2';
|
||||||
import md5 from 'js-md5';
|
import md5 from 'js-md5';
|
||||||
|
import {UserUISettings} from '@/types/user';
|
||||||
|
|
||||||
export const loginService = (loginData) => {
|
export const loginService = (loginData) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
@ -230,6 +231,26 @@ export const getThirdPartyLoginStatus = (Data) => {
|
||||||
return request.get(url)
|
return request.get(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取用户前端配置
|
||||||
|
export const getUserUIconfigInfoService = (Data) => {
|
||||||
|
let url ='/user/get_user_ui_config'
|
||||||
|
return request.get(url,{
|
||||||
|
headers: {
|
||||||
|
'token': Data.token,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateUserUIconfigInfoService = (Data: UserUISettings, token:string) => {
|
||||||
|
return request.post('/user/set_user_ui_config' , Data, {
|
||||||
|
headers: {
|
||||||
|
'token': token,
|
||||||
|
'Content-Type': 'application/json' // 设置请求头为 JSON 格式
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const fetchUserData = () => {
|
export const fetchUserData = () => {
|
||||||
return {
|
return {
|
||||||
"list": [
|
"list": [
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,36 @@ export interface ThirdPartyUserInfo {
|
||||||
third_party_user_name: string; // 第三方用户名
|
third_party_user_name: string; // 第三方用户名
|
||||||
third_party_user_avatar: string; // 第三方用户头像
|
third_party_user_avatar: string; // 第三方用户头像
|
||||||
third_party_user_url: string; // 第三方用户主页,可选
|
third_party_user_url: string; // 第三方用户主页,可选
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {
|
||||||
|
// "user_id": 0,
|
||||||
|
// "theme": "",
|
||||||
|
// "language": "",
|
||||||
|
// "font_size": 0,
|
||||||
|
// "gen_ai_function": {
|
||||||
|
// "model_id": 0,
|
||||||
|
// "session_id": 0
|
||||||
|
// },
|
||||||
|
// "k_base_function": {
|
||||||
|
// "model_id": 0,
|
||||||
|
// "session_id": 0
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
export interface UserUISettings {
|
||||||
|
user_id: number; // 用户ID
|
||||||
|
theme: string; // 主题
|
||||||
|
language: string; // 语言
|
||||||
|
font_size: number; // 字体大小
|
||||||
|
gen_ai_function: {
|
||||||
|
model_id: number; // 模型ID
|
||||||
|
session_id: number; // 会话ID
|
||||||
|
temperature: number; // 温度
|
||||||
|
top_p: number; // 采样范围
|
||||||
|
};
|
||||||
|
k_base_function: {
|
||||||
|
model_id: number; // 模型ID
|
||||||
|
session_id: number; // 会话ID
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,26 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useSidebarStore } from '@/store/sidebar';
|
import { useSidebarStore } from '@/store/sidebar';
|
||||||
import { useTabsStore } from '@/store/tabs';
|
import { useTabsStore } from '@/store/tabs';
|
||||||
|
import {getUserUIconfigInfoService} from '@/api/user';
|
||||||
|
import {UserUISettings} from '@/types/user';
|
||||||
import vHeader from '@/components/header.vue';
|
import vHeader from '@/components/header.vue';
|
||||||
import vSidebar from '@/components/sidebar.vue';
|
import vSidebar from '@/components/sidebar.vue';
|
||||||
import vTabs from '@/components/tabs.vue';
|
import vTabs from '@/components/tabs.vue';
|
||||||
|
|
||||||
|
const getUserUIconfigInfo = async () => {
|
||||||
|
let req = {
|
||||||
|
token: localStorage.getItem('token'),
|
||||||
|
}
|
||||||
|
let res = await getUserUIconfigInfoService(req);
|
||||||
|
if (res['code'] === 0){
|
||||||
|
let settings: UserUISettings = res['data'];
|
||||||
|
localStorage.setItem('userUIconfigInfo', JSON.stringify(settings));
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('userUIconfigInfo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserUIconfigInfo();
|
||||||
const sidebar = useSidebarStore();
|
const sidebar = useSidebarStore();
|
||||||
const tabs = useTabsStore();
|
const tabs = useTabsStore();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@
|
||||||
:step="0.1"
|
:step="0.1"
|
||||||
:show-tooltip="false"
|
:show-tooltip="false"
|
||||||
/>
|
/>
|
||||||
<div class="param-value">{{ temperature.toFixed(1) }}</div>
|
<div class="param-value">{{ temperature }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Top P 参数 -->
|
<!-- Top P 参数 -->
|
||||||
|
|
@ -178,7 +178,7 @@
|
||||||
:step="0.1"
|
:step="0.1"
|
||||||
:show-tooltip="false"
|
:show-tooltip="false"
|
||||||
/>
|
/>
|
||||||
<div class="param-value">{{ topP.toFixed(1) }}</div>
|
<div class="param-value">{{ topP }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -318,28 +318,32 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted, reactive, nextTick } from "vue";
|
import { ref, onMounted, onUnmounted, reactive, nextTick,watch } from "vue";
|
||||||
import { ElCard, ElInput, ElButton, ElDialog } from "element-plus";
|
import { ElCard, ElInput, ElButton, ElDialog } from "element-plus";
|
||||||
import { WSMessage, GenMessage } from "@/types/im";
|
import { WSMessage, GenMessage } from "@/types/im";
|
||||||
import { GetMessageService } from "@/api/im";
|
import { GetMessageService } from "@/api/im";
|
||||||
import { FindUserFileService } from "@/api/file";
|
import { FindUserFileService } from "@/api/file";
|
||||||
import { Model } from "@/types/model";
|
import { Model } from "@/types/model";
|
||||||
|
import {UserUISettings} from '@/types/user';
|
||||||
import { File, fileUrl } from "@/types/file";
|
import { File, fileUrl } from "@/types/file";
|
||||||
import { Session } from "@/types/session";
|
import { Session } from "@/types/session";
|
||||||
import { FindSessionService } from "@/api/session";
|
import { FindSessionService } from "@/api/session";
|
||||||
import { SetMessageTextToDocService } from "@/api/tool";
|
import { SetMessageTextToDocService } from "@/api/tool";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { Check, DocumentCopy,Document } from "@element-plus/icons-vue";
|
import { Check, DocumentCopy,Document, PriceTag } from "@element-plus/icons-vue";
|
||||||
import MarkdownIt from "markdown-it";
|
import MarkdownIt from "markdown-it";
|
||||||
import hljs from "highlight.js";
|
import hljs from "highlight.js";
|
||||||
import UploadFile from "@/components/upload-file.vue";
|
import UploadFile from "@/components/upload-file.vue";
|
||||||
|
import { updateUserUIconfigInfoService } from "@/api/user";
|
||||||
import { FindModelListByFunctionName } from "@/api/function";
|
import { FindModelListByFunctionName } from "@/api/function";
|
||||||
import markdownItHighlightjs from "markdown-it-highlightjs";
|
import markdownItHighlightjs from "markdown-it-highlightjs";
|
||||||
import markdownItKatex from "markdown-it-katex";
|
import markdownItKatex from "markdown-it-katex";
|
||||||
import mermaidPlugin from "@agoose77/markdown-it-mermaid";
|
import mermaidPlugin from "@agoose77/markdown-it-mermaid";
|
||||||
import "katex/dist/katex.min.css";
|
import "katex/dist/katex.min.css";
|
||||||
import Vditor from 'vditor'
|
import Vditor from 'vditor';
|
||||||
import 'vditor/dist/index.css';
|
import 'vditor/dist/index.css';
|
||||||
|
import { json } from "d3";
|
||||||
|
import { pa } from "element-plus/es/locale";
|
||||||
|
|
||||||
|
|
||||||
interface Message {
|
interface Message {
|
||||||
|
|
@ -409,6 +413,17 @@ const textToDocFileName = ref(""); // 文本创建文件的名称
|
||||||
const textToDocFileContent = ref(""); // 文本创建文件的内容
|
const textToDocFileContent = ref(""); // 文本创建文件的内容
|
||||||
const vditor = ref(); // Vditor 实例
|
const vditor = ref(); // Vditor 实例
|
||||||
const vditorRef = ref(null);
|
const vditorRef = ref(null);
|
||||||
|
const userUIconfigInfo = ref<UserUISettings>({} as UserUISettings); // 用户UI配置
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//监听需要保存的配置
|
||||||
|
watch(
|
||||||
|
[selectModel, temperature, topP,sessionID],
|
||||||
|
() => { //保存配置
|
||||||
|
updateUserUIconfigInfo();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
const historyMsgHtml= ref([]); // 用于存储历史消息的HTML内容
|
const historyMsgHtml= ref([]); // 用于存储历史消息的HTML内容
|
||||||
|
|
@ -484,6 +499,7 @@ const handleSelectFileConfirm = () => {
|
||||||
console.log("选中的文件:", selectedFiles.value);
|
console.log("选中的文件:", selectedFiles.value);
|
||||||
// 在这里可以进行文件上传或其他操作
|
// 在这里可以进行文件上传或其他操作
|
||||||
selectFileVisible.value = false; // 关闭对话框
|
selectFileVisible.value = false; // 关闭对话框
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -597,6 +613,11 @@ onMounted(() => {
|
||||||
socket.value = null;
|
socket.value = null;
|
||||||
console.error("WebSocket 发生错误:", error);
|
console.error("WebSocket 发生错误:", error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
userUIconfigInfo.value = JSON.parse(
|
||||||
|
localStorage.getItem("userUIconfigInfo") || "{}"
|
||||||
|
);
|
||||||
|
//console.log("userUIconfigInfo:", userUIconfigInfo.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|
@ -636,6 +657,26 @@ const doReceiveMessage = (event) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateUserUIconfigInfo = () => {
|
||||||
|
//将配置保存到数据库
|
||||||
|
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("保存失败");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const sendMessage = () => {
|
const sendMessage = () => {
|
||||||
localStorage.setItem("gen_ai_chat_model_id", selectModel.value.toString());
|
localStorage.setItem("gen_ai_chat_model_id", selectModel.value.toString());
|
||||||
sendMessageWithFile()
|
sendMessageWithFile()
|
||||||
|
|
@ -925,12 +966,16 @@ const GetModelListByFunctionName = async () => {
|
||||||
let result = await FindModelListByFunctionName(req);
|
let result = await FindModelListByFunctionName(req);
|
||||||
if (result["code"] === 0) {
|
if (result["code"] === 0) {
|
||||||
ModelList.value = result["data"];
|
ModelList.value = result["data"];
|
||||||
let gen_ai_chat_model_id = localStorage.getItem("gen_ai_chat_model_id");
|
if(userUIconfigInfo.value.gen_ai_function.model_id ==0 ){
|
||||||
//console.log("gen_ai_chat_model_id:", gen_ai_chat_model_id);
|
|
||||||
if(gen_ai_chat_model_id == "" || gen_ai_chat_model_id == null){
|
|
||||||
selectModel.value = ModelList.value[0].ID;
|
selectModel.value = ModelList.value[0].ID;
|
||||||
}else{
|
}else{
|
||||||
selectModel.value = parseInt(gen_ai_chat_model_id);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//console.log("gen_ai_chat_model_id:", gen_ai_chat_model_id);
|
//console.log("gen_ai_chat_model_id:", gen_ai_chat_model_id);
|
||||||
//console.log("selectModel:", selectModel.value);
|
//console.log("selectModel:", selectModel.value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue