perf: 优化ai机器人

This commit is contained in:
kuaifan 2024-02-29 19:39:05 +08:00
parent 81690d6ce9
commit 9133f289b4
3 changed files with 68 additions and 7 deletions

View File

@ -559,6 +559,8 @@ class User extends AbstractModel
return url("images/avatar/default_openai.png"); return url("images/avatar/default_openai.png");
case 'ai-claude@bot.system': case 'ai-claude@bot.system':
return url("images/avatar/default_claude.png"); return url("images/avatar/default_claude.png");
case 'ai-gemini@bot.system':
return url("images/avatar/default_gemini.png");
case 'bot-manager@bot.system': case 'bot-manager@bot.system':
return url("images/avatar/default_bot.png"); return url("images/avatar/default_bot.png");
case 'meeting-alert@bot.system': case 'meeting-alert@bot.system':

View File

@ -170,7 +170,7 @@ services:
ai: ai:
container_name: "dootask-ai-${APP_ID}" container_name: "dootask-ai-${APP_ID}"
image: "kuaifan/dooai:0.1.4" image: "kuaifan/dooai:0.1.8"
networks: networks:
extnetwork: extnetwork:
ipv4_address: "${APP_IPPR}.12" ipv4_address: "${APP_IPPR}.12"
@ -178,7 +178,7 @@ services:
okr: okr:
container_name: "dootask-okr-${APP_ID}" container_name: "dootask-okr-${APP_ID}"
image: "kuaifan/doookr:0.0.35" image: "kuaifan/doookr:0.0.37"
environment: environment:
TZ: "${TIMEZONE:-PRC}" TZ: "${TIMEZONE:-PRC}"
DOO_TASK_URL: "http://${APP_IPPR}.3" DOO_TASK_URL: "http://${APP_IPPR}.3"

View File

@ -762,6 +762,7 @@ export default {
approvaUserStatus: '', approvaUserStatus: '',
observers: [], observers: [],
msgChangeCache: {},
unreadOne: 0, // id unreadOne: 0, // id
topPosLoad: 0, // topPosLoad: 0, //
@ -1586,22 +1587,80 @@ export default {
this.sendMsg(`<p><span data-quick-key="${item.key}">${item.label}</span></p>`) this.sendMsg(`<p><span data-quick-key="${item.key}">${item.label}</span></p>`)
}, },
/**
* 消息变化处理
* @param data
*/
onMsgChange(data) { onMsgChange(data) {
const item = this.allMsgs.find(({type, id}) => type == "text" && id == data.id) const item = this.allMsgs.find(({type, id}) => type == "text" && id == data.id)
if (item) { if (item) {
const {tail} = this.scrollInfo() if (typeof this.msgChangeCache[data.id] === "undefined") {
if (data.type === 'append') { this.msgChangeCache[data.id] = []
item.msg.text += data.text this.msgChangeCache[`${data.id}_load`] = false
} else if (data.type === 'replace') {
item.msg.text = data.text
} }
if (data.type === 'append') {
this.msgChangeCache[data.id].push(...`${data.text}`.split("").map(text => {
return {
type: 'append',
text
}
}))
} else if (data.type === 'replace') {
this.msgChangeCache[data.id] = [{
type: 'replace',
text: data.text
}]
}
this.onMsgOutput(data.id, item.msg)
}
},
/**
* 追加或替换消息
* @param id
* @param msg
*/
onMsgOutput(id, msg) {
const load = `${id}_load`
const arr = this.msgChangeCache[id]
if (!arr || arr.length === 0) return
if (this.msgChangeCache[load] === true) return
this.msgChangeCache[load] = true
try {
const data = arr.shift()
if (!data) {
this.msgChangeCache[load] = false
return
}
const {type, text} = data
const {tail} = this.scrollInfo()
if (type === 'append') {
msg.text += text
} else if (type === 'replace') {
msg.text = text
}
this.$nextTick(_ => { this.$nextTick(_ => {
if (tail <= 10 && tail != this.scrollInfo().tail) { if (tail <= 10 && tail != this.scrollInfo().tail) {
this.operatePreventScroll++ this.operatePreventScroll++
this.$refs.scroller.scrollToBottom() this.$refs.scroller.scrollToBottom()
setTimeout(_ => this.operatePreventScroll--, 50) setTimeout(_ => this.operatePreventScroll--, 50)
} }
if (arr.length === 0) {
this.msgChangeCache[load] = false
return
}
setTimeout(_ => {
this.msgChangeCache[load] = false
this.onMsgOutput(id, msg)
}, 5)
}) })
} catch (e) {
this.msgChangeCache[load] = false
} }
}, },