From c0c4402902a9062743b3632d946c2aee426351d4 Mon Sep 17 00:00:00 2001 From: ylj20011123 Date: Tue, 6 Jan 2026 19:26:01 +0800 Subject: [PATCH] update --- .../deepseek/components/RobotDialogueBox.vue | 12 +- src/components/deepseek/index.less | 2 +- src/components/deepseek/index.vue | 846 ++++++++++++------ src/components/service.ts | 18 + src/request/requestPython.ts | 80 ++ 5 files changed, 670 insertions(+), 288 deletions(-) create mode 100644 src/request/requestPython.ts diff --git a/src/components/deepseek/components/RobotDialogueBox.vue b/src/components/deepseek/components/RobotDialogueBox.vue index 03bb0af..c2fe86b 100644 --- a/src/components/deepseek/components/RobotDialogueBox.vue +++ b/src/components/deepseek/components/RobotDialogueBox.vue @@ -399,8 +399,10 @@ const handleConfigRequest = async ( return handleGetListSumObj(resultNest, config.totalField); } return resultNest; + } else if (config.responseFormat === 'original') { + return data.Result_Data; } - } else { + } else if (detail.RULE_SOURCE === 2000) { // 用户自定义 if (config.responseFormat === "nestingList") { data = handleSetRowKeyTable(wrapTreeNode(data.Result_Data.List)); @@ -551,6 +553,10 @@ const handleConfigRequest = async ( } return finalRes; + } else if (detail.RULE_SOURCE === 3000) { + if (config.responseFormat === 'original') { + return data.Result_Data.content; + } } }; @@ -802,7 +808,7 @@ const handleAnalyzeConfig = async (configDetail: any, answer: any) => { // 配置请求的参数 let req: any = handleGetReq(configDetail, answer); - console.log("req2", req); + console.log("req2", JSON.parse(JSON.stringify(req))); // 给post的请求 的参数 需要包一层的包一层 if (OUTPUT_FORMAT) { if (OUTPUT_FORMAT.paramsFormat === "searchModel") { @@ -824,7 +830,7 @@ const handleAnalyzeConfig = async (configDetail: any, answer: any) => { haveALLNull = false; } } - + console.log("reqreqreqreq", JSON.parse(JSON.stringify(req))); if (!req.ServerpartId && !req.SERVERPART_ID) { req.ServerpartId = allID.value; } diff --git a/src/components/deepseek/index.less b/src/components/deepseek/index.less index de906ba..ba79c1e 100644 --- a/src/components/deepseek/index.less +++ b/src/components/deepseek/index.less @@ -59,7 +59,7 @@ } .leftFilterTabBox { - height: calc(100vh - 540px); + height: calc(100vh - 580px); .el-tabs__header { .el-tabs__nav-wrap { diff --git a/src/components/deepseek/index.vue b/src/components/deepseek/index.vue index 647b5e0..7d72385 100644 --- a/src/components/deepseek/index.vue +++ b/src/components/deepseek/index.vue @@ -17,8 +17,9 @@ import { } from "./service"; import moment from "moment"; import pageBg from '../../assets/pageBg.png' +import { handleGetGeminiResult } from "../service"; -const userInput = ref('新桥服务区python营收'); +const userInput = ref(''); const loading = ref(); const error = ref(); const response = ref(); @@ -116,6 +117,45 @@ let modalTypeDataList = reactive([ const hideLeft = ref(true); // 省略过程 const omitProcess = ref(false); +// 本次会话的id +const thisSessionId = ref(""); +// 使用专家模式 +const pythonSemantics = ref(true); +// 选择的模型 +const selectModal = ref(1); +// 专家模式选择的模型 +const selectModalList = [ + { label: "[日常使用] Gemini 2.5 Flash ", value: 1 }, + { label: "[专家模式] Gemini 3.0 Flash", value: 2 }, + // { label: "[知识库 3.3] Gemini 2.5 Flash", value: 3 }, + // { label: "gemini-3-flash-preview(深度分析、复杂逻辑)", value: 1 }, + // { label: "gemini-2.5-flash(日常快速问答)", value: 2 }, + // { label: "gemini-3-flash-preview", value: 3 }, +] + +const selectModalCacheIDList: any = { + 1: "cachedContents/oo1x7gs8rnvcd5gd0vkyqopgzs06z4snmx5m8qgp", + 2: "cachedContents/jipudug6kwzw83niu4ufka93cpqwepumnfx4evsy", + // 3: "cachedContents/oo1x7gs8rnvcd5gd0vkyqopgzs06z4snmx5m8qgp", + // 4: "cachedContents/8x6no7sqolqrakwjra9md56r4pixe32obxc9jarp", + // 5: "cachedContents/oo1x7gs8rnvcd5gd0vkyqopgzs06z4snmx5m8qgp" +} + +const selectModalListObj: any = { + 1: "gemini-2.5-flash", + 2: "gemini-3-flash-preview", + // 3: "gemini-2.5-flash", + // 4: "gemini-3-flash-preview", + // 5: "gemini-2.5-flash", + // 3: "gemini-3-flash-preview" +} +const selectModalCacheID = ref("cachedContents/95ttblr2a58llzeoiaqmkd0kavw3kf4o6bkicx51") +// const selectModalCacheID = { +// 1: "cachedContents/ajvtu6x0pjpgqrox2zzumdj8fxt5pti9pk73u633", +// 2: "cachedContents/spsbxuz8yqfjqklyyogf0wffzech2eh5xwosfw3g", +// 3: "cachedContents/95ttblr2a58llzeoiaqmkd0kavw3kf4o6bkicx51", +// } + // 左侧的筛选条件的tab显示的内容 const leftTabShow = ref("first"); // 页面类型 通过来自哪里 来存值 0 本身 1 云南大屏 @@ -545,6 +585,11 @@ const handleSendRequest = async (bigObj?: any) => { } }); + if (pythonSemantics.value) { + await handleAskDirectlyDeepseek(); + return + } + // 判断是否开启了自由定义 开启了就换个方法 if (startFree.value || thisQuestion.length > 50) { await handleAskDirectlyDeepseek(); @@ -600,8 +645,6 @@ const handleSendRequest = async (bigObj?: any) => { return } - - if (useMapData) { modalTypeDataList.forEach((item: any) => { if (bigObj.value) { @@ -627,6 +670,7 @@ const handleSendRequest = async (bigObj?: any) => { await handleNewRuleList(); for (let i = 0; i < modalTypeDataList.length; i++) { + console.log("thisQuestion21", thisQuestion); if (modalTypeDataList[i].isShow) { // 调用自己的语义 const mapData: any = await RobotDialogueBoxRef.value.handleSubmit( @@ -697,31 +741,32 @@ const handleSendRequest = async (bigObj?: any) => { dataStr += `
`; } - if (item.tableData && item.tableData.length > 0) { - item.tableData.forEach((subItem: any) => { - let str: string = ""; - let obj: any = JSON.parse(JSON.stringify(subItem)); - obj = handleChangObjType(obj); + // 拿一下语义规则的内容 + let OUTPUT_FORMATRUNLE: any = JSON.parse(item.ruleDetail.OUTPUT_FORMAT) + if (OUTPUT_FORMATRUNLE.responseFormat !== 'original') { + if (item.tableData && item.tableData.length > 0) { + item.tableData.forEach((subItem: any) => { + let str: string = ""; + let obj: any = JSON.parse(JSON.stringify(subItem)); + obj = handleChangObjType(obj); - console.log("obj", obj); - console.log("showColumnsListshowColumnsList", showColumnsList); - console.log("itemitem", item); - - if (obj) { - let text: string = handleTableDataToStr( - obj, - showColumnsList, - item.ruleDetail.CHILD_NODENAME, - 1 - ); - str = `${text}`; - } - if (str) { - dataStr += ` + if (obj) { + let text: string = handleTableDataToStr( + obj, + showColumnsList, + item.ruleDetail.CHILD_NODENAME, + 1 + ); + str = `${text}`; + } + if (str) { + dataStr += ` ${str}`; - } - }); + } + }); + } } + if (item.VHtml && item.VHtml !== "暂无数据") { allStr += `#id【${item.ruleDetail.ANALYSISRULE_ID}】接口数据如下#:
${item.VHtml}
`; } else { @@ -1287,23 +1332,12 @@ const handleGetAnswerID = async (obj: any) => { // let responseText: string = ""; let oldMessage: any = []; // 当对话列表小于3时 说明是第一次问问题 那么就直接找user就好了 - if ( - obj.messageList && - obj.messageList.length < 2 && - obj.messageList.length > 0 - ) { + if (obj.messageList && obj.messageList.length < 2 && obj.messageList.length > 0) { obj.messageList.forEach((item: any, index: number) => { - // if (startFree.value ? item.role === "user" : item.role === "default") { if (item.role === "default") { oldMessage.push({ role: "user", content: item.content, - // (RoleDescription.value ? suffixText.value : "") + - // (useMapData - // ? item.mapContent === "查询失败" - // ? "" - // : item.mapContent - // : item.content), }); } else if (item.role === "user") { oldMessage.push({ @@ -1320,12 +1354,6 @@ const handleGetAnswerID = async (obj: any) => { oldMessage.push({ role: "user", content: item.content, - // (RoleDescription.value ? suffixText.value : "") + - // (useMapData - // ? item.mapContent === "查询失败" - // ? "" - // : item.mapContent - // : item.content), }); } else if (item.role === "assistant") { // 历史回答记录 @@ -1337,24 +1365,8 @@ const handleGetAnswerID = async (obj: any) => { }); } - // if (obj.messageList && obj.messageList.length > 0) { - // obj.messageList.forEach((item: any, index: number) => { - // if (item.role !== "default") { - // if (index + 1 === obj.messageList.length) { - // oldMessage.push({ - // role: item.role, - // content: - // (RoleDescription.value ? suffixText.value : "") + item.content, - // }); - // } else { - // oldMessage.push({ - // role: item.role, - // content: useMapData ? item.mapContent : item.content, - // }); - // } - // } - // }); - // } + + obj.messageList.push({ role: "assistant", content: "", @@ -1364,140 +1376,72 @@ const handleGetAnswerID = async (obj: any) => { }); handleScrollToBottomID("gjldBox" + obj.value); - // 记录是否有数据流 - let hasStreamData: boolean = false; - // 终止器 - const controller = new AbortController(); - controllers.value.push(controller); // 存入全局数组 - showController.value = true; - let timeoutId: any = null; // 记录超时 ID + console.log('pythonSemanticspythonSemantics', pythonSemantics); + // 判断一下 如果开了专家模式 就直接去问 封装成接口的gemini 不然就按原本的路子走 + if (pythonSemantics.value) { + // 拿到最新的问题 + console.log('objobjobjobj', JSON.parse(JSON.stringify(oldMessage))); - try { - const timeoutPromise = new Promise((resolve) => { - timeoutId = setTimeout(() => { - if (!hasStreamData) { - // 仅当没有数据流时才执行超时逻辑 - let list: any = obj.messageList; - list[list.length - 1] = { - ...list[list.length - 1], - content: "请求超时,请稍后重试!", - loading: false, - loadingContent: null, - }; - obj.messageList = list; - resolve({}); - } - }, 60000); - }); - let resText: any = await Promise.race([ - new Promise(async (resolve) => { - try { - // 判断数据流是否继续 - let isStreaming: boolean = true; - let modal = { - model: - obj.value === 1 - ? selectDeepseekVersion.value === 1 - ? "deepseek-chat" - : selectDeepseekVersion.value === 2 - ? "deepseek-reasoner" - : "" - : obj.value === 2 - ? selectDeepseekVersion.value === 1 - ? "deepseek-ai/DeepSeek-V3" - : selectDeepseekVersion.value === 2 - ? "deepseek-ai/DeepSeek-R1-Distill-Llama-70B" - : "" - : obj.value === 3 - ? selectDeepseekVersion.value === 1 - ? "deepseek-v3" - : selectDeepseekVersion.value === 2 - ? "deepseek-r1" - : "" - : obj.value === 4 - ? "qwen-plus" - : obj.value === 5 - ? 'claude-sonnet-4-5' - : '', - messages: [...oldMessage], - stream: true, - // max_tokens: 200000, - // max_tokens: obj.value === 5 ? 200000 : maxTokens.value, - // stop: ["null"], - // temperature: Temperature.value, - // top_p: TopP.value, - // top_k: TopK.value, - // frequency_penalty: FrequencyPenalty.value, - // n: 1, - // response_format: { - // type: "text", - // }, - }; - const options = { - method: "POST", - headers: { - Authorization: - obj.value === 1 - ? "Bearer sk-d47e0bdc7fd249f29d2f0dba807d46f0" - : obj.value === 2 - ? "Bearer sk-nynbgbtnmsffijgkttoimqkptetivviwuqrdhbuclgbmvnsq" - : obj.value === 3 - ? "Bearer sk-1aa2c1c672034c6d826ce62d3aebcb47" - : obj.value === 4 - ? "Bearer sk-1aa2c1c672034c6d826ce62d3aebcb47" - : obj.value === 5 - ? "Bearer sk-f67d5aae13e14efc8a01e8cd0e665d15" - : "", - "Content-Type": "application/json", - }, - body: JSON.stringify(modal), - signal: controller.signal, // 关键:绑定控制器信号 - }; - let geminiContent: any = [] - if (modal.messages && modal.messages.length > 0) { - modal.messages.forEach((item: any, index: number) => { - if (item.role === "user") { - if (index + 1 === modal.messages.length) { - geminiContent.push({ - parts: [ - { - text: item.content, - } - ] - }) - } - } - }) + let geminiContent: any = [] + if (oldMessage && oldMessage.length > 0) { + oldMessage.forEach((item: any, index: number) => { + if (item.role === "user") { + if (index + 1 === oldMessage.length) { + geminiContent.push(item.content) } - // 判断是否成功 - let isSuccess: boolean = false; - const response: any = await fetch( - obj.value === 1 - ? "https://api.deepseek.com/v1/chat/completions" - : obj.value === 2 - ? "https://api.siliconflow.cn/v1/chat/completions" - : obj.value === 3 - ? "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" - : obj.value === 4 - ? "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" - : obj.value === 5 - ? "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent" - : "", - obj.value === 5 ? { + } + }) + } + + // 记录是否有数据流 + let hasStreamData: boolean = false; + // 终止器 + const controller = new AbortController(); + controllers.value.push(controller); // 存入全局数组 + showController.value = true; + let timeoutId: any = null; // 记录超时 ID + try { + const timeoutPromise = new Promise((resolve) => { + timeoutId = setTimeout(() => { + if (!hasStreamData) { + // 仅当没有数据流时才执行超时逻辑 + let list: any = obj.messageList; + list[list.length - 1] = { + ...list[list.length - 1], + content: "请求超时,请稍后重试!", + loading: false, + loadingContent: null, + }; + obj.messageList = list; + resolve({}); + } + }, 60000); + }); + let resText: any = await Promise.race([ + new Promise(async (resolve) => { + try { + // 判断数据流是否继续 + let isStreaming: boolean = true; + const req: any = { + question: geminiContent[0], + config_type: "deep_analysis", + cache_id: selectModal.value ? selectModalCacheIDList[selectModal.value] : "cachedContents/95ttblr2a58llzeoiaqmkd0kavw3kf4o6bkicx51", + model_name: selectModal.value ? selectModalListObj[selectModal.value] : "gemini-2.5-flash", + stream: true, + max_output_tokens: 8192, + thisSessionId: thisSessionId.value || "" + } + let isSuccess: boolean = false; + const response: any = await fetch('http://192.168.1.207:8002/api/gemini/query/', { method: "POST", headers: { "Content-Type": "application/json", - "x-goog-api-key": "AIzaSyAg1lJ8oZL_jMAefrRswIhx5xA8JTOZUTs", }, - body: JSON.stringify({ - contents: geminiContent - }), - } : options - ); - if (response.status === 200) { - isSuccess = true; - } - if (obj.value === 5) { + body: JSON.stringify(req), + }) + if (response.status === 100) { + isSuccess = true; + } // 非流式返回 // const data = await response.json(); const reader = response.body.getReader(); @@ -1508,7 +1452,7 @@ const handleGetAnswerID = async (obj: any) => { const chunk = decoder.decode(value); let JSONChunk = trimFirstChar(chunk) JSONChunk = JSONChunk ? JSON.parse(JSONChunk) : "" - handleStreamChunkIDGemini(JSONChunk ? [JSONChunk] : [], obj) + handleStreamChunkIDGeminiNew(JSONChunk ? [JSONChunk] : [], obj) // 判断当前的这个框 是滚动数组里面的第几个 对他进行判断是不是在底部 let nowShowList: any = []; if (modalTypeDataList && modalTypeDataList.length > 0) { @@ -1540,101 +1484,368 @@ const handleGetAnswerID = async (obj: any) => { } resolve(true) } - } else { - // 创建流式读取器 - const reader = response.body.getReader(); - const decoder = new TextDecoder("utf-8"); - while (isStreaming) { - const { done, value } = await reader.read(); - if (done) break; - // 解码并处理数据 - const chunk = decoder.decode(value); - handleStreamChunkID(chunk, obj); - // 判断当前的这个框 是滚动数组里面的第几个 对他进行判断是不是在底部 - let nowShowList: any = []; - if (modalTypeDataList && modalTypeDataList.length > 0) { - modalTypeDataList.forEach((item: any) => { - if (item.isShow) { - nowShowList.push(item); - } - }); - } - let index: number = 99999; - let isBottom: any = "default"; - if (nowShowList && nowShowList.length > 0) { - nowShowList.forEach((item: any, itemIndex: number) => { - if (item.value === obj.value) { - index = itemIndex; - if (scrollList.value && scrollList.value.length > 0) { - isBottom = scrollList.value[itemIndex].isBottom; - } - } - }); - } - if ( - index === 99999 || - isBottom === "default" || - isBottom === true - ) { - handleScrollToBottomID("gjldBox" + obj.value); - } - - resolve(true); // 完成流处理后resolve + } catch (error: any) { + if (error.name !== "AbortError") { + console.error("流式请求失败:", error); } + } finally { } + }).then((res) => { + hasStreamData = true; // 这里标记数据流出现了 + clearTimeout(timeoutId); // 取消超时逻辑 + }), + timeoutPromise + ]); + showController.value = false; + return resText; + } catch (error) { + let list: any = obj.messageList; + list[list.length - 1] = { + ...list[list.length - 1], + content: "请求超时,请稍后重试!", + loading: false, + loadingContent: null, + }; + obj.messageList = list; + } - // messageList.push({ - // role: "assistant", - // content: responseText.value, - // descResponseText: descResponseText.value, - // }); - obj.responseText = ""; - obj.descResponseText = ""; - showController.value = false; - // handleStop(); - return isSuccess; - } catch (error: any) { - if (error.name !== "AbortError") { - console.error("流式请求失败:", error); - } - } finally { - } - }).then((res) => { - hasStreamData = true; // 这里标记数据流出现了 - clearTimeout(timeoutId); // 取消超时逻辑 - }), - // handleAiDeepThinking(obj, oldMessage, controller).then((res) => { - // if (res) { - // hasStreamData = true; // 这里标记数据流出现了 - // clearTimeout(timeoutId); // 取消超时逻辑 - // } - // }), - timeoutPromise, - ]); - return resText; - } catch (error) { - // modalTypeDataList.forEach((item: any) => { - // if (item.isShow) { - // let list: any = item.messageList; - // list[list.length - 1] = { - // ...list[list.length - 1], - // content: "请求超时,请稍后重试!", - // loading: false, - // loadingContent: null, - // }; - // item.messageList = list; + // 若以后不要流式返回 就把下面这段注释取消掉 就可以一口气返回了 + // const data = await handleGetGeminiResult(req) + // console.log('gemini接口调用结果', data); + // if (data.Result_Code === 100) { + + // obj.responseText = data.Result_Data; + // obj.descResponseText = ""; + // obj.messageList[obj.messageList.length - 1] = { + // ...obj.messageList[obj.messageList.length - 1], + // content: marked(data.Result_Data), + // realContent: data.Result_Data, + // descResponseText: "", + // loading: false, + // loadingContent: null, + // index: + // obj.messageList && obj.messageList.length > 0 + // ? obj.messageList.length + // : 0, + // }; + // showController.value = false; + + // // 判断当前的这个框 是滚动数组里面的第几个 对他进行判断是不是在底部 + // let nowShowList: any = []; + // if (modalTypeDataList && modalTypeDataList.length > 0) { + // modalTypeDataList.forEach((item: any) => { + // if (item.isShow) { + // nowShowList.push(item); + // } + // }); // } - // }); - let list: any = obj.messageList; - list[list.length - 1] = { - ...list[list.length - 1], - content: "请求超时,请稍后重试!", - loading: false, - loadingContent: null, - }; - obj.messageList = list; + // let index: number = 99999; + // let isBottom: any = "default"; + // if (nowShowList && nowShowList.length > 0) { + // nowShowList.forEach((item: any, itemIndex: number) => { + // if (item.value === obj.value) { + // index = itemIndex; + // if (scrollList.value && scrollList.value.length > 0) { + // isBottom = scrollList.value[itemIndex].isBottom; + // } + // } + // }); + // } + + // if ( + // index === 99999 || + // isBottom === "default" || + // isBottom === true + // ) { + // handleScrollToBottomID("gjldBox" + obj.value); + // } + + // return data.Result_Data + // } else { + // let list: any = obj.messageList; + // list[list.length - 1] = { + // ...list[list.length - 1], + // content: "请求超时,请稍后重试!", + // loading: false, + // loadingContent: null, + // }; + // obj.messageList = list; + // } + } else { + // 记录是否有数据流 + let hasStreamData: boolean = false; + // 终止器 + const controller = new AbortController(); + controllers.value.push(controller); // 存入全局数组 + showController.value = true; + let timeoutId: any = null; // 记录超时 ID + + try { + const timeoutPromise = new Promise((resolve) => { + timeoutId = setTimeout(() => { + if (!hasStreamData) { + // 仅当没有数据流时才执行超时逻辑 + let list: any = obj.messageList; + list[list.length - 1] = { + ...list[list.length - 1], + content: "请求超时,请稍后重试!", + loading: false, + loadingContent: null, + }; + obj.messageList = list; + resolve({}); + } + }, 60000); + }); + let resText: any = await Promise.race([ + new Promise(async (resolve) => { + try { + // 判断数据流是否继续 + let isStreaming: boolean = true; + let modal = { + model: + obj.value === 1 + ? selectDeepseekVersion.value === 1 + ? "deepseek-chat" + : selectDeepseekVersion.value === 2 + ? "deepseek-reasoner" + : "" + : obj.value === 2 + ? selectDeepseekVersion.value === 1 + ? "deepseek-ai/DeepSeek-V3" + : selectDeepseekVersion.value === 2 + ? "deepseek-ai/DeepSeek-R1-Distill-Llama-70B" + : "" + : obj.value === 3 + ? selectDeepseekVersion.value === 1 + ? "deepseek-v3" + : selectDeepseekVersion.value === 2 + ? "deepseek-r1" + : "" + : obj.value === 4 + ? "qwen-plus" + : obj.value === 5 + ? 'claude-sonnet-4-5' + : '', + messages: [...oldMessage], + stream: true, + // max_tokens: 200000, + // max_tokens: obj.value === 5 ? 200000 : maxTokens.value, + // stop: ["null"], + // temperature: Temperature.value, + // top_p: TopP.value, + // top_k: TopK.value, + // frequency_penalty: FrequencyPenalty.value, + // n: 1, + // response_format: { + // type: "text", + // }, + }; + const options = { + method: "POST", + headers: { + Authorization: + obj.value === 1 + ? "Bearer sk-d47e0bdc7fd249f29d2f0dba807d46f0" + : obj.value === 2 + ? "Bearer sk-nynbgbtnmsffijgkttoimqkptetivviwuqrdhbuclgbmvnsq" + : obj.value === 3 + ? "Bearer sk-1aa2c1c672034c6d826ce62d3aebcb47" + : obj.value === 4 + ? "Bearer sk-1aa2c1c672034c6d826ce62d3aebcb47" + : obj.value === 5 + ? "Bearer sk-f67d5aae13e14efc8a01e8cd0e665d15" + : "", + "Content-Type": "application/json", + }, + body: JSON.stringify(modal), + signal: controller.signal, // 关键:绑定控制器信号 + }; + let geminiContent: any = [] + if (modal.messages && modal.messages.length > 0) { + modal.messages.forEach((item: any, index: number) => { + if (item.role === "user") { + if (index + 1 === modal.messages.length) { + geminiContent.push({ + parts: [ + { + text: item.content, + } + ] + }) + } + } + }) + } + // 判断是否成功 + let isSuccess: boolean = false; + const response: any = await fetch( + obj.value === 1 + ? "https://api.deepseek.com/v1/chat/completions" + : obj.value === 2 + ? "https://api.siliconflow.cn/v1/chat/completions" + : obj.value === 3 + ? "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" + : obj.value === 4 + ? "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" + : obj.value === 5 + ? "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent" + : "", + obj.value === 5 ? { + method: "POST", + headers: { + "Content-Type": "application/json", + "x-goog-api-key": "AIzaSyAg1lJ8oZL_jMAefrRswIhx5xA8JTOZUTs", + }, + body: JSON.stringify({ + contents: geminiContent + }), + } : options + ); + if (response.status === 200) { + isSuccess = true; + } + if (obj.value === 5) { + // 非流式返回 + // const data = await response.json(); + const reader = response.body.getReader(); + const decoder = new TextDecoder("utf-8"); + while (isStreaming) { + const { done, value } = await reader.read(); + if (done) break; + const chunk = decoder.decode(value); + let JSONChunk = trimFirstChar(chunk) + JSONChunk = JSONChunk ? JSON.parse(JSONChunk) : "" + handleStreamChunkIDGemini(JSONChunk ? [JSONChunk] : [], obj) + // 判断当前的这个框 是滚动数组里面的第几个 对他进行判断是不是在底部 + let nowShowList: any = []; + if (modalTypeDataList && modalTypeDataList.length > 0) { + modalTypeDataList.forEach((item: any) => { + if (item.isShow) { + nowShowList.push(item); + } + }); + } + let index: number = 99999; + let isBottom: any = "default"; + if (nowShowList && nowShowList.length > 0) { + nowShowList.forEach((item: any, itemIndex: number) => { + if (item.value === obj.value) { + index = itemIndex; + if (scrollList.value && scrollList.value.length > 0) { + isBottom = scrollList.value[itemIndex].isBottom; + } + } + }); + } + + if ( + index === 99999 || + isBottom === "default" || + isBottom === true + ) { + handleScrollToBottomID("gjldBox" + obj.value); + } + resolve(true) + } + } else { + // 创建流式读取器 + const reader = response.body.getReader(); + const decoder = new TextDecoder("utf-8"); + while (isStreaming) { + const { done, value } = await reader.read(); + if (done) break; + // 解码并处理数据 + const chunk = decoder.decode(value); + handleStreamChunkID(chunk, obj); + + // 判断当前的这个框 是滚动数组里面的第几个 对他进行判断是不是在底部 + let nowShowList: any = []; + if (modalTypeDataList && modalTypeDataList.length > 0) { + modalTypeDataList.forEach((item: any) => { + if (item.isShow) { + nowShowList.push(item); + } + }); + } + let index: number = 99999; + let isBottom: any = "default"; + if (nowShowList && nowShowList.length > 0) { + nowShowList.forEach((item: any, itemIndex: number) => { + if (item.value === obj.value) { + index = itemIndex; + if (scrollList.value && scrollList.value.length > 0) { + isBottom = scrollList.value[itemIndex].isBottom; + } + } + }); + } + + if ( + index === 99999 || + isBottom === "default" || + isBottom === true + ) { + handleScrollToBottomID("gjldBox" + obj.value); + } + + resolve(true); // 完成流处理后resolve + } + } + + // messageList.push({ + // role: "assistant", + // content: responseText.value, + // descResponseText: descResponseText.value, + // }); + obj.responseText = ""; + obj.descResponseText = ""; + showController.value = false; + // handleStop(); + return isSuccess; + } catch (error: any) { + if (error.name !== "AbortError") { + console.error("流式请求失败:", error); + } + } finally { + } + }).then((res) => { + hasStreamData = true; // 这里标记数据流出现了 + clearTimeout(timeoutId); // 取消超时逻辑 + }), + // handleAiDeepThinking(obj, oldMessage, controller).then((res) => { + // if (res) { + // hasStreamData = true; // 这里标记数据流出现了 + // clearTimeout(timeoutId); // 取消超时逻辑 + // } + // }), + timeoutPromise, + ]); + return resText; + } catch (error) { + // modalTypeDataList.forEach((item: any) => { + // if (item.isShow) { + // let list: any = item.messageList; + // list[list.length - 1] = { + // ...list[list.length - 1], + // content: "请求超时,请稍后重试!", + // loading: false, + // loadingContent: null, + // }; + // item.messageList = list; + // } + // }); + let list: any = obj.messageList; + list[list.length - 1] = { + ...list[list.length - 1], + content: "请求超时,请稍后重试!", + loading: false, + loadingContent: null, + }; + obj.messageList = list; + } } }; @@ -1997,6 +2208,38 @@ const handleStreamChunkIDGemini = async (chunk: any, obj: any) => { }); }; +// 自己封装的 gemini 的流式返回 +const handleStreamChunkIDGeminiNew = async (chunk: any, obj: any) => { + if (!(chunk && chunk.length > 0)) { + return + } + + chunk.forEach((line: any) => { + try { + // const parsed = JSON.parse(line); + const parsed = line; + if (parsed.text) { + obj.responseText += parsed.text + } + if (parsed.session_id) { + thisSessionId.value = parsed.session_id + } + obj.messageList[obj.messageList.length - 1] = { + ...obj.messageList[obj.messageList.length - 1], + content: marked(obj.responseText), + realContent: obj.responseText, + loading: false, + loadingContent: null, + index: + obj.messageList && obj.messageList.length > 0 + ? obj.messageList.length + : 0, + }; + } catch (err) { + } + }); +}; + // 拿到云南大屏的数据 const handleGetYNMapData = async () => { let obj: any = { @@ -2350,6 +2593,7 @@ watch( // 点击深度分析 const handleDepthAnalysis = async (bigObj: any, obj: any) => { + console.log('bigObjbigObjbigObj', bigObj); handleOnceMoreModal([bigObj.value]); }; @@ -2660,6 +2904,7 @@ const handleNewRuleList = async () => { const data = await handleGetANALYSISRULEList({ searchParameter: { ANALYSISRULE_IDS: "", + RULE_SOURCE: pythonSemantics.value ? 3000 : '', current: 1, pageSize: 10, }, @@ -2736,6 +2981,10 @@ const handleCopyContent = (bigObj: any) => { } }; +const handleChangePython = (e: any) => { + pythonSemantics.value = !pythonSemantics.value; +} + // 改变工作模式的方法 const handleChangeProcess = (e: any) => { modalTypeDataList.forEach((item: any) => { @@ -2852,6 +3101,35 @@ const handleChangeProcess = (e: any) => { +
+
+
+ 专家模式 +
+ +
+
+ +
+
+
+ 模型选择 +
+ + + +
+
+ +
+
+
+ 知识库编码 +
+ +
+
+
@@ -2863,7 +3141,7 @@ const handleChangeProcess = (e: any) => {
-
+
Max Tokens @@ -2879,7 +3157,7 @@ const handleChangeProcess = (e: any) => {
-
+
Temperature @@ -2894,7 +3172,7 @@ const handleChangeProcess = (e: any) => {
-
+
Top-P @@ -2909,7 +3187,7 @@ const handleChangeProcess = (e: any) => {
-
+
Top-K @@ -2924,7 +3202,7 @@ const handleChangeProcess = (e: any) => {
-
+
Frequency Penalty diff --git a/src/components/service.ts b/src/components/service.ts index 35e2ed5..4318f9c 100644 --- a/src/components/service.ts +++ b/src/components/service.ts @@ -1,4 +1,5 @@ import request from "../request/request"; +import requestPython from '../request/requestPython' export async function GetProjectSplitSummary(params: any) { const data: any = await request.get('/BusinessProject/GetMonthSummaryList', params) @@ -14,4 +15,21 @@ export async function GetProjectSplitSummary(params: any) { } return data.Result_Data; +} + +// 测试AI回复 +export async function handleGetGeminiResult(params: any) { + const data: any = await requestPython.post('gemini/query/', params) + + if (data.Result_Code !== 100) { + return { + data: [], + current: 1, + pageSize: 20, + total: 0, + success: true, + }; + } + + return data } \ No newline at end of file diff --git a/src/request/requestPython.ts b/src/request/requestPython.ts new file mode 100644 index 0000000..39d5ab2 --- /dev/null +++ b/src/request/requestPython.ts @@ -0,0 +1,80 @@ +import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; +// import { notification } from 'antd'; +// import Cookies from 'js-cookie'; +import moment from 'moment'; + +// 定义 HTTP 状态码及其描述 +const codeMessage: Record = { + 200: '服务器成功返回请求的数据。', + 201: '新建或修改数据成功。', + 202: '一个请求已经进入后台排队(异步任务)。', + 204: '删除数据成功。', + 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。', + 401: '用户没有权限(令牌、用户名、密码错误)。', + 403: '用户得到授权,但是访问是被禁止的。', + 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。', + 406: '请求的格式不可得。', + 410: '请求的资源被永久删除,且不会再得到的。', + 422: '当创建一个对象时,发生一个验证错误。', + 500: '服务器发生错误,请检查服务器。', + 502: '网关错误。', + 503: '服务不可用,服务器暂时过载或维护。', + 504: '网关超时。', +}; + +// 错误处理 +const errorHandler = (error: any): any => { + const { response } = error; + if (response && response.status) { + const errorText = codeMessage[response.status] || response.statusText; + const { status, url } = response; + // notification.error({ + // message: `请求错误 ${status}: ${url}`, + // description: errorText, + // }); + } else { + // notification.error({ + // description: '您的网络异常,无法连接到服务器。', + // message: '网络异常', + // }); + } + return Promise.reject(error); +}; + +// 创建 axios 实例 +const instance = axios.create({ + baseURL: 'http://192.168.1.207:8002/api/', // 默认请求前缀 + timeout: 60000, // 请求超时时间 + headers: { + "provincecode": "340000", + 'Content-Type': 'application/json', + }, +}); + +// 请求拦截器 +instance.interceptors.request.use( + (config: any) => { + return config; + }, + errorHandler +); + +// 响应拦截器 +instance.interceptors.response.use( + (response: AxiosResponse) => { + // 每次响应,设置一个 tmp 的 Cookie + // Cookies.set('tmp', moment().format()); + return response.data; // 统一返回 data + }, + errorHandler +); + +// 封装的请求方法 +const request = { + get: (url: string, params?: any) => instance.get(url, { params }), + post: (url: string, data?: any) => instance.post(url, data), + put: (url: string, data?: any) => instance.put(url, data), + delete: (url: string, params?: any) => instance.delete(url, { params }), +}; + +export default request;