可信代码库-AI大模型公网接口对接
This commit is contained in:
@@ -182,6 +182,7 @@ import ViewHistoryAside from './components/ViewHistoryAside/ViewHistoryAside.vue
|
||||
import axios from 'axios';
|
||||
import { useDiscussGetUserInfo } from '@/api/discussion/hook';
|
||||
import { Message } from 'vue-devui/message';
|
||||
import { fetchChatUseSql, fetchConversationDetail, fetchCreateConversation, FetchFollowupQuestions } from '@/api/jyh';
|
||||
|
||||
// 获取当前用户信息 & 是否登录
|
||||
const { isLogin = false, userInfo = {}} = useDiscussGetUserInfo();
|
||||
@@ -337,16 +338,21 @@ const getAIAnswer = async (content) => {
|
||||
question: content
|
||||
});
|
||||
|
||||
const response = await axios.post(`${VITE_AI_API_HOST}/api/v0/chat_use_sql`, {
|
||||
// const response = await axios.post(`${VITE_AI_API_HOST}/api/v0/chat_use_sql`, {
|
||||
// userId: username, // 使用 username 作为 userId
|
||||
// conversationId: CONV_ID.value,
|
||||
// question: content,
|
||||
// });
|
||||
const response = await fetchChatUseSql({
|
||||
userId: username, // 使用 username 作为 userId
|
||||
conversationId: CONV_ID.value,
|
||||
question: content,
|
||||
});
|
||||
|
||||
debugger
|
||||
|
||||
if(response.data.data.type) {
|
||||
const {text,type,id,table_name=[], states={}} = response.data.data;
|
||||
const row = response.data
|
||||
if(row.type) {
|
||||
const {text,type,id,table_name=[], states={}} = row;
|
||||
messages.value[messages.value.length - 1].id = id;
|
||||
// 处理思考过程
|
||||
const thinkProcess = processThinkStates(states);
|
||||
@@ -358,13 +364,13 @@ const getAIAnswer = async (content) => {
|
||||
messages.value[messages.value.length - 1].loading = false;
|
||||
messages.value[messages.value.length - 1].type = 'text';
|
||||
} else if(type==='df') {
|
||||
messages.value[messages.value.length - 1].content = response.data.data[type];
|
||||
messages.value[messages.value.length - 1].content = row[type];
|
||||
messages.value[messages.value.length - 1].loading = false;
|
||||
messages.value[messages.value.length - 1].type = 'df';
|
||||
|
||||
// 判断是否软件详情
|
||||
if(table_name.length===1&&table_name[0]==='critical_software_info') {
|
||||
let arr = JSON.parse(response.data.data[type]);
|
||||
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;
|
||||
@@ -372,7 +378,7 @@ const getAIAnswer = async (content) => {
|
||||
}
|
||||
}
|
||||
} else if(type==='sql_error') {
|
||||
messages.value[messages.value.length - 1].content = response.data.data.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';
|
||||
}
|
||||
@@ -430,10 +436,13 @@ const createConversation = async () => {
|
||||
Message.error('请先登录!');
|
||||
return;
|
||||
}
|
||||
const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, {
|
||||
// const response = await axios.post(`${VITE_AI_API_HOST}/api/createConversation`, {
|
||||
// userId: username,
|
||||
// });
|
||||
const response = await fetchCreateConversation({
|
||||
userId: username,
|
||||
});
|
||||
const createRes = response.data.data;
|
||||
const createRes = response.data;
|
||||
debugger
|
||||
if (createRes&&createRes.conversationId) {
|
||||
debugger
|
||||
@@ -462,10 +471,11 @@ const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||
df_id: df_id || '', // 使用当前会话ID,若无则为空
|
||||
sql_id: sql_id || '' // 同上
|
||||
};
|
||||
const response = await axios.post(
|
||||
`${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
||||
params
|
||||
);
|
||||
// const response = await axios.post(
|
||||
// `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
||||
// params
|
||||
// );
|
||||
const response = await FetchFollowupQuestions(params);
|
||||
const createRes = response.data;
|
||||
if (createRes&&createRes.questions) {
|
||||
followupQuestions.value = createRes.questions
|
||||
@@ -507,15 +517,23 @@ const handleSelectConv = (convId: string) => {
|
||||
// 定义获取会话详情的接口(根据实际接口调整)
|
||||
const getConversationDetail = async (convId: string) => {
|
||||
try {
|
||||
const response = await axios.get(`${VITE_AI_API_HOST}/api/conversationDetail`, {
|
||||
params: {
|
||||
userId: username,
|
||||
conversationId: convId,
|
||||
},
|
||||
// const response = await axios.get(`${VITE_AI_API_HOST}/api/conversationDetail`, {
|
||||
// params: {
|
||||
// userId: username,
|
||||
// conversationId: convId,
|
||||
// },
|
||||
// });
|
||||
const response = await fetchConversationDetail({
|
||||
userId: username,
|
||||
conversationId: convId,
|
||||
});
|
||||
const detail = response.data.data;
|
||||
// 处理详情数据(如回显消息列表)
|
||||
handleDetailResponse(detail);
|
||||
if(response.data?.error) {
|
||||
Message.error(response.data?.error);
|
||||
} else {
|
||||
const detail = response.data.messages;
|
||||
// 处理详情数据(如回显消息列表)
|
||||
handleDetailResponse(detail);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取会话详情失败:', error);
|
||||
Message.error('获取会话详情失败,请重试');
|
||||
|
||||
Reference in New Issue
Block a user