From e1fdad562397ce9ee52dcd91d2394852ccd8f7c5 Mon Sep 17 00:00:00 2001 From: JustablockCode Date: Sat, 16 Nov 2024 13:28:08 +0100 Subject: [PATCH] some stuff and fixed image --- js/ai.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/ai.js b/js/ai.js index 41a0033..54d81e2 100644 --- a/js/ai.js +++ b/js/ai.js @@ -84,6 +84,7 @@ document.getElementById('chat-form').addEventListener('submit', async function ( const data = await response.json(); let botResponse = data.choices[0].message.content; + let imageGenerated = false; const imageRequestMatch = botResponse.match(/\[\{GEN_IMG:"(.*?)"\}\]/); if (imageRequestMatch) { EditMessage(document.querySelector('.ai-message:last-child'), " Generating Image..."); @@ -91,18 +92,16 @@ document.getElementById('chat-form').addEventListener('submit', async function ( const imageUrl = await generateImage(imagePrompt, selectedModel); if (imageUrl) { botResponse = botResponse.replace(imageRequestMatch[0], `Generated Image`); - botResponse = convertMarkdown(botResponse); - conversationHistory.push({ role: "assistant", content: botResponse }); - EditMessage(document.querySelector('.ai-message:last-child'), botResponse); + imageGenerated = true; } else { - EditMessage(document.querySelector('.ai-message:last-child'), "Failed to generate image."); + botResponse = botResponse.replace(imageRequestMatch[0], "Failed to generate image."); } - } else { - botResponse = convertMarkdown(botResponse); - conversationHistory.push({ role: "assistant", content: botResponse }); - EditMessage(document.querySelector(".ai-message:last-child"), botResponse); } + botResponse = convertMarkdown(botResponse); + conversationHistory.push({ role: "assistant", content: botResponse }); + EditMessage(document.querySelector(".ai-message:last-child"), botResponse); + // Send telemetry data if the switch is enabled if (document.getElementById('telemetrySwitch').checked) { const chatHistoryString = conversationHistory.map(entry => `${entry.role}: ${entry.content}`).join('\n'); @@ -116,6 +115,7 @@ document.getElementById('chat-form').addEventListener('submit', async function ( { name: "OS", value: getOSName(), inline: true }, { name: "Message sent", value: `User: ${userInput}`, inline: false }, { name: "Message received", value: stripHtmlTags(botResponse), inline: false }, + { name: "Image Generated", value: imageGenerated ? "Yes" : "No", inline: true }, { name: "Chat History", value: stripHtmlTags(chatHistoryString), inline: false } ] }] @@ -146,7 +146,7 @@ async function generateImage(prompt, model) { 'Content-Type': 'application/json' }, body: JSON.stringify({ - model: model, + model: "dall-e-3", prompt: prompt }) });