@@ -58,6 +58,8 @@ import { useLazyGetRelevantDocumentsQuery } from '../../shared/reducers/rag.redu
58
58
import { IConfiguration } from '../../shared/model/configuration.model' ;
59
59
import { DocumentSummarizationModal } from './DocumentSummarizationModal' ;
60
60
import { ChatMemory } from '../../shared/util/chat-memory' ;
61
+ import { setBreadcrumbs } from '../../shared/reducers/breadcrumbs.reducer' ;
62
+ import { truncateText } from '../../shared/util/formats' ;
61
63
62
64
export default function Chat ( { sessionId } ) {
63
65
const dispatch = useAppDispatch ( ) ;
@@ -87,13 +89,15 @@ export default function Chat ({ sessionId }) {
87
89
88
90
const modelsOptions = useMemo ( ( ) => allModels . map ( ( model ) => ( { label : model . modelId , value : model . modelId } ) ) , [ allModels ] ) ;
89
91
const [ selectedModel , setSelectedModel ] = useState < IModel > ( ) ;
92
+ const [ dirtySession , setDirtySession ] = useState ( false ) ;
90
93
const [ session , setSession ] = useState < LisaChatSession > ( {
91
94
history : [ ] ,
92
95
sessionId : '' ,
93
96
userId : '' ,
94
97
startTime : new Date ( Date . now ( ) ) . toISOString ( ) ,
95
98
} ) ;
96
99
const [ internalSessionId , setInternalSessionId ] = useState < string | null > ( null ) ;
100
+ const [ loadingSession , setLoadingSession ] = useState ( false ) ;
97
101
98
102
const [ isConnected , setIsConnected ] = useState ( false ) ;
99
103
const [ metadata , setMetadata ] = useState < LisaChatMessageMetadata > ( { } ) ;
@@ -126,8 +130,8 @@ export default function Chat ({ sessionId }) {
126
130
input : ( previousOutput : any ) => previousOutput . input ,
127
131
context : ( previousOutput : any ) => previousOutput . context ,
128
132
history : ( previousOutput : any ) => previousOutput . memory ?. history || '' ,
129
- aiPrefix : ( previousOutput : any ) => previousOutput . aiPrefix ,
130
- humanPrefix : ( previousOutput : any ) => previousOutput . humanPrefix ,
133
+ aiPrefix : ( ) => chatConfiguration . promptConfiguration . aiPrefix ,
134
+ humanPrefix : ( ) => chatConfiguration . promptConfiguration . humanPrefix ,
131
135
} ;
132
136
133
137
const chainSteps = [
@@ -226,8 +230,8 @@ export default function Chat ({ sessionId }) {
226
230
input : ( initialInput : any ) => initialInput . input ,
227
231
memory : ( ) => memory . loadMemoryVariables ( ) ,
228
232
context : ( ) => fileContext || '' ,
229
- humanPrefix : ( initialInput : any ) => initialInput . humanPrefix ,
230
- aiPrefix : ( initialInput : any ) => initialInput . aiPrefix ,
233
+ humanPrefix : ( ) => chatConfiguration . promptConfiguration . humanPrefix ,
234
+ aiPrefix : ( ) => chatConfiguration . promptConfiguration . aiPrefix ,
231
235
} ;
232
236
233
237
chainSteps . unshift ( nonRagStep ) ;
@@ -322,17 +326,27 @@ export default function Chat ({ sessionId }) {
322
326
} , [ auth , getConfiguration ] ) ;
323
327
324
328
useEffect ( ( ) => {
325
- if ( ! isRunning && session . history . length ) {
329
+ if ( ! isRunning && session . history . length && dirtySession ) {
326
330
if ( session . history . at ( - 1 ) . type === 'ai' && ! auth . isLoading ) {
331
+ setDirtySession ( false ) ;
327
332
updateSession ( session ) ;
328
333
}
329
334
}
330
- // eslint-disable-next-line react-hooks/exhaustive-deps
331
- } , [ isRunning , session , auth ] ) ;
335
+ } , [ isRunning , session , dirtySession , auth , updateSession ] ) ;
332
336
333
337
useEffect ( ( ) => {
334
338
if ( sessionId ) {
335
339
setInternalSessionId ( sessionId ) ;
340
+ setLoadingSession ( true ) ;
341
+ setSession ( { ...session , history : [ ] } ) ;
342
+ dispatch ( setBreadcrumbs ( [ {
343
+ text : 'Chatbot' ,
344
+ href : ''
345
+ } , {
346
+ text : 'Loading session...' ,
347
+ href : ''
348
+ } ] ) ) ;
349
+
336
350
getSessionById ( sessionId ) . then ( ( resp ) => {
337
351
// session doesn't exist so we create it
338
352
let sess : LisaChatSession = resp . data ;
@@ -345,6 +359,16 @@ export default function Chat ({ sessionId }) {
345
359
} ;
346
360
}
347
361
setSession ( sess ) ;
362
+
363
+ // override the default breadcrumbs
364
+ dispatch ( setBreadcrumbs ( [ {
365
+ text : 'Chatbot' ,
366
+ href : ''
367
+ } , {
368
+ text : truncateText ( sess . history ?. [ 0 ] ?. content ?. toString ( ) ) || 'New Session' ,
369
+ href : ''
370
+ } ] ) ) ;
371
+ setLoadingSession ( false ) ;
348
372
} ) ;
349
373
} else {
350
374
const newSessionId = uuidv4 ( ) ;
@@ -497,6 +521,7 @@ export default function Chat ({ sessionId }) {
497
521
message : message
498
522
} ) ;
499
523
524
+ setDirtySession ( true ) ;
500
525
} , [ userPrompt , useRag , fileContext , chatConfiguration . promptConfiguration . aiPrefix , chatConfiguration . promptConfiguration . humanPrefix , chatConfiguration . promptConfiguration . promptTemplate , generateResponse ] ) ;
501
526
502
527
return (
@@ -547,9 +572,9 @@ export default function Chat ({ sessionId }) {
547
572
< div className = 'overflow-y-auto h-[calc(100vh-25rem)] bottom-8' >
548
573
< SpaceBetween direction = 'vertical' size = 'l' >
549
574
{ session . history . map ( ( message , idx ) => (
550
- < Message key = { idx } message = { message } showMetadata = { chatConfiguration . sessionConfiguration . showMetadata } isRunning = { false } isStreaming = { isStreaming && idx === session . history . length - 1 } />
575
+ < Message key = { idx } message = { message } showMetadata = { chatConfiguration . sessionConfiguration . showMetadata } isRunning = { false } isStreaming = { isStreaming && idx === session . history . length - 1 } markdownDisplay = { chatConfiguration . sessionConfiguration . markdownDisplay } />
551
576
) ) }
552
- { isRunning && ! isStreaming && < Message isRunning = { isRunning } /> }
577
+ { isRunning && ! isStreaming && < Message isRunning = { isRunning } markdownDisplay = { chatConfiguration . sessionConfiguration . markdownDisplay } /> }
553
578
< div ref = { bottomRef } />
554
579
</ SpaceBetween >
555
580
</ div >
@@ -609,9 +634,9 @@ export default function Chat ({ sessionId }) {
609
634
placeholder = {
610
635
! selectedModel ? 'You must select a model before sending a message' : 'Send a message'
611
636
}
612
- disabled = { ! selectedModel }
637
+ disabled = { ! selectedModel || loadingSession }
613
638
onChange = { ( { detail } ) => setUserPrompt ( detail . value ) }
614
- onAction = { userPrompt . length > 0 && ! isRunning && handleSendGenerateRequest }
639
+ onAction = { userPrompt . length > 0 && ! isRunning && ! loadingSession && handleSendGenerateRequest }
615
640
secondaryActions = {
616
641
< Box padding = { { left : 'xxs' , top : 'xs' } } >
617
642
< ButtonGroup
0 commit comments