diff --git a/ui/src/api/type/application.ts b/ui/src/api/type/application.ts index 8d578be68..d6f3ccfcb 100644 --- a/ui/src/api/type/application.ts +++ b/ui/src/api/type/application.ts @@ -1,3 +1,4 @@ +import { type Ref } from 'vue' interface ApplicationFormType { name?: string desc?: string @@ -11,5 +12,42 @@ interface chatType { id: string problem_text: string answer_text: string + buffer: Array +} + +export class ChatManage { + id?: NodeJS.Timer + ms: number + chat: chatType + is_close?: boolean + loading?: Ref + constructor(chat: chatType, ms?: number, loading?: Ref) { + this.ms = ms ? ms : 10 + this.chat = chat + this.loading = loading + } + write() { + this.id = setInterval(() => { + const s = this.chat.buffer.shift() + if (s !== undefined) { + this.chat.answer_text = this.chat.answer_text + s + } else { + if (this.is_close) { + clearInterval(this.id) + if (this.loading) { + this.loading.value = false + } + } + } + }, this.ms) + } + close() { + this.is_close = true + } + append(answer_text_block: string) { + for (let index = 0; index < answer_text_block.length; index++) { + this.chat.buffer.push(answer_text_block[index]) + } + } } export type { ApplicationFormType, chatType } diff --git a/ui/src/components/ai-dialog/index.vue b/ui/src/components/ai-dialog/index.vue index 085b92182..c019b51d6 100644 --- a/ui/src/components/ai-dialog/index.vue +++ b/ui/src/components/ai-dialog/index.vue @@ -100,7 +100,7 @@