@@ -124,38 +124,41 @@ export class ChatController implements ReactiveController {
124124
125125 // Check if message is a bot message to process citations and follow-up questions 
126126
127-  let  messageToUpdate  =  response ; 
128- 
129-  if  ( ! useStream  &&  ! isUserMessage  &&  typeof  response  !==  'string' )  { 
130-  const  generatedResponse  =  ( response  as  BotResponse ) . choices [ 0 ] . message ; 
127+  if  ( isUserMessage  ||  typeof  response  ===  'string' )  { 
128+  await  updateChatWithMessageOrChunk ( response ,  false ) ; 
129+  }  else  if  ( useStream )  { 
130+  await  updateChatWithMessageOrChunk ( response ,  true ) ; 
131+  }  else  { 
131132 // non-streamed response 
133+  const  generatedResponse  =  ( response  as  BotResponse ) . choices [ 0 ] . message ; 
132134 const  processedText  =  processText ( generatedResponse . content ,  [ citations ,  followingSteps ,  followupQuestions ] ) ; 
133-  messageToUpdate  =  processedText . replacedText ; 
135+  const   messageToUpdate  =  processedText . replacedText ; 
134136 // Push all lists coming from processText to the corresponding arrays 
135137 citations . push ( ...( processedText . arrays [ 0 ]  as  unknown  as  Citation [ ] ) ) ; 
136138 followingSteps . push ( ...( processedText . arrays [ 1 ]  as  string [ ] ) ) ; 
137139 followupQuestions . push ( ...( processedText . arrays [ 2 ]  as  string [ ] ) ) ; 
138140 thoughts  =  generatedResponse . context ?. thoughts  ??  '' ; 
139141 dataPoints  =  generatedResponse . context ?. data_points  ??  [ ] ; 
140-  } 
141142
142-  await  updateChatWithMessageOrChunk ( messageToUpdate ,  ! isUserMessage  &&  useStream ) ; 
143+  await  updateChatWithMessageOrChunk ( messageToUpdate ,  false ) ; 
144+  } 
143145 } 
144146
145147 async  generateAnswer ( requestOptions : ChatRequestOptions ,  httpOptions : ChatHttpOptions )  { 
146148 const  {  question }  =  requestOptions ; 
147149
148150 if  ( question )  { 
149151 try  { 
150-  this . processingMessage  =  undefined ; 
151152 this . generatingAnswer  =  true ; 
152-  this . isAwaitingResponse  =  true ; 
153153
154154 // for chat messages, process user question as a chat entry 
155155 if  ( requestOptions . type  ===  'chat' )  { 
156156 await  this . processResponse ( question ,  true ,  false ) ; 
157157 } 
158158
159+  this . isAwaitingResponse  =  true ; 
160+  this . processingMessage  =  undefined ; 
161+ 
159162 const  response  =  ( await  getAPIResponse ( requestOptions ,  httpOptions ) )  as  BotResponse ; 
160163 this . isAwaitingResponse  =  false ; 
161164
0 commit comments