diff --git a/ui/src/components/ai-dialog/index.vue b/ui/src/components/ai-dialog/index.vue index 800e6c7bc..a8d267854 100644 --- a/ui/src/components/ai-dialog/index.vue +++ b/ui/src/components/ai-dialog/index.vue @@ -73,7 +73,7 @@ text class="sent-button" :disabled="!(inputValue && data?.name && data?.model_id)" - @click="chatHandle" + @click="chatMessage" > { - chatMessage(res.data) + chartOpenId.value = res.data + chatMessage() }) .catch(() => { loading.value = false }) } -function chatMessage(chatId: string) { - applicationApi.postChatMessage(chatId, inputValue.value).then(async (response) => { - const reader = response.body.getReader() - while (true) { - const { done, value } = await reader.read() - if (done) { - loading.value = false - break +function chatMessage() { + if (!chartOpenId.value) { + getChartOpenId() + } else { + applicationApi.postChatMessage(chartOpenId.value, inputValue.value).then(async (response) => { + const reader = response.body.getReader() + while (true) { + const { done, value } = await reader.read() + if (done) { + loading.value = false + break + } + const decoder = new TextDecoder('utf-8') + const str = decoder.decode(value, { stream: true }) + console.log('value', JSON.parse(str.replace('data:', ''))) } - const decoder = new TextDecoder('utf-8') - const str = decoder.decode(value, { stream: true }) - console.log('value', JSON.parse(str.replace('data:', ''))) - } - }) + }) + } }