pet/http/api/assistant.js

113 lines
2.3 KiB
JavaScript

// AI助手相关API接口
// 注意:所有接口的鉴权配置已在 http/config/config.js 中统一管理
/**
* 发送消息给AI助手
* @param {Object} messageData 消息数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const sendMessage = (messageData, config = {}) => {
return uni.$u.http.post('/ai/chat', messageData, {
custom: {
auth: true,
loading: true,
loadingText: 'AI正在思考中...',
...config.custom
},
...config
})
}
/**
* 获取AI知识库
* @param {Object} params 查询参数
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const getKnowledgeBase = (params = {}, config = {}) => {
return uni.$u.http.get('/ai/knowledge', {
params,
custom: {
auth: false,
loading: false,
...config.custom
},
...config
})
}
/**
* 获取聊天历史
* @param {Object} params 查询参数
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const getChatHistory = (params = {}, config = {}) => {
return uni.$u.http.get('/ai/chat/history', {
params,
custom: {
auth: true,
loading: false,
...config.custom
},
...config
})
}
/**
* 清除聊天历史
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const clearChatHistory = (config = {}) => {
return uni.$u.http.delete('/ai/chat/history', {}, {
custom: {
auth: true,
loading: true,
loadingText: '正在清除历史记录...',
...config.custom
},
...config
})
}
/**
* 获取AI建议
* @param {Object} petData 宠物数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const getAISuggestion = (petData, config = {}) => {
return uni.$u.http.post('/ai/suggestion', petData, {
custom: {
auth: true,
loading: true,
loadingText: '正在分析宠物状况...',
...config.custom
},
...config
})
}
/**
* 语音转文字
* @param {Object} audioData 音频数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const speechToText = (audioData, config = {}) => {
return uni.$u.http.upload('/ai/speech-to-text', {
filePath: audioData.filePath,
name: 'audio',
formData: audioData.formData || {},
custom: {
auth: true,
loading: true,
loadingText: '正在识别语音...',
...config.custom
},
...config
})
}