@@ -142,7 +142,7 @@ const Chat = () => {
142142 }
143143
144144 const processResultMessage = ( resultMessage : ChatMessage , userMessage : ChatMessage , conversationId ?: string ) => {
145- if ( resultMessage . content . includes ( 'all_exec_results' ) ) {
145+ if ( typeof resultMessage . content === "string" && resultMessage . content . includes ( 'all_exec_results' ) ) {
146146 const parsedExecResults = JSON . parse ( resultMessage . content ) as AzureSqlServerExecResults
147147 setExecResults ( parsedExecResults . all_exec_results )
148148 assistantMessage . context = JSON . stringify ( {
@@ -179,24 +179,27 @@ const Chat = () => {
179179 }
180180 }
181181
182- const makeApiRequestWithoutCosmosDB = async ( question : string , conversationId ?: string ) => {
182+ const makeApiRequestWithoutCosmosDB = async ( question : ChatMessage [ "content" ] , conversationId ?: string ) => {
183183 setIsLoading ( true )
184184 setShowLoadingMessage ( true )
185185 const abortController = new AbortController ( )
186186 abortFuncs . current . unshift ( abortController )
187187
188+ const questionContent = typeof question === 'string' ? question : [ { type : "text" , text : question [ 0 ] . text } , { type : "image_url" , image_url : { url : question [ 1 ] . image_url . url } } ]
189+ question = typeof question !== 'string' && question [ 0 ] ?. text ?. length > 0 ? question [ 0 ] . text : question
190+
188191 const userMessage : ChatMessage = {
189192 id : uuid ( ) ,
190193 role : 'user' ,
191- content : question ,
194+ content : questionContent as string ,
192195 date : new Date ( ) . toISOString ( )
193196 }
194197
195198 let conversation : Conversation | null | undefined
196199 if ( ! conversationId ) {
197200 conversation = {
198201 id : conversationId ?? uuid ( ) ,
199- title : question ,
202+ title : question as string ,
200203 messages : [ userMessage ] ,
201204 date : new Date ( ) . toISOString ( )
202205 }
@@ -303,20 +306,21 @@ const Chat = () => {
303306 return abortController . abort ( )
304307 }
305308
306- const makeApiRequestWithCosmosDB = async ( question : string , conversationId ?: string ) => {
309+ const makeApiRequestWithCosmosDB = async ( question : ChatMessage [ "content" ] , conversationId ?: string ) => {
307310 setIsLoading ( true )
308311 setShowLoadingMessage ( true )
309312 const abortController = new AbortController ( )
310313 abortFuncs . current . unshift ( abortController )
314+ const questionContent = typeof question === 'string' ? question : [ { type : "text" , text : question [ 0 ] . text } , { type : "image_url" , image_url : { url : question [ 1 ] . image_url . url } } ]
315+ question = typeof question !== 'string' && question [ 0 ] ?. text ?. length > 0 ? question [ 0 ] . text : question
311316
312317 const userMessage : ChatMessage = {
313318 id : uuid ( ) ,
314319 role : 'user' ,
315- content : question ,
320+ content : questionContent as string ,
316321 date : new Date ( ) . toISOString ( )
317322 }
318323
319- //api call params set here (generate)
320324 let request : ConversationRequest
321325 let conversation
322326 if ( conversationId ) {
@@ -648,7 +652,7 @@ const Chat = () => {
648652 }
649653 const noContentError = appStateContext . state . currentChat . messages . find ( m => m . role === ERROR )
650654
651- if ( ! noContentError ?. content . includes ( NO_CONTENT_ERROR ) ) {
655+ if ( typeof noContentError ?. content === "string" && ! noContentError ?. content . includes ( NO_CONTENT_ERROR ) ) {
652656 saveToDB ( appStateContext . state . currentChat . messages , appStateContext . state . currentChat . id )
653657 . then ( res => {
654658 if ( ! res . ok ) {
@@ -713,7 +717,7 @@ const Chat = () => {
713717 }
714718
715719 const parseCitationFromMessage = ( message : ChatMessage ) => {
716- if ( message ?. role && message ?. role === 'tool' ) {
720+ if ( message ?. role && message ?. role === 'tool' && typeof message ?. content === "string" ) {
717721 try {
718722 const toolMessage = JSON . parse ( message . content ) as ToolMessageContent
719723 return toolMessage . citations
@@ -725,7 +729,7 @@ const Chat = () => {
725729 }
726730
727731 const parsePlotFromMessage = ( message : ChatMessage ) => {
728- if ( message ?. role && message ?. role === "tool" ) {
732+ if ( message ?. role && message ?. role === "tool" && typeof message ?. content === "string" ) {
729733 try {
730734 const execResults = JSON . parse ( message . content ) as AzureSqlServerExecResults ;
731735 const codeExecResult = execResults . all_exec_results . at ( - 1 ) ?. code_exec_result ;
@@ -797,11 +801,13 @@ const Chat = () => {
797801 < >
798802 { answer . role === 'user' ? (
799803 < div className = { styles . chatMessageUser } tabIndex = { 0 } >
800- < div className = { styles . chatMessageUserMessage } > { answer . content } </ div >
804+ < div className = { styles . chatMessageUserMessage } >
805+ { typeof answer . content === "string" && answer . content ? answer . content : Array . isArray ( answer . content ) ? < > { answer . content [ 0 ] . text } < img className = { styles . uploadedImageChat } src = { answer . content [ 1 ] . image_url . url } alt = "Uploaded Preview" /> </ > : null }
806+ </ div >
801807 </ div >
802808 ) : answer . role === 'assistant' ? (
803809 < div className = { styles . chatMessageGpt } >
804- < Answer
810+ { typeof answer . content === "string" && < Answer
805811 answer = { {
806812 answer : answer . content ,
807813 citations : parseCitationFromMessage ( messages [ index - 1 ] ) ,
@@ -812,15 +818,15 @@ const Chat = () => {
812818 } }
813819 onCitationClicked = { c => onShowCitation ( c ) }
814820 onExectResultClicked = { ( ) => onShowExecResult ( answerId ) }
815- />
821+ /> }
816822 </ div >
817823 ) : answer . role === ERROR ? (
818824 < div className = { styles . chatMessageError } >
819825 < Stack horizontal className = { styles . chatMessageErrorContent } >
820826 < ErrorCircleRegular className = { styles . errorIcon } style = { { color : 'rgba(182, 52, 67, 1)' } } />
821827 < span > Error</ span >
822828 </ Stack >
823- < span className = { styles . chatMessageErrorContent } > { answer . content } </ span >
829+ < span className = { styles . chatMessageErrorContent } > { typeof answer . content === "string" && answer . content } </ span >
824830 </ div >
825831 ) : null }
826832 </ >
0 commit comments