fix chat limit reached message

This commit is contained in:
Emily
2025-01-04 15:52:32 +01:00
parent 835ab6208e
commit b8e434be9a

View File

@@ -23,7 +23,7 @@ const { data: chatsRemaining, refresh: reloadChatsRemaining } = useFetch(`/api/a
const currentText = ref<string>(""); const currentText = ref<string>("");
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const canSend = ref<boolean>(false); const canSend = ref<boolean>(true);
const currentChatId = ref<string>(""); const currentChatId = ref<string>("");
const currentChatMessages = ref<{ role: string, content: string, charts?: any[], tool_calls?: any }[]>([]); 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)); setTimeout(() => pollSendMessageStatus(chat_id, times + 1, updateStatus), (times > 10 ? 2000 : 1000));
} else { } else {
canSend.value = true;
typer.stop(); typer.stop();
const messages = await $fetch(`/api/ai/${chat_id}/get_messages`, { 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; currentChatMessages.value = messages.map(e => ({ ...e, charts: e.charts.map(k => JSON.parse(k)) })) as any;
currentChatMessageDelta.value = ''; currentChatMessageDelta.value = '';
} }
} }
async function sendMessage() { async function sendMessage() {
if (canSend.value === false) return;
if (loading.value) return; if (loading.value) return;
if (!project.value) return; if (!project.value) return;
@@ -128,25 +132,25 @@ async function sendMessage() {
currentChatMessageDelta.value = status; currentChatMessageDelta.value = status;
}); });
canSend.value = true;
} catch (ex: any) { } catch (ex: any) {
if (ex.message.includes('CHAT_LIMIT_REACHED')) { if (ex.message.includes('CHAT_LIMIT_REACHED')) {
currentChatMessages.value.push({ currentChatMessages.value.push({
role: 'assistant', role: 'assistant',
content: 'You have reached your current tier chat limit.\n Upgrade to an higher tier. <a style="color: blue; text-decoration: underline;" href="/plans"> Upgrade now. </a>', content: `Chat limit reached.
Upgrade your plan to continue chatting.`
}); });
} } else if (ex.message.includes('Unauthorized')) {
if (ex.message.includes('Unauthorized')) {
currentChatMessages.value.push({ currentChatMessages.value.push({
role: 'assistant', role: 'assistant',
content: 'To use AI you need to provide AI_ORG, AI_PROJECT and AI_KEY in docker compose', 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, });
} }
loading.value = false;
currentChatMessages.value.push({ role: 'assistant', content: ex.message, });
canSend.value = true; canSend.value = true;