Clever Helmet智慧问答系统:基于GPT-3.5-Turbo的智能对话体验
<script>
export default {
data() {
return {
prompt: '',
responseData: '',
response: '',
loading: 'false'
};
},
methods: {
submit() {
if (this.prompt !== '') {
this.submitData();
} else {
// uni.showToast({
// title: '提交内容为空',
// icon: 'error'
// });
uni.showModal({
title: '操作错误',
content: '提交内容不能为空\n请在问题输入框中输入你要咨询的问题\n来自开发者冯楠2010188的提示',
showCancel: false,
confirmText: '确定'
});
}
},
submitData() {
uni.showLoading({
title: '请耐心等待回答结果...'
}); // 显示等待框
this.loading = true;
uni.request({
url: 'https://svip1-api.cveoy.top/v3/completions', // 假设接口地址为 http://localhost:3000/data
method: 'POST',
data: {
prompt: this.prompt,
keys: 'sk-eae8a6f4e46c49fb9c1c8e933b2a33e7'
},
success: res => {
let responseData = res.data;
responseData = responseData.replace('你当前使用的模型为gpt-3.5-turbo!', '欢迎使用Clever Helmet智慧问答系统\n');
console.log(responseData);
this.responseData = responseData;
let responseArray = responseData.split('\n');
let i = 0;
let timer = setInterval(() => {
if (i < responseArray.length) {
this.response += responseArray[i] + '\n';
i++;
} else {
clearInterval(timer);
}
}, 1000);
},
complete: () => {
uni.hideLoading(); // 隐藏等待框
this.loading = false;
}
});
}
}
};
</script>
原文地址: https://www.cveoy.top/t/topic/jk7e 著作权归作者所有。请勿转载和采集!