@@ -413,6 +413,95 @@ <h3 class="card-title">🌱 Expert Recommendations</h3>
413413 addMessage ( 'bot' , recContainer ) ;
414414 }
415415
416+
417+ // Integrated JSON configuration
418+ const IMAGE_GEN_CONFIG = {
419+ prompt : "Generate a high-quality, detailed satellite image view..." ,
420+ negative_prompt : "cartoon, drawing, illustration..." ,
421+ style_raw : "photorealistic, remote sensing data visualization" ,
422+ aspect_ratio : "16:9" ,
423+ image_description : "This high-quality image depicts..."
424+ } ;
425+
426+ // Modified handleSend function with JSON integration
427+ async function handleSend ( ) {
428+ const message = userInput . value . trim ( ) ;
429+ if ( ! message && ! currentImage ) return ;
430+
431+ if ( message ) addMessage ( 'user' , message ) ;
432+ userInput . value = '' ;
433+
434+ try {
435+ const messages = [ {
436+ role : "system" ,
437+ content : `As an agricultural imaging specialist, analyze inputs using these guidelines:
438+ ${ IMAGE_GEN_CONFIG . prompt }
439+ Avoid: ${ IMAGE_GEN_CONFIG . negative_prompt }
440+ Style: ${ IMAGE_GEN_CONFIG . style_raw }
441+ Format: ${ IMAGE_GEN_CONFIG . image_description } `
442+ } ] ;
443+
444+ const content = [ ] ;
445+ if ( message ) content . push ( { type : 'text' , text : message } ) ;
446+ if ( currentImage ) content . push ( {
447+ type : 'image_url' ,
448+ image_url : { url : currentImage , detail : 'high' }
449+ } ) ;
450+
451+ messages . push ( { role : 'user' , content } ) ;
452+
453+ const response = await fetch ( endpoint , {
454+ method : 'POST' ,
455+ headers : {
456+ 'Content-Type' : 'application/json' ,
457+ 'Authorization' : `Bearer ${ apiKey } `
458+ } ,
459+ body : JSON . stringify ( {
460+ messages : messages ,
461+ temperature : 0.7 ,
462+ max_tokens : 1000
463+ } )
464+ } ) ;
465+
466+ if ( ! response . ok ) throw new Error ( `API Error: ${ response . statusText } ` ) ;
467+
468+ const data = await response . json ( ) ;
469+ const botResponse = data . choices [ 0 ] . message . content ;
470+ displayEnhancedResponse ( botResponse ) ;
471+ currentImage = null ;
472+
473+ } catch ( error ) {
474+ console . error ( 'Error:' , error ) ;
475+ addMessage ( 'bot' , `Error: ${ error . message } ` ) ;
476+ }
477+ }
478+
479+ // Enhanced response display with JSON template
480+ function displayEnhancedResponse ( response ) {
481+ const container = document . createElement ( 'div' ) ;
482+
483+ // Merge JSON template with AI response
484+ const fullResponse = `
485+ ${ response }
486+
487+ <div class="recommendation-card">
488+ <h4>Image Generation Specs</h4>
489+ <p>Aspect Ratio: ${ IMAGE_GEN_CONFIG . aspect_ratio } </p>
490+ <p>Style: ${ IMAGE_GEN_CONFIG . style_raw } </p>
491+ <p>Negative Guidance: ${ IMAGE_GEN_CONFIG . negative_prompt } </p>
492+ </div>
493+ ` ;
494+
495+ const formattedResponse = fullResponse
496+ . replace ( / # # \s ( .+ ?) \n / g, '<h3>$1</h3>' )
497+ . replace ( / - ( .+ ?) \n / g, '<div class="recommendation-card">$1</div>' )
498+ . replace ( / ( h t t p s ? : \/ \/ [ ^ \s ] + ) / g, '<a class="fao-link" href="$1" target="_blank">$1</a>' ) ;
499+
500+ container . innerHTML = formattedResponse ;
501+ addMessage ( 'bot' , container ) ;
502+ }
503+
504+
416505// Handle Enter key press
417506
418507userInput . addEventListener ( 'keypress' , ( e ) => {
0 commit comments