可信代码库-AI大模型公网接口对接

This commit is contained in:
付民康
2025-06-24 17:35:03 +08:00
parent 8e76b60c75
commit dfde8df815
6 changed files with 225 additions and 56 deletions

View File

@@ -369,3 +369,86 @@ export function basicDict(data) {
data: data,
});
}
/*AI大模型接口*/
// 1. 创建对话
export function fetchCreateConversation(data) {
return request({
url: `/agentHelper/api/createConversation`,
method: 'post',
data: data,
});
}
// 2. 对话
export function fetchChatUseSql(data) {
return request({
url: `/agentHelper/api/v0/chat_use_sql`,
method: 'post',
data: data,
});
}
// 3. 查询会话列表
export function fetchConversationList(data) {
return request({
url: `/agentHelper/api/conversationList`,
method: 'post',
data: data,
});
}
// 4. 查询会话详情
export function fetchConversationDetail(params) {
return request({
url: `/agentHelper/api/conversationDetail`,
method: 'get',
params: params,
});
}
// 5. 获取推荐问题
export function FetchFollowupQuestions(data) {
return request({
url: `/agentHelper/api/v0/provide_followup_questions`,
method: 'post',
data: data,
});
}
// 6. 修改会话标题
export function fetchChangeConversationTitle(data) {
return request({
url: `/agentHelper/api/changeConversationTitle`,
method: 'post',
data: data,
});
}
// 7. 修改会话的收藏状态
export function fetchToggleConversationCollect(data) {
return request({
url: `/agentHelper/api/toggleConversationCollect`,
method: 'post',
data: data,
});
}
// 8. 删除对话
export function fetchDeleteConversation(data) {
return request({
url: `/agentHelper/api/deleteConversation`,
method: 'post',
data: data,
});
}
// 9. 首页推荐问题
export function fetchUpdateRecommendQuestions(data) {
return request({
url: `/agentHelper/api/v0/update_recommend_questions`,
method: 'post',
data: data,
});
}

View File

@@ -133,7 +133,7 @@ const handleHelp = () => {
// window.location.href = 'http://222.20.126.208:4399/';
// 或者使用 window.open 打开新标签页
window.open('http://222.20.126.208:4399/', '_blank');
window.open('http://52.184.83.30:8088/', '_blank');
console.log('正在跳转到帮助页面');
} catch (error) {

View File

@@ -21,6 +21,7 @@
<script setup>
import { nextTick, onMounted, ref } from 'vue';
import axios from 'axios';
import { fetchUpdateRecommendQuestions } from '@/api/jyh';
const emits = defineEmits(['submit']);
@@ -59,11 +60,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/update_recommend_questions`,
params
);
debugger
// const response = await axios.post(
// `${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

View File

@@ -153,6 +153,7 @@ import axios from 'axios';
import { Message } from 'vue-devui/message';
import NoData from '@/components/NoData/NoData.vue';
import { GModal } from '@/components/Setting/index';
import { fetchConversationList, fetchDeleteConversation, fetchToggleConversationCollect } from '@/api/jyh';
// 接收父组件传递的用户名
const props = defineProps(['username']);
@@ -196,7 +197,16 @@ const getQuestionHistory = async () => {
return;
}
try {
const { data } = await axios.post(import.meta.env.VITE_AI_API_HOST + '/api/conversationList', {
// const { data } = await axios.post(import.meta.env.VITE_AI_API_HOST + '/api/conversationList', {
// "userId": props.username,
// "list_type": "history",
// "is_manage": true,
// "page": dhlsPagination.value.page,
// "size": dhlsPagination.value.size,
// "search": searchText.value
// });
const { data } = await fetchConversationList({
"userId": props.username,
"list_type": "history",
"is_manage": true,
@@ -204,7 +214,7 @@ const getQuestionHistory = async () => {
"size": dhlsPagination.value.size,
"search": searchText.value
});
debugger
if (data.data.conversationList) {
dhlsList.value = data.data.conversationList;
dhlsPagination.value.total = data.data.pagination.total || 0;
@@ -221,7 +231,15 @@ const getQuestionCollection = async () => {
return;
}
try {
const { data } = await axios.post(import.meta.env.VITE_AI_API_HOST + '/api/conversationList', {
// const { data } = await axios.post(import.meta.env.VITE_AI_API_HOST + '/api/conversationList', {
// "userId": props.username,
// "list_type": "collection",
// "is_manage": true,
// "page": collectionPagination.value.page,
// "size": collectionPagination.value.size,
// "search": searchText.value
// });
const { data } = await fetchConversationList({
"userId": props.username,
"list_type": "collection",
"is_manage": true,
@@ -229,6 +247,7 @@ const getQuestionCollection = async () => {
"size": collectionPagination.value.size,
"search": searchText.value
});
if (data.data.conversationList) {
collectionList.value = data.data.conversationList;
collectionPagination.value.total = data.data.pagination.total || 0;
@@ -304,14 +323,19 @@ const handleDelete = async (conversationIds) => {
}
try {
const res = await axios.post(
`${import.meta.env.VITE_AI_API_HOST}/api/deleteConversation`,
{
// const res = await axios.post(
// `${import.meta.env.VITE_AI_API_HOST}/api/deleteConversation`,
// {
// userId: props.username,
// conversationIdList: conversationIds
// }
// );
const res = await fetchDeleteConversation({
userId: props.username,
conversationIdList: conversationIds
}
);
if (res.data.code === 200) {
if (res.data.code === 200||res.data.code === 20000) {
Message.success(res.data.message || '删除成功');
// 刷新当前标签页的数据
initData()
@@ -333,12 +357,17 @@ const toggleCollect = async (conversationIds) => {
}
try {
const res = await axios.post(`${VITE_AI_API_HOST}/api/toggleConversationCollect`, {
// const res = await axios.post(`${VITE_AI_API_HOST}/api/toggleConversationCollect`, {
// userId: props.username,
// conversationIdList: conversationIds
// });
const res = await fetchToggleConversationCollect({
userId: props.username,
conversationIdList: conversationIds
});
if (res.data.code === 200) {
if (res.data.code === 200||res.data.code === 20000) {
Message.success(res.data.message || '取消收藏成功');
// 刷新当前标签页的数据
initData()

View File

@@ -52,9 +52,9 @@
name="icon-edit-3"
/>
</d-tooltip>
<d-tooltip content="分享">
<d-icon style="font-size: 14px;margin-right: 2px" @click.stop="handleShare(item)" name="icon-redo-new"></d-icon>
</d-tooltip>
<!-- <d-tooltip content="分享">-->
<!-- <d-icon style="font-size: 14px;margin-right: 2px" @click.stop="handleShare(item)" name="icon-redo-new"></d-icon>-->
<!-- </d-tooltip>-->
<d-dropdown style="width: 100px;" align="start">
<d-icon style="font-size: 14px;" @click.stop="handleMore(item)" name="icon-more-operate"></d-icon>
<template #menu>
@@ -171,9 +171,9 @@
name="icon-edit-3"
/>
</d-tooltip>
<d-tooltip content="分享">
<d-icon style="font-size: 14px;margin-right: 2px" @click.stop="handleShare(item)" name="icon-redo-new"></d-icon>
</d-tooltip>
<!-- <d-tooltip content="分享">-->
<!-- <d-icon style="font-size: 14px;margin-right: 2px" @click.stop="handleShare(item)" name="icon-redo-new"></d-icon>-->
<!-- </d-tooltip>-->
<d-dropdown style="width: 100px;" align="start">
<d-icon style="font-size: 14px;" @click.stop="handleMore(item)" name="icon-more-operate"></d-icon>
<template #menu>
@@ -245,6 +245,12 @@ import axios from 'axios';
import { Message } from 'vue-devui/message';
import { useTimeFormat } from '@/utils/hooks/useTimeFormat';
import NoData from '@/components/NoData/NoData.vue';
import {
fetchChangeConversationTitle,
fetchConversationList,
fetchDeleteConversation,
fetchToggleConversationCollect
} from '@/api/jyh';
// 定义父组件通信的事件
const emit = defineEmits(['select-conv']);
@@ -310,12 +316,16 @@ const confirmEdit = async (item) => {
}
try {
const res = await axios.post(`${VITE_AI_API_HOST}/api/changeConversationTitle`, {
// const res = await axios.post(`${VITE_AI_API_HOST}/api/changeConversationTitle`, {
// conversationId: item.conversationId,
// newTitle: item.tempTitle
// });
const res = await fetchChangeConversationTitle({
conversationId: item.conversationId,
newTitle: item.tempTitle
});
if (res.data.code === 200 ||res.data.code === 20001||res.data.code === 200) {
if (res.data.code === 200 ||res.data.code === 20001||res.data.code === 20000) {
item.title = item.tempTitle; // 更新标题
item.isEditing = false; // 退出编辑状态
Message.success('标题修改成功');
@@ -336,12 +346,17 @@ const toggleCollect = async (item) => {
}
try {
const res = await axios.post(`${VITE_AI_API_HOST}/api/toggleConversationCollect`, {
// const res = await axios.post(`${VITE_AI_API_HOST}/api/toggleConversationCollect`, {
// userId: props.username,
// conversationIdList: [item.conversationId]
// });
const res = await fetchToggleConversationCollect({
userId: props.username,
conversationIdList: [item.conversationId]
});
if (res.data.code === 200) {
if (res.data.code === 200||res.data.code === 20000) {
// // 确保is_collected是响应式的
// const isCollected = res.data.isCollected;
// // 找到对应的项并更新(使用索引确保响应式更新)
@@ -406,7 +421,16 @@ const page = ref({
const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST;
const getQuestionHistory = async () => {
if(props.username) {
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
// const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
// "userId": props.username,
// "list_type": "history",
// "is_manage": false,
// "page": page.value.pageNum,
// "size": page.value.size,
// "search": searchText.value
// });
const {data} = await fetchConversationList({
"userId": props.username,
"list_type": "history",
"is_manage": false,
@@ -415,8 +439,8 @@ const getQuestionHistory = async () => {
"search": searchText.value
});
debugger
if(data.data) {
dhlsList.value = data.data
if(data.conversationList) {
dhlsList.value = data.conversationList
} else {
// Message.error(data.error||'接口异常!')
}
@@ -426,7 +450,15 @@ const getQuestionHistory = async () => {
};
const getQuestionCollection = async () => {
if(props.username) {
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
// const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
// "userId": props.username,
// "list_type": "collection",
// "is_manage": false,
// "page": page.value.pageNum,
// "size": page.value.size,
// "search": searchText.value
// });
const {data} = await fetchConversationList({
"userId": props.username,
"list_type": "collection",
"is_manage": false,
@@ -434,8 +466,8 @@ const getQuestionCollection = async () => {
"size": page.value.size,
"search": searchText.value
});
if(data.data) {
collectionList.value = data.data
if(data.conversationList) {
collectionList.value = data.conversationList
} else {
// Message.error(data.error||'接口异常!')
}
@@ -452,14 +484,20 @@ const handleDelete = async (conversationIds, tabType) => {
}
try {
const res = await axios.post(
`${import.meta.env.VITE_AI_API_HOST}/api/deleteConversation`,
{
// const res = await axios.post(
// `${import.meta.env.VITE_AI_API_HOST}/api/deleteConversation`,
// {
// userId: props.username,
// conversationIdList: conversationIds
// }
// );
const res = await fetchDeleteConversation({
userId: props.username,
conversationIdList: conversationIds
}
);
if (res.data.code === 200) {
if (res.data.code === 200 || res.data.code === 20000) {
Message.success(res.data.message || '删除成功');
loadData()
} else {

View File

@@ -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('获取会话详情失败,请重试');