From 0defac4200cab94fe7b932b0ca093d9ed19a4b8f Mon Sep 17 00:00:00 2001 From: DCloud__JSON Date: Tue, 6 Jun 2023 21:46:42 +0800 Subject: [PATCH] 1.0.21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 用户输入的内容,会被markdown解析,导致显示错误的问题 - 修复 web-pc端 发送消息,会失去焦点的问题 - 修复 当ai回答的问题未完成时,点击换答案会进入异常的问题 - 修复 部分情况下 ai回复问题时,光标不停地换行和撤销换行 导致界面上下抖动的问题 - 修复 短时间内多次操作 `停止响应`和`换答案`功能,偶发响应的数据顺序错乱的问题 - 新增 客户端支持`model`选择功能(仅预置了`openai`的6个model,可以自行在组件路径:`/components/llm-config/llm-config.vue`中,增改) --- changelog.md | 7 + common/unicloud-co-task.js | 61 +++++ components/llm-config/llm-config.vue | 167 ++++++++++++ components/uni-ai-msg/uni-ai-msg.vue | 28 +- package.json | 2 +- pages/chat/chat.vue | 240 ++++++++++-------- .../cloudfunctions/uni-ai-chat/index.obj.js | 8 +- 7 files changed, 399 insertions(+), 114 deletions(-) create mode 100644 common/unicloud-co-task.js create mode 100644 components/llm-config/llm-config.vue diff --git a/changelog.md b/changelog.md index 9f02742..c6b8de0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +## 1.0.21(2023-06-06) +- 修复 用户输入的内容,会被markdown解析,导致显示错误的问题 +- 修复 web-pc端 发送消息,会失去焦点的问题 +- 修复 当ai回答的问题未完成时,点击换答案会进入异常的问题 +- 修复 部分情况下 ai回复问题时,光标不停地换行和撤销换行 导致界面上下抖动的问题 +- 修复 短时间内多次操作 `停止响应`和`换答案`功能,偶发响应的数据顺序错乱的问题 +- 新增 客户端支持`model`选择功能(仅预置了`openai`的6个model,可以自行在组件路径:`/components/llm-config/llm-config.vue`中,增改) ## 1.0.20(2023-06-05) - 修复 移动端 部分情况下 代码块的复制按钮,挡住内容的问题 - 修复 微信小程序端 点击“复制按钮”无效的问题 diff --git a/common/unicloud-co-task.js b/common/unicloud-co-task.js new file mode 100644 index 0000000..417102d --- /dev/null +++ b/common/unicloud-co-task.js @@ -0,0 +1,61 @@ +class Task { + constructor({ + success, + fail, + complete + } = {}) { + this.status = 0 + this.callback = { + success, + fail, + complete + } + } + + invoke(callbackName, ...args) { + if (this.status !== 0) { + // console.log('此任务已被终止'); + return + } + const callback = this.callback[callbackName] + callback && callback(...args) + } + abort() { + this.status = 1 + } +} + +export default function main({ + coName, + funName, + param, + success, + fail, + complete, + config +} = {}) { + + if(!Array.isArray(param)){ + throw new Error('param的值必须为数组') + } + + const task = new Task({ + success, + fail, + complete + }) + + const uniCloudCo = uniCloud.importObject(coName, config||{}) + + uniCloudCo[funName](...param) + .then(res => { + task.invoke('success', res) + }) + .catch(err => { + task.invoke('fail', err) + }) + .finally(res => { + task.invoke('complete', res) + }) + return task +} \ No newline at end of file diff --git a/components/llm-config/llm-config.vue b/components/llm-config/llm-config.vue new file mode 100644 index 0000000..3ab4d87 --- /dev/null +++ b/components/llm-config/llm-config.vue @@ -0,0 +1,167 @@ + + + + + \ No newline at end of file diff --git a/components/uni-ai-msg/uni-ai-msg.vue b/components/uni-ai-msg/uni-ai-msg.vue index 70c5674..d5c43df 100644 --- a/components/uni-ai-msg/uni-ai-msg.vue +++ b/components/uni-ai-msg/uni-ai-msg.vue @@ -5,12 +5,16 @@ - + - + + + {{msgContent}} + + 默认不启用广告组件(被注释),如需使用,请"去掉注释"(“重新运行”后生效) @@ -151,20 +155,20 @@ default () { return false } - } + } }, computed: { - md() { + msgContent() { return this.msg.content }, nodes() { let htmlString = '' // 修改转换结果的htmlString值 用于正确给界面增加鼠标闪烁的效果 // 判断markdown中代码块标识符的数量是否为偶数 - if (this.md.split("```").length % 2) { - htmlString = markdownIt.render(this.md + ' \n |'); + if (this.msgContent.split("```").length % 2) { + htmlString = markdownIt.render(this.msgContent + ' |'); } else { - htmlString = markdownIt.render(this.md) + ' \n |'; + htmlString = markdownIt.render(this.msgContent) + ' \n |'; } // #ifndef APP-NVUE @@ -179,7 +183,7 @@ // #endif } }, - methods: { + methods: { // 根据消息状态返回对应的图标 msgStateIcon(msg) { switch (msg.state) { @@ -229,7 +233,7 @@ // 复制文本内容到系统剪切板 copy() { uni.setClipboardData({ - data: this.md, + data: this.msgContent, showToast: false, success() { uni.showToast({ @@ -256,7 +260,7 @@ /* #endif */ .userInfo { - flex-direction: column; + flex-direction: column; } .msg-item { @@ -278,8 +282,8 @@ width: 40px; height: 40px; border-radius: 2px; - } - + } + .create_time { font-size: 12px; padding: 5px 0; diff --git a/package.json b/package.json index cd81199..61968ad 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "uni-ai-chat", "name": "uni-ai-chat", - "version": "1.0.20", + "version": "1.0.21", "description": "基于uni-ai的聊天示例项目,支持流式、支持前文总结,云端一体", "main": "main.js", "scripts": { diff --git a/pages/chat/chat.vue b/pages/chat/chat.vue index 71a642e..be3d75b 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -1,5 +1,5 @@