修复spark制作选择文件问题,修改通用交互中文件及图片理解
This commit is contained in:
parent
c7fe1367d0
commit
3cb9ec046b
|
|
@ -3,7 +3,7 @@ import router from "@/router/index.js";
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
//const baseURL = "https://gep.ljsea.top/";
|
//const baseURL = "https://gep.ljsea.top/";
|
||||||
const baseURL = "https://pm.ljsea.top/";
|
const baseURL = "https://pm.ljsea.top/";
|
||||||
//const baseURL= "http://localhost:8083";
|
//const baseURL= "http://localhost:8084";
|
||||||
//const baseURL="https://pm.ljsea.top";
|
//const baseURL="https://pm.ljsea.top";
|
||||||
//const baseURL = "https://gep.ljsea.xyz/";
|
//const baseURL = "https://gep.ljsea.xyz/";
|
||||||
const request = axios.create({
|
const request = axios.create({
|
||||||
|
|
|
||||||
|
|
@ -256,12 +256,12 @@ export const dashOpt1 = {
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
smooth: true,
|
smooth: true,
|
||||||
data: [120, 132, 301, 134, 90, 230, 210],
|
data: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'line',
|
type: 'line',
|
||||||
smooth: true,
|
smooth: true,
|
||||||
data: [220, 122, 191, 234, 190, 130, 310],
|
data: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
@ -282,13 +282,7 @@ export const dashOpt2 = {
|
||||||
borderColor: '#fff',
|
borderColor: '#fff',
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
},
|
},
|
||||||
data: [
|
data: [],
|
||||||
{ value: 1048, name: '数码' },
|
|
||||||
{ value: 735, name: '食品' },
|
|
||||||
{ value: 580, name: '母婴' },
|
|
||||||
{ value: 484, name: '家电' },
|
|
||||||
{ value: 300, name: '运动' },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ const getDashBoardStatistics = async () => {
|
||||||
};
|
};
|
||||||
let result = await GetDashBoardStatisticsService(req);
|
let result = await GetDashBoardStatisticsService(req);
|
||||||
if (result['code'] === 0) {
|
if (result['code'] === 0) {
|
||||||
console.log('dashboard:', result['data']);
|
// console.log('dashboard:', result['data']);
|
||||||
baseInfo.value = result['data']["dashboard_statistics_st"];
|
baseInfo.value = result['data']["dashboard_statistics_st"];
|
||||||
dashOpt2_.series[0].data = result['data']["dashboard_statistics_model_st"];
|
dashOpt2_.series[0].data = result['data']["dashboard_statistics_model_st"];
|
||||||
let max_model = Math.max(...result['data']["dashboard_statistics_model_st"].map((item: any) => item.value));
|
let max_model = Math.max(...result['data']["dashboard_statistics_model_st"].map((item: any) => item.value));
|
||||||
|
|
@ -210,7 +210,7 @@ const getDashBoardStatistics = async () => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
ranks.value.sort((a, b) => b.value - a.value);
|
ranks.value.sort((a, b) => b.value - a.value);
|
||||||
console.log('ranks:', ranks.value);
|
//console.log('ranks:', ranks.value);
|
||||||
// 处理数据
|
// 处理数据
|
||||||
//过去一周会话、消息数
|
//过去一周会话、消息数
|
||||||
let sessionData = result['data']["dashboard_statistics_week"]["session_count"];
|
let sessionData = result['data']["dashboard_statistics_week"]["session_count"];
|
||||||
|
|
|
||||||
|
|
@ -650,14 +650,15 @@ const CreateSparkPPTOutline = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateSparkPPT = async () => {
|
const CreateSparkPPT = async () => {
|
||||||
|
console.log("CreateSparkPPT:", selectedFile.value);
|
||||||
let req = {
|
let req = {
|
||||||
token: localStorage.getItem('token'),
|
token: localStorage.getItem('token'),
|
||||||
function: "spark-create-ppt",
|
function: "spark-create-ppt",
|
||||||
sessionId: sessionID.value,
|
sessionId: sessionID.value,
|
||||||
outline: createOutlineResp.value.data.outline,
|
outline: createOutlineResp.value.data.outline,
|
||||||
query: "生成PPT",
|
query: "生成PPT",
|
||||||
fileUrl: fileUrl + selectedFiles.value[0].file_store_name,
|
fileUrl: fileUrl + selectedFile.value.file_store_name,
|
||||||
fileName: selectedFiles.value[0].UserFileName,
|
fileName: selectedFile.value.UserFileName,
|
||||||
}
|
}
|
||||||
let result = await CreateSparkPPTService(req);
|
let result = await CreateSparkPPTService(req);
|
||||||
let msg1 :MessageOutline = { role: "user", content: `[${req.fileName}](${req.fileUrl})` + "\n"+ req.query, finished: true, isOutline: true,outline: req.outline }
|
let msg1 :MessageOutline = { role: "user", content: `[${req.fileName}](${req.fileUrl})` + "\n"+ req.query, finished: true, isOutline: true,outline: req.outline }
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,15 @@ interface ImageMessage {
|
||||||
image_content: SendImageMessage[];
|
image_content: SendImageMessage[];
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
interface FileMessage {
|
||||||
|
file_content: File; //文件内容,文件内容的base64编码
|
||||||
|
file_type: string | null; //文件类型,文本类型,图片类型等,text_file,img_file等
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GenerationMessage {
|
||||||
|
text: string;
|
||||||
|
file_content: FileMessage[];
|
||||||
|
}
|
||||||
|
|
||||||
const md = new MarkdownIt();
|
const md = new MarkdownIt();
|
||||||
md.use(markdownItHighlightjs, {
|
md.use(markdownItHighlightjs, {
|
||||||
|
|
@ -392,6 +401,9 @@ onMounted(() => {
|
||||||
"wss://pm.ljsea.top/im/ai_chat_ws?" +
|
"wss://pm.ljsea.top/im/ai_chat_ws?" +
|
||||||
"token=" +
|
"token=" +
|
||||||
localStorage.getItem("token");
|
localStorage.getItem("token");
|
||||||
|
//获取模型列表
|
||||||
|
let test_url = "ws://127.0.0.1:8084/im/ai_chat_ws?" + "token=" + localStorage.getItem("token");
|
||||||
|
//url =test_url;
|
||||||
socket.value = new WebSocket(url);
|
socket.value = new WebSocket(url);
|
||||||
socket.value.onopen = () => {
|
socket.value.onopen = () => {
|
||||||
console.log("WebSocket 连接已建立");
|
console.log("WebSocket 连接已建立");
|
||||||
|
|
@ -450,6 +462,8 @@ onUnmounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const sendMessage = () => {
|
const sendMessage = () => {
|
||||||
|
sendMessageWithFile()
|
||||||
|
return;
|
||||||
if (inputMessage.value.trim() === "") {
|
if (inputMessage.value.trim() === "") {
|
||||||
ElMessage.warning("消息不能为空");
|
ElMessage.warning("消息不能为空");
|
||||||
return;
|
return;
|
||||||
|
|
@ -512,6 +526,92 @@ const sendMessage = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const sendMessageWithFile = () => {
|
||||||
|
if (inputMessage.value.trim() === "") {
|
||||||
|
ElMessage.warning("消息不能为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let end_msg = {
|
||||||
|
msg: inputMessage.value,
|
||||||
|
type: "ollama",
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
console.log("end_msg:", end_msg);
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket.value.send(JSON.stringify(end_msg));
|
||||||
|
console.log("send msg:", end_msg);
|
||||||
|
} catch (e) {
|
||||||
|
ElMessage.error("发送失败!连接已断开!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sessionID.value == 0) {
|
||||||
|
sessionName.value = inputMessage.value;
|
||||||
|
}
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// let img_content= img_msg.image_content
|
||||||
|
// for (let i = 0; i < img_content.length; i++) {
|
||||||
|
// pMsgContent += `![${img_content[i].img_name}](${img_content[i].img_url})` + "\n";
|
||||||
|
// }
|
||||||
|
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 loadSession = async (session_id: number) => {
|
const loadSession = async (session_id: number) => {
|
||||||
sessionID.value = session_id;
|
sessionID.value = session_id;
|
||||||
messages.length = 0; // 清空消息
|
messages.length = 0; // 清空消息
|
||||||
|
|
@ -549,6 +649,58 @@ const getShortenedName = (name: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMessage = async (session_id: number) => {
|
const getMessage = async (session_id: number) => {
|
||||||
|
let result = {};
|
||||||
|
try {
|
||||||
|
let req = {
|
||||||
|
token: localStorage.getItem("token"),
|
||||||
|
session_id: session_id,
|
||||||
|
};
|
||||||
|
result = await GetMessageService(req);
|
||||||
|
if (result["code"] === 0) {
|
||||||
|
console.log(result["data"]);
|
||||||
|
let data = result["data"];
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
if (data[i]["Type"] === 3) {
|
||||||
|
let msg: GenMessage = data[i];
|
||||||
|
let pMsgContent="";
|
||||||
|
if (msg.Status == 3) {
|
||||||
|
let file_msg: GenerationMessage = JSON.parse(msg.Msg);
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pMsgContent = pMsgContent + file_msg.text;
|
||||||
|
} 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) => {
|
||||||
let result = {};
|
let result = {};
|
||||||
try {
|
try {
|
||||||
let req = {
|
let req = {
|
||||||
|
|
@ -595,6 +747,8 @@ const getMessage = async (session_id: number) => {
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const copyMessage = (content: string) => {
|
const copyMessage = (content: string) => {
|
||||||
navigator.clipboard
|
navigator.clipboard
|
||||||
.writeText(content)
|
.writeText(content)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import TableSearch from '@/components/table-search.vue';
|
||||||
import UploadFile from '@/components/upload-file.vue';
|
import UploadFile from '@/components/upload-file.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
|
||||||
const userRole = localStorage.getItem('role') == 'admin';
|
const userRole = ref(localStorage.getItem('role') == 'admin');
|
||||||
const page = reactive({
|
const page = reactive({
|
||||||
index: 1,
|
index: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import TableDetail from '@/components/table-detail.vue';
|
||||||
import TableSearch from '@/components/table-search.vue';
|
import TableSearch from '@/components/table-search.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
|
||||||
const userRole = localStorage.getItem('role') == 'admin';
|
const userRole = ref(localStorage.getItem('role') == 'admin');
|
||||||
|
|
||||||
// 查询相关
|
// 查询相关
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import { ElMessage } from 'element-plus';
|
||||||
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
||||||
import { UserInfo } from '@/types/user';
|
import { UserInfo } from '@/types/user';
|
||||||
import { Model } from '@/types/model';
|
import { Model } from '@/types/model';
|
||||||
import { fetchUserData } from '@/api';
|
|
||||||
import {FindModelService} from "@/api/model";
|
import {FindModelService} from "@/api/model";
|
||||||
import {UpdateModelService} from "@/api/model";
|
import {UpdateModelService} from "@/api/model";
|
||||||
import {AddModelService} from "@/api/model";
|
import {AddModelService} from "@/api/model";
|
||||||
|
|
@ -39,9 +38,8 @@ import TableCustom from '@/components/table-custom.vue';
|
||||||
import TableDetail from '@/components/table-detail.vue';
|
import TableDetail from '@/components/table-detail.vue';
|
||||||
import TableSearch from '@/components/table-search.vue';
|
import TableSearch from '@/components/table-search.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
import { number } from 'echarts';
|
|
||||||
|
|
||||||
const userRole = localStorage.getItem('role') == 'admin';
|
const userRole = ref(localStorage.getItem('role') == 'admin');
|
||||||
|
|
||||||
// 查询相关
|
// 查询相关
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ import TableDetail from '@/components/table-detail.vue';
|
||||||
import TableSearch from '@/components/table-search.vue';
|
import TableSearch from '@/components/table-search.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
|
||||||
const userRole = localStorage.getItem('role') == 'admin';
|
// const userRole = localStorage.getItem('role') == 'admin';
|
||||||
|
const userRole = ref(localStorage.getItem('role') == 'admin');
|
||||||
const page = reactive({
|
const page = reactive({
|
||||||
index: 1,
|
index: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue