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