@@ -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 ( / \[ \{ G E N _ I M G : " ( .* ?) " \} \] / ) ;
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