可信代码库-AI大模型模型推荐问题接口改造与对接
This commit is contained in:
@@ -85,7 +85,7 @@
|
||||
@click="onSubmit(q)"
|
||||
>
|
||||
<img src="@/assets/imgs/jyh/ai/icon_cnxw.png" style="height: 15px; margin-right: 8px" />
|
||||
<span class="ml-xs">{{ q }}</span>
|
||||
<span class="ml-xs">{{ q.question }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -245,19 +245,25 @@ const onInputIconClick = (e) => {
|
||||
};
|
||||
|
||||
const onSubmit = async (e, answer = undefined) => {
|
||||
debugger
|
||||
let obj = {
|
||||
role: 'user',
|
||||
avatarPosition: 'side-right',
|
||||
}
|
||||
if(e === '') {
|
||||
return;
|
||||
}
|
||||
if (e?.sql) {
|
||||
obj.content = e.question
|
||||
obj.sql = e.sql
|
||||
} else {
|
||||
obj.content = e
|
||||
}
|
||||
inputValue.value = '';
|
||||
if (!messages.value.length) {
|
||||
startChat.value = true;
|
||||
}
|
||||
messages.value.push({
|
||||
role: 'user',
|
||||
content: e,
|
||||
avatarPosition: 'side-right',
|
||||
avatarConfig: { ...customerAvatar },
|
||||
});
|
||||
messages.value.push(obj);
|
||||
followupQuestions.value = [];
|
||||
// getAIAnswer(answer ?? e);
|
||||
// 判断是否有会话id
|
||||
@@ -278,7 +284,11 @@ const onSubmit = async (e, answer = undefined) => {
|
||||
const handleRefresh = (index: number) => {
|
||||
const currentMsg = messages.value[index-1];
|
||||
if (currentMsg.role === 'user' && currentMsg.content) { // 假设AI回答的question字段存储了用户原始问题
|
||||
onSubmit(currentMsg.content); // 调用原有发送方法
|
||||
if(currentMsg.sql) {
|
||||
onSubmit({question:currentMsg.content,sql:currentMsg.sql}); // 调用原有发送方法
|
||||
} else {
|
||||
onSubmit(currentMsg.content); // 调用原有发送方法
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -336,7 +346,7 @@ const VITE_AI_API_HOST = (import.meta as any).env.VITE_AI_API_HOST;
|
||||
// AI对话接口对接
|
||||
const getAIAnswer = async (content) => {
|
||||
if(CONV_ID.value) {
|
||||
messages.value.push({
|
||||
let obj = {
|
||||
role: 'ai-model',
|
||||
type: '',
|
||||
content: '',
|
||||
@@ -344,7 +354,15 @@ const getAIAnswer = async (content) => {
|
||||
avatarConfig: { ...aiModelAvatar },
|
||||
loading: true,
|
||||
question: content
|
||||
});
|
||||
}
|
||||
if (content.sql) {
|
||||
obj.question = content.question
|
||||
obj.sql = content.sql
|
||||
} else {
|
||||
obj.question = content
|
||||
}
|
||||
|
||||
messages.value.push(obj);
|
||||
|
||||
// const response = await axios.post(`${VITE_AI_API_HOST}/api/v0/chat_use_sql`, {
|
||||
// userId: username, // 使用 username 作为 userId
|
||||
@@ -354,7 +372,8 @@ const getAIAnswer = async (content) => {
|
||||
const {data} = await fetchChatUseSql({
|
||||
userId: username, // 使用 username 作为 userId
|
||||
conversationId: CONV_ID.value,
|
||||
question: content,
|
||||
question: obj.question,
|
||||
sql: obj?.sql || '',
|
||||
});
|
||||
if(data.code===200) {
|
||||
const row = data.data
|
||||
@@ -491,22 +510,27 @@ const createConversation = async () => {
|
||||
};
|
||||
// 猜你想问接口
|
||||
const fetchFollowupQuestions = async (question,df_id,sql_id='') => {
|
||||
debugger
|
||||
try {
|
||||
// 构造请求参数(需根据实际文档补充 df_id 和 sql_id,示例中使用空字符串占位)
|
||||
const params = {
|
||||
let params = {
|
||||
question,
|
||||
df_id: df_id || '', // 使用当前会话ID,若无则为空
|
||||
sql_id: sql_id || '' // 同上
|
||||
};
|
||||
if (question?.sql) {
|
||||
params.question = question.question
|
||||
}
|
||||
// const response = await axios.post(
|
||||
// `${VITE_AI_API_HOST}/api/v0/provide_followup_questions`,
|
||||
// params
|
||||
// );
|
||||
const {data} = await FetchFollowupQuestions(params);
|
||||
debugger
|
||||
if(data.code===200) {
|
||||
const createRes = data.data;
|
||||
if (createRes&&createRes.questions) {
|
||||
followupQuestions.value = createRes.questions
|
||||
if (createRes) {
|
||||
followupQuestions.value = createRes
|
||||
} else {
|
||||
// Message.error('创建会话失败,未获取到会话ID');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user