diff --git a/changelog.md b/changelog.md index 9f02742df1105c41fe8acdfc1d4a04403893ad4a..c6b8de08cf08b557261bf64b4ce1ef70306458e6 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 0000000000000000000000000000000000000000..417102d391a121aaaaff3439a6f6a18acbf317c3 --- /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 0000000000000000000000000000000000000000..3ab4d879c3a09b403b2565e36b77663c0f37d63b --- /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 70c5674f2735311d161429af0e8b310d8d5f783f..d5c43df0a1735aec09894f538cf63d6f40e854a1 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 cd811997934e8e5bb016993b5caa56fb8c5da586..61968add8499b8782976eab10e4a4a6d1b515585 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 71a642e42bc031be4d1023dbee7bfea51c1e145a..be3d75b421f6f8560405b9a2471fe8c22f690f4d 100644 --- a/pages/chat/chat.vue +++ b/pages/chat/chat.vue @@ -1,5 +1,5 @@