【Spring AI】基于专属知识库的RAG智能问答小程序开发——完备项目(含完备
系列文章目次[*]【Spring AI】基于专属知识库的RAG智能问答小程序开发——完备项目(含完备前端+后端代码)
[*]【Spring AI】基于专属知识库的RAG智能问答小程序开发——代码逐行精讲:焦点ChatClient对象相干构造函数
<hr>
<hr> 项目效果展示
https://i-blog.csdnimg.cn/direct/8a18abae344b47a7875c89c223163b68.png
1.开发工具及环境
IntelliJ IDEA
微信开发者工具
JDK版本 >= 17
Spring Boot版本 >= 3.3.x
阿里云百炼api_keyu获取:阿里云百炼官网api获取教程
2.前端代码(原生微信小程序开发)
2.1.前端文件架构:
https://i-blog.csdnimg.cn/direct/bc434489c34f4256a9aa257e9d0bff0f.png
2.2.index.js文件
// index.js
Page({
onLoad() {
// const systemInfo = wx.getDeviceInfo();
const systemInfo = wx.getSystemInfoSync();
this.setData({
statusBarHeight: systemInfo.statusBarHeight,
navBarHeight: systemInfo.platform === 'android' ? 48 : 44
});
if (this.data.messages.length === 0) {
this.setData({
messages: [{
content: '用户您好,我是百晓生,了解金融行业的各类信息,您有什么问题吗?',
role: 'bot',
timestamp: new Date().getTime()
}]
})
}
},
data: {
messages: [], // 消息列表
inputValue: '', // 输入框内容
isLoading: false, // 加载状态
scrollTop: 0, // 滚动位置
statusBarHeight: 20, // 默认状态栏高度
navBarHeight: 44, // 导航栏默认高度
inputContainerHeight: 100 // 初始高度对应min-height
},
onInput(e) {
this.setData({
inputValue: e.detail.value });
},
sendMessage() {
const question = this.data.inputValue.trim();
if (!question) return;
// 添加用户消息
const newMessage = {
content: question,
role: 'user',
timestamp: new Date().getTime()
};
this.setData({
messages: [...this.data.messages, newMessage],
inputValue: '',
key: Date.now(), // 强制重置textarea
isLoading: true,
scrollTop: 99999
});
// 调用后端接口
wx.request({
url: 'http://localhost:8080/ai/ragChat',
method: 'POST',
header: {
'Content-Type': 'application/json'
},
timeout: 200000, // 增加5分钟超时设置(300秒=300000毫秒)
data: {
input: question
},
success: (res) => {
if (res.statusCode === 200) {
const answer = {
content: res.data,
role: 'bot',
timestamp: new Date().getTime()
};
this.setData({
messages: [...this.data.messages, answer],
isLoading: false,
scrollTop: 99999
});
}
},
fail: (err) => {
console.error('请求失败', err);
let title = '请求失败,请重试';
// 添加超时特定提示
if (err.errMsg && err.errMsg.includes('timeout')) {
title = '请求超时,请检查网络或稍后再试';
}
this.setData({
isLoading: false
})
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]