From b8e434be9a1ae08e062253c4d01df2aa315d90c0 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 4 Jan 2025 15:52:32 +0100 Subject: [PATCH] fix chat limit reached message --- dashboard/pages/analyst.vue | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dashboard/pages/analyst.vue b/dashboard/pages/analyst.vue index e6b3c79..b67f1b1 100644 --- a/dashboard/pages/analyst.vue +++ b/dashboard/pages/analyst.vue @@ -23,7 +23,7 @@ const { data: chatsRemaining, refresh: reloadChatsRemaining } = useFetch(`/api/a const currentText = ref(""); const loading = ref(false); -const canSend = ref(false); +const canSend = ref(true); const currentChatId = ref(""); const currentChatMessages = ref<{ role: string, content: string, charts?: any[], tool_calls?: any }[]>([]); @@ -75,6 +75,8 @@ async function pollSendMessageStatus(chat_id: string, times: number, updateStatu setTimeout(() => pollSendMessageStatus(chat_id, times + 1, updateStatus), (times > 10 ? 2000 : 1000)); } else { + canSend.value = true; + typer.stop(); const messages = await $fetch(`/api/ai/${chat_id}/get_messages`, { @@ -84,12 +86,14 @@ async function pollSendMessageStatus(chat_id: string, times: number, updateStatu currentChatMessages.value = messages.map(e => ({ ...e, charts: e.charts.map(k => JSON.parse(k)) })) as any; currentChatMessageDelta.value = ''; + } } async function sendMessage() { + if (canSend.value === false) return; if (loading.value) return; if (!project.value) return; @@ -128,25 +132,25 @@ async function sendMessage() { currentChatMessageDelta.value = status; }); - canSend.value = true; + } catch (ex: any) { if (ex.message.includes('CHAT_LIMIT_REACHED')) { currentChatMessages.value.push({ role: 'assistant', - content: 'You have reached your current tier chat limit.\n Upgrade to an higher tier. Upgrade now. ', + content: `Chat limit reached. + Upgrade your plan to continue chatting.` }); - } - - if (ex.message.includes('Unauthorized')) { + } else if (ex.message.includes('Unauthorized')) { currentChatMessages.value.push({ role: 'assistant', content: 'To use AI you need to provide AI_ORG, AI_PROJECT and AI_KEY in docker compose', }); + } else { + currentChatMessages.value.push({ role: 'assistant', content: ex.message, }); } - - currentChatMessages.value.push({ role: 'assistant', content: ex.message, }); + loading.value = false; canSend.value = true;