2222 padding : 10px ;
2323 border : # 90909075 ;
2424 border-style : solid;
25- max-height : 200 px ;
25+ max-height : 320 px ;
2626 overflow : auto;
27+ margin-bottom : 10px ;
2728 }
2829
2930 .message-output > img {
@@ -1574,23 +1575,28 @@ <h3 class="text-center">Welcome to BioImage.IO Chatbot</h3>
15741575 }
15751576 }
15761577
1577- window . generateResponse = async function ( ) {
1578+ window . generateResponse = async function ( chatIndex ) {
1579+ let fullTextMessage = textMessage ;
15781580 if ( envPrompt && envPrompt . length > 0 ) {
1579- textMessage = envPrompt + textMessage
1581+ fullTextMessage = envPrompt + fullTextMessage
15801582 }
15811583 $ ( "#regenerate-btn-small" ) . remove ( ) ;
15821584 $ ( "#" + currentMessageId ) . append ( spinner ) ;
15831585 // disable send message
15841586 $ ( '#send-btn' ) . prop ( 'disabled' , true ) ;
15851587 try {
1588+ // fix chat_history to chatIndex
1589+ chat_history . length = chatIndex ;
15861590 // Call the chat function with text and image data
1587- response = await svc . chat ( textMessage , chat_history , user_profile , statusCallback , sessionId , getSelectedExtensions ( ) , assistantName ) ;
1591+ response = await svc . chat ( fullTextMessage , chat_history , user_profile , statusCallback , sessionId , getSelectedExtensions ( ) , assistantName ) ;
15881592 // const regex = /!\[.*?\]\(data:.+?\)/g;
15891593 // const replacementText = '`image placeholder`';
15901594 // responseWithoutImage = response.replace(regex, replacementText);
15911595 console . log ( response )
15921596 chat_history . push ( { role : 'user' , content : textMessage } ) ;
15931597 chat_history . push ( { role : 'assistant' , content : response . text } ) ;
1598+ console . log ( "Current Text message:" , fullTextMessage ) ;
1599+ console . log ( "Current Chat history:" , chat_history ) ;
15941600 // Convert the message to HTML using the marked library
15951601 const steps = response . steps ;
15961602 let message = response . text && marked ( response . text , { renderer : renderer } ) || "" ;
@@ -1609,23 +1615,23 @@ <h3 class="text-center">Welcome to BioImage.IO Chatbot</h3>
16091615 throw e
16101616 }
16111617 finally {
1612- $ ( "#" + currentMessageId ) . append ( `<button class="small-grey-button" style="color:gray" id="regenerate-btn-small" onclick="generateResponse()"><i class="fas fa-redo"></i></button>` ) ;
1618+ $ ( "#" + currentMessageId ) . append ( `<button class="small-grey-button" style="color:gray" id="regenerate-btn-small" onclick="generateResponse(${ chatIndex } )"><i class="fas fa-redo"></i></button>` ) ;
16131619 // remove spinner
16141620 $ ( '.spinner' ) . remove ( ) ;
16151621 showReadyStatus ( ) ;
16161622 }
16171623 }
1618-
1624+ const chatIndex = chat_history . length ;
16191625 try {
1620- await window . generateResponse ( ) ;
1626+ await window . generateResponse ( chatIndex ) ;
16211627 }
16221628 catch ( e ) {
16231629 // generate an error message to simulate how Melman from Madagascar would respond to an error
16241630 const message = marked ( "Oh no! I'm sorry, an unexpected error occurred. Please try again." , { renderer : renderer } )
16251631 $ ( `#content-${ currentMessageId } ` ) . html ( message + `<button class="btn btn-info" id="regenerate-btn"><i class="fas fa-sync-alt"></i>Regenerate</button>` ) ;
16261632 $ ( '#regenerate-btn' ) . click ( async function ( ) {
16271633 $ ( `#content-${ currentMessageId } ` ) . html ( "Regenerating response..." ) ;
1628- await window . generateResponse ( ) ;
1634+ await window . generateResponse ( chatIndex ) ;
16291635 } )
16301636 showErrorStatus ( `The server failed to respond, please try again. ${ e } ` ) ;
16311637 console . error ( e ) ;
0 commit comments