可信代码库-AI大模型接口改造
This commit is contained in:
@@ -52,7 +52,6 @@ onMounted(() => {
|
||||
const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST;
|
||||
// 猜你想问接口
|
||||
const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||
debugger
|
||||
try {
|
||||
// 构造请求参数(需根据实际文档补充 df_id 和 sql_id,示例中使用空字符串占位)
|
||||
const params = {
|
||||
@@ -64,10 +63,9 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||
// `${VITE_AI_API_HOST}/api/v0/update_recommend_questions`,
|
||||
// params
|
||||
// );
|
||||
const response = await fetchUpdateRecommendQuestions(params);
|
||||
const createRes = response.data;
|
||||
if (createRes&&createRes.questions) {
|
||||
questions.value = createRes.questions
|
||||
const { data } = await fetchUpdateRecommendQuestions(params);
|
||||
if(data.code===200) {
|
||||
questions.value = data.data
|
||||
} else {
|
||||
// Message.error('创建会话失败,未获取到会话ID');
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ const getQuestionHistory = async () => {
|
||||
"search": searchText.value
|
||||
});
|
||||
|
||||
if (data.data.conversationList) {
|
||||
if (data.code===200) {
|
||||
dhlsList.value = data.data.conversationList;
|
||||
dhlsPagination.value.total = data.data.pagination.total || 0;
|
||||
}
|
||||
@@ -250,7 +250,7 @@ const getQuestionCollection = async () => {
|
||||
"search": searchText.value
|
||||
});
|
||||
|
||||
if (data.data.conversationList) {
|
||||
if (data.code===200) {
|
||||
collectionList.value = data.data.conversationList;
|
||||
collectionPagination.value.total = data.data.pagination.total || 0;
|
||||
}
|
||||
@@ -377,7 +377,6 @@ const toggleCollect = async (conversationIds) => {
|
||||
userId: props.username,
|
||||
conversationIdList: conversationIds
|
||||
});
|
||||
|
||||
if (res.data.code === 200||res.data.code === 20000) {
|
||||
Message.success(res.data.message || '取消收藏成功');
|
||||
// 刷新当前标签页的数据
|
||||
|
||||
@@ -440,8 +440,8 @@ const getQuestionHistory = async () => {
|
||||
"search": searchText.value
|
||||
});
|
||||
debugger
|
||||
if(data.conversationList) {
|
||||
dhlsList.value = data.conversationList
|
||||
if(data.code===200) {
|
||||
dhlsList.value = data.data
|
||||
} else {
|
||||
// Message.error(data.error||'接口异常!')
|
||||
}
|
||||
@@ -467,8 +467,8 @@ const getQuestionCollection = async () => {
|
||||
"size": page.value.size,
|
||||
"search": searchText.value
|
||||
});
|
||||
if(data.conversationList) {
|
||||
collectionList.value = data.conversationList
|
||||
if(data.code===200) {
|
||||
collectionList.value = data.data
|
||||
} else {
|
||||
// Message.error(data.error||'接口异常!')
|
||||
}
|
||||
|
||||
@@ -351,14 +351,14 @@ const getAIAnswer = async (content) => {
|
||||
// conversationId: CONV_ID.value,
|
||||
// question: content,
|
||||
// });
|
||||
const response = await fetchChatUseSql({
|
||||
const {data} = await fetchChatUseSql({
|
||||
userId: username, // 使用 username 作为 userId
|
||||
conversationId: CONV_ID.value,
|
||||
question: content,
|
||||
});
|
||||
|
||||
if(data.code===200) {
|
||||
debugger
|
||||
const row = response.data
|
||||
const row = data.data
|
||||
if(row.type) {
|
||||
const {text,type,id,table_name=[], states={}} = row;
|
||||
messages.value[messages.value.length - 1].id = id;
|
||||
@@ -416,6 +416,7 @@ const getAIAnswer = async (content) => {
|
||||
// });
|
||||
// }
|
||||
// }, 1000);
|
||||
}
|
||||
} else {
|
||||
// Message.error('请先创建会话!');
|
||||
}
|
||||
@@ -470,14 +471,11 @@ const createConversation = async () => {
|
||||
// const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, {
|
||||
// userId: username,
|
||||
// });
|
||||
const response = await fetchCreateConversation({
|
||||
const {data} = await fetchCreateConversation({
|
||||
userId: username,
|
||||
});
|
||||
const createRes = response.data;
|
||||
debugger
|
||||
if (createRes&&createRes.conversationId) {
|
||||
debugger
|
||||
CONV_ID.value = createRes.conversationId;
|
||||
if(data.code===200) {
|
||||
CONV_ID.value = data.data.conversationId;
|
||||
console.log('创建会话成功,会话ID:', CONV_ID.value);
|
||||
nextTick(() => {
|
||||
// 刷新会话列表
|
||||
@@ -506,13 +504,17 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||
// `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
||||
// params
|
||||
// );
|
||||
const response = await FetchFollowupQuestions(params);
|
||||
const createRes = response.data;
|
||||
const {data} = await FetchFollowupQuestions(params);
|
||||
if(data.code===200) {
|
||||
const createRes = data.data;
|
||||
if (createRes&&createRes.questions) {
|
||||
followupQuestions.value = createRes.questions
|
||||
} else {
|
||||
// Message.error('创建会话失败,未获取到会话ID');
|
||||
}
|
||||
} else {
|
||||
// Message.error('创建会话失败,未获取到会话ID');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询相关问题失败:', error);
|
||||
// Message.error('创建会话失败,请重试');
|
||||
@@ -558,10 +560,11 @@ const getConversationDetail = async (convId: string) => {
|
||||
userId: username,
|
||||
conversationId: convId,
|
||||
});
|
||||
if(response.data?.error) {
|
||||
debugger
|
||||
if(response.data.code!==200) {
|
||||
// Message.error(response.data?.error);
|
||||
} else {
|
||||
const detail = response.data.messages;
|
||||
const detail = response.data.data;
|
||||
// 处理详情数据(如回显消息列表)
|
||||
handleDetailResponse(detail);
|
||||
}
|
||||
@@ -582,7 +585,7 @@ const handleDetailResponse = (detail: any) => {
|
||||
let type = i.type;
|
||||
let table_name = i.table_name;
|
||||
if(type==='text') {
|
||||
messages.content = i.text;
|
||||
messages.content = i.text || i.content;
|
||||
messages.loading = false;
|
||||
messages.type = 'text';
|
||||
} else if(type==='df') {
|
||||
|
||||
Reference in New Issue
Block a user