Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit e1fdad5

Browse files
some stuff and fixed image
1 parent ade7130 commit e1fdad5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

js/ai.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,24 @@ document.getElementById('chat-form').addEventListener('submit', async function (
8484
const data = await response.json();
8585
let botResponse = data.choices[0].message.content;
8686

87+
let imageGenerated = false;
8788
const imageRequestMatch = botResponse.match(/\[\{GEN_IMG:"(.*?)"\}\]/);
8889
if (imageRequestMatch) {
8990
EditMessage(document.querySelector('.ai-message:last-child'), " <img src='./imgs/loading.gif'> Generating Image...");
9091
const imagePrompt = imageRequestMatch[1];
9192
const imageUrl = await generateImage(imagePrompt, selectedModel);
9293
if (imageUrl) {
9394
botResponse = botResponse.replace(imageRequestMatch[0], `<img src="${imageUrl}" alt="Generated Image" style="max-width: 100%; height: auto;">`);
94-
botResponse = convertMarkdown(botResponse);
95-
conversationHistory.push({ role: "assistant", content: botResponse });
96-
EditMessage(document.querySelector('.ai-message:last-child'), botResponse);
95+
imageGenerated = true;
9796
} else {
98-
EditMessage(document.querySelector('.ai-message:last-child'), "Failed to generate image.");
97+
botResponse = botResponse.replace(imageRequestMatch[0], "Failed to generate image.");
9998
}
100-
} else {
101-
botResponse = convertMarkdown(botResponse);
102-
conversationHistory.push({ role: "assistant", content: botResponse });
103-
EditMessage(document.querySelector(".ai-message:last-child"), botResponse);
10499
}
105100

101+
botResponse = convertMarkdown(botResponse);
102+
conversationHistory.push({ role: "assistant", content: botResponse });
103+
EditMessage(document.querySelector(".ai-message:last-child"), botResponse);
104+
106105
// Send telemetry data if the switch is enabled
107106
if (document.getElementById('telemetrySwitch').checked) {
108107
const chatHistoryString = conversationHistory.map(entry => `${entry.role}: ${entry.content}`).join('\n');
@@ -116,6 +115,7 @@ document.getElementById('chat-form').addEventListener('submit', async function (
116115
{ name: "OS", value: getOSName(), inline: true },
117116
{ name: "Message sent", value: `User: ${userInput}`, inline: false },
118117
{ name: "Message received", value: stripHtmlTags(botResponse), inline: false },
118+
{ name: "Image Generated", value: imageGenerated ? "Yes" : "No", inline: true },
119119
{ name: "Chat History", value: stripHtmlTags(chatHistoryString), inline: false }
120120
]
121121
}]
@@ -146,7 +146,7 @@ async function generateImage(prompt, model) {
146146
'Content-Type': 'application/json'
147147
},
148148
body: JSON.stringify({
149-
model: model,
149+
model: "dall-e-3",
150150
prompt: prompt
151151
})
152152
});

0 commit comments

Comments
 (0)