可信代码库-AI大模型接口改造
This commit is contained in:
@@ -52,7 +52,6 @@ onMounted(() => {
|
|||||||
const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST;
|
const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST;
|
||||||
// 猜你想问接口
|
// 猜你想问接口
|
||||||
const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||||
debugger
|
|
||||||
try {
|
try {
|
||||||
// 构造请求参数(需根据实际文档补充 df_id 和 sql_id,示例中使用空字符串占位)
|
// 构造请求参数(需根据实际文档补充 df_id 和 sql_id,示例中使用空字符串占位)
|
||||||
const params = {
|
const params = {
|
||||||
@@ -64,10 +63,9 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
|||||||
// `${VITE_AI_API_HOST}/api/v0/update_recommend_questions`,
|
// `${VITE_AI_API_HOST}/api/v0/update_recommend_questions`,
|
||||||
// params
|
// params
|
||||||
// );
|
// );
|
||||||
const response = await fetchUpdateRecommendQuestions(params);
|
const { data } = await fetchUpdateRecommendQuestions(params);
|
||||||
const createRes = response.data;
|
if(data.code===200) {
|
||||||
if (createRes&&createRes.questions) {
|
questions.value = data.data
|
||||||
questions.value = createRes.questions
|
|
||||||
} else {
|
} else {
|
||||||
// Message.error('创建会话失败,未获取到会话ID');
|
// Message.error('创建会话失败,未获取到会话ID');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ const getQuestionHistory = async () => {
|
|||||||
"search": searchText.value
|
"search": searchText.value
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.data.conversationList) {
|
if (data.code===200) {
|
||||||
dhlsList.value = data.data.conversationList;
|
dhlsList.value = data.data.conversationList;
|
||||||
dhlsPagination.value.total = data.data.pagination.total || 0;
|
dhlsPagination.value.total = data.data.pagination.total || 0;
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ const getQuestionCollection = async () => {
|
|||||||
"search": searchText.value
|
"search": searchText.value
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.data.conversationList) {
|
if (data.code===200) {
|
||||||
collectionList.value = data.data.conversationList;
|
collectionList.value = data.data.conversationList;
|
||||||
collectionPagination.value.total = data.data.pagination.total || 0;
|
collectionPagination.value.total = data.data.pagination.total || 0;
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,6 @@ const toggleCollect = async (conversationIds) => {
|
|||||||
userId: props.username,
|
userId: props.username,
|
||||||
conversationIdList: conversationIds
|
conversationIdList: conversationIds
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.data.code === 200||res.data.code === 20000) {
|
if (res.data.code === 200||res.data.code === 20000) {
|
||||||
Message.success(res.data.message || '取消收藏成功');
|
Message.success(res.data.message || '取消收藏成功');
|
||||||
// 刷新当前标签页的数据
|
// 刷新当前标签页的数据
|
||||||
|
|||||||
@@ -440,8 +440,8 @@ const getQuestionHistory = async () => {
|
|||||||
"search": searchText.value
|
"search": searchText.value
|
||||||
});
|
});
|
||||||
debugger
|
debugger
|
||||||
if(data.conversationList) {
|
if(data.code===200) {
|
||||||
dhlsList.value = data.conversationList
|
dhlsList.value = data.data
|
||||||
} else {
|
} else {
|
||||||
// Message.error(data.error||'接口异常!')
|
// Message.error(data.error||'接口异常!')
|
||||||
}
|
}
|
||||||
@@ -467,8 +467,8 @@ const getQuestionCollection = async () => {
|
|||||||
"size": page.value.size,
|
"size": page.value.size,
|
||||||
"search": searchText.value
|
"search": searchText.value
|
||||||
});
|
});
|
||||||
if(data.conversationList) {
|
if(data.code===200) {
|
||||||
collectionList.value = data.conversationList
|
collectionList.value = data.data
|
||||||
} else {
|
} else {
|
||||||
// Message.error(data.error||'接口异常!')
|
// Message.error(data.error||'接口异常!')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,71 +351,72 @@ const getAIAnswer = async (content) => {
|
|||||||
// conversationId: CONV_ID.value,
|
// conversationId: CONV_ID.value,
|
||||||
// question: content,
|
// question: content,
|
||||||
// });
|
// });
|
||||||
const response = await fetchChatUseSql({
|
const {data} = await fetchChatUseSql({
|
||||||
userId: username, // 使用 username 作为 userId
|
userId: username, // 使用 username 作为 userId
|
||||||
conversationId: CONV_ID.value,
|
conversationId: CONV_ID.value,
|
||||||
question: content,
|
question: content,
|
||||||
});
|
});
|
||||||
|
if(data.code===200) {
|
||||||
|
debugger
|
||||||
|
const row = data.data
|
||||||
|
if(row.type) {
|
||||||
|
const {text,type,id,table_name=[], states={}} = row;
|
||||||
|
messages.value[messages.value.length - 1].id = id;
|
||||||
|
// 处理思考过程
|
||||||
|
const { thinkProcess,steps } = processThinkStates(states);
|
||||||
|
messages.value[messages.value.length - 1].thinkProcess = thinkProcess;
|
||||||
|
messages.value[messages.value.length - 1].steps = steps;
|
||||||
|
messages.value[messages.value.length - 1].thinkExpanded = true;
|
||||||
|
|
||||||
debugger
|
if(type==='text') {
|
||||||
const row = response.data
|
messages.value[messages.value.length - 1].content = text;
|
||||||
if(row.type) {
|
messages.value[messages.value.length - 1].loading = false;
|
||||||
const {text,type,id,table_name=[], states={}} = row;
|
messages.value[messages.value.length - 1].type = 'text';
|
||||||
messages.value[messages.value.length - 1].id = id;
|
} else if(type==='df') {
|
||||||
// 处理思考过程
|
messages.value[messages.value.length - 1].content = row[type];
|
||||||
const { thinkProcess,steps } = processThinkStates(states);
|
messages.value[messages.value.length - 1].loading = false;
|
||||||
messages.value[messages.value.length - 1].thinkProcess = thinkProcess;
|
messages.value[messages.value.length - 1].type = 'df';
|
||||||
messages.value[messages.value.length - 1].steps = steps;
|
|
||||||
messages.value[messages.value.length - 1].thinkExpanded = true;
|
|
||||||
|
|
||||||
if(type==='text') {
|
// 判断是否软件详情
|
||||||
messages.value[messages.value.length - 1].content = text;
|
if(table_name.length===1&&table_name[0]==='critical_software_info') {
|
||||||
messages.value[messages.value.length - 1].loading = false;
|
let arr = JSON.parse(row[type]);
|
||||||
messages.value[messages.value.length - 1].type = 'text';
|
if(arr&&arr.length===1) {
|
||||||
} else if(type==='df') {
|
messages.value[messages.value.length - 1].type = 'critical_software_info';
|
||||||
messages.value[messages.value.length - 1].content = row[type];
|
messages.value[messages.value.length - 1].id = arr[0]?.id || arr[0]?.ID;
|
||||||
messages.value[messages.value.length - 1].loading = false;
|
messages.value[messages.value.length - 1].software_name = arr[0]?.software_name || arr[0]['软件名称'];
|
||||||
messages.value[messages.value.length - 1].type = 'df';
|
}
|
||||||
|
|
||||||
// 判断是否软件详情
|
|
||||||
if(table_name.length===1&&table_name[0]==='critical_software_info') {
|
|
||||||
let arr = JSON.parse(row[type]);
|
|
||||||
if(arr&&arr.length===1) {
|
|
||||||
messages.value[messages.value.length - 1].type = 'critical_software_info';
|
|
||||||
messages.value[messages.value.length - 1].id = arr[0]?.id || arr[0]?.ID;
|
|
||||||
messages.value[messages.value.length - 1].software_name = arr[0]?.software_name || arr[0]['软件名称'];
|
|
||||||
}
|
}
|
||||||
|
} else if(type==='sql_error') {
|
||||||
|
messages.value[messages.value.length - 1].content = row.error;
|
||||||
|
messages.value[messages.value.length - 1].loading = false;
|
||||||
|
messages.value[messages.value.length - 1].type = 'error';
|
||||||
}
|
}
|
||||||
} else if(type==='sql_error') {
|
fetchFollowupQuestions(content,id)
|
||||||
messages.value[messages.value.length - 1].content = row.error;
|
} else {
|
||||||
messages.value[messages.value.length - 1].loading = false;
|
Message.warning('接口异常!')
|
||||||
messages.value[messages.value.length - 1].type = 'error';
|
|
||||||
}
|
}
|
||||||
fetchFollowupQuestions(content,id)
|
// messages.value.push({
|
||||||
} else {
|
// from: 'ai-model',
|
||||||
Message.warning('接口异常!')
|
// content: '',
|
||||||
}
|
// avatarPosition: 'side-left',
|
||||||
// messages.value.push({
|
// avatarConfig: { ...aiModelAvatar },
|
||||||
// from: 'ai-model',
|
// loading: true,
|
||||||
// content: '',
|
// });
|
||||||
// avatarPosition: 'side-left',
|
|
||||||
// avatarConfig: { ...aiModelAvatar },
|
|
||||||
// loading: true,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// /* 模拟流式数据返回 */
|
// /* 模拟流式数据返回 */
|
||||||
// setTimeout(async () => {
|
// setTimeout(async () => {
|
||||||
// messages.value.at(-1).loading = false;
|
// messages.value.at(-1).loading = false;
|
||||||
// for (let i = 0; i < content.length;) {
|
// for (let i = 0; i < content.length;) {
|
||||||
// await new Promise(r => setTimeout(r, 300 * Math.random()));
|
// await new Promise(r => setTimeout(r, 300 * Math.random()));
|
||||||
// messages.value[messages.value.length - 1].content = content.slice(0, i += Math.random() * 10);
|
// messages.value[messages.value.length - 1].content = content.slice(0, i += Math.random() * 10);
|
||||||
// nextTick(() => {
|
// nextTick(() => {
|
||||||
// conversationRef.value?.scrollTo({
|
// conversationRef.value?.scrollTo({
|
||||||
// top: conversationRef.value.scrollHeight
|
// top: conversationRef.value.scrollHeight
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
// }, 1000);
|
// }, 1000);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Message.error('请先创建会话!');
|
// Message.error('请先创建会话!');
|
||||||
}
|
}
|
||||||
@@ -470,19 +471,16 @@ const createConversation = async () => {
|
|||||||
// const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, {
|
// const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, {
|
||||||
// userId: username,
|
// userId: username,
|
||||||
// });
|
// });
|
||||||
const response = await fetchCreateConversation({
|
const {data} = await fetchCreateConversation({
|
||||||
userId: username,
|
userId: username,
|
||||||
});
|
});
|
||||||
const createRes = response.data;
|
if(data.code===200) {
|
||||||
debugger
|
CONV_ID.value = data.data.conversationId;
|
||||||
if (createRes&&createRes.conversationId) {
|
|
||||||
debugger
|
|
||||||
CONV_ID.value = createRes.conversationId;
|
|
||||||
console.log('创建会话成功,会话ID:', CONV_ID.value);
|
console.log('创建会话成功,会话ID:', CONV_ID.value);
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
// 刷新会话列表
|
// 刷新会话列表
|
||||||
if (viewHistoryRef.value) {
|
if (viewHistoryRef.value) {
|
||||||
viewHistoryRef.value.getQuestionHistory(); // 调用子组件方法
|
viewHistoryRef.value.getQuestionHistory(); // 调用子组件方法
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -506,10 +504,14 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
|||||||
// `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
// `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
||||||
// params
|
// params
|
||||||
// );
|
// );
|
||||||
const response = await FetchFollowupQuestions(params);
|
const {data} = await FetchFollowupQuestions(params);
|
||||||
const createRes = response.data;
|
if(data.code===200) {
|
||||||
if (createRes&&createRes.questions) {
|
const createRes = data.data;
|
||||||
followupQuestions.value = createRes.questions
|
if (createRes&&createRes.questions) {
|
||||||
|
followupQuestions.value = createRes.questions
|
||||||
|
} else {
|
||||||
|
// Message.error('创建会话失败,未获取到会话ID');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Message.error('创建会话失败,未获取到会话ID');
|
// Message.error('创建会话失败,未获取到会话ID');
|
||||||
}
|
}
|
||||||
@@ -558,10 +560,11 @@ const getConversationDetail = async (convId: string) => {
|
|||||||
userId: username,
|
userId: username,
|
||||||
conversationId: convId,
|
conversationId: convId,
|
||||||
});
|
});
|
||||||
if(response.data?.error) {
|
debugger
|
||||||
|
if(response.data.code!==200) {
|
||||||
// Message.error(response.data?.error);
|
// Message.error(response.data?.error);
|
||||||
} else {
|
} else {
|
||||||
const detail = response.data.messages;
|
const detail = response.data.data;
|
||||||
// 处理详情数据(如回显消息列表)
|
// 处理详情数据(如回显消息列表)
|
||||||
handleDetailResponse(detail);
|
handleDetailResponse(detail);
|
||||||
}
|
}
|
||||||
@@ -582,7 +585,7 @@ const handleDetailResponse = (detail: any) => {
|
|||||||
let type = i.type;
|
let type = i.type;
|
||||||
let table_name = i.table_name;
|
let table_name = i.table_name;
|
||||||
if(type==='text') {
|
if(type==='text') {
|
||||||
messages.content = i.text;
|
messages.content = i.text || i.content;
|
||||||
messages.loading = false;
|
messages.loading = false;
|
||||||
messages.type = 'text';
|
messages.type = 'text';
|
||||||
} else if(type==='df') {
|
} else if(type==='df') {
|
||||||
|
|||||||
Reference in New Issue
Block a user