-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reset chat or reload history after data source change #194
Changes from 4 commits
a4954bf
adb38cc
07eae19
f3e4aab
dc465d2
7590f93
b84272b
418f84c
4a7328c
13f2b1d
7981746
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,15 @@ export const useChatActions = (): AssistantActions => { | |
} | ||
}; | ||
|
||
const resetChat = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you simply call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
abortControllerRef?.abort(); | ||
core.services.conversationLoad.abortController?.abort(); | ||
chatContext.setConversationId(undefined); | ||
chatContext.setTitle(undefined); | ||
chatContext.setFlyoutComponent(null); | ||
chatStateDispatch({ type: 'reset' }); | ||
}; | ||
|
||
const openChatUI = () => { | ||
chatContext.setFlyoutVisible(true); | ||
chatContext.setSelectedTabId(TAB_ID.CHAT); | ||
|
@@ -225,5 +234,5 @@ export const useChatActions = (): AssistantActions => { | |
} | ||
}; | ||
|
||
return { send, loadChat, executeAction, openChatUI, abortAction, regenerate }; | ||
return { send, loadChat, resetChat, executeAction, openChatUI, abortAction, regenerate }; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
*/ | ||
|
||
import { BehaviorSubject, Subscription, combineLatest, of } from 'rxjs'; | ||
import { first, map } from 'rxjs/operators'; | ||
import { distinctUntilChanged, first, map } from 'rxjs/operators'; | ||
|
||
import type { IUiSettingsClient } from '../../../../src/core/public'; | ||
import type { DataSourceOption } from '../../../../src/plugins/data_source_management/public/components/data_source_menu/types'; | ||
|
@@ -74,24 +74,23 @@ export class DataSourceService { | |
} | ||
|
||
setDataSourceId(newDataSourceId: string | null) { | ||
if (this.dataSourceId$.getValue() === newDataSourceId) { | ||
return; | ||
} | ||
Comment on lines
-77
to
-79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate more on why we remove duplicate check in set function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we already add |
||
this.dataSourceId$.next(newDataSourceId); | ||
} | ||
|
||
getDataSourceId$() { | ||
return combineLatest([ | ||
this.dataSourceId$, | ||
this.dataSourceManagement?.getDefaultDataSourceId$?.(this.uiSettings) ?? of(null), | ||
]).pipe( | ||
map(([selectedDataSourceId, defaultDataSourceId]) => { | ||
if (selectedDataSourceId !== null) { | ||
return selectedDataSourceId; | ||
} | ||
return defaultDataSourceId; | ||
}) | ||
); | ||
]) | ||
.pipe( | ||
map(([selectedDataSourceId, defaultDataSourceId]) => { | ||
if (selectedDataSourceId !== null) { | ||
return selectedDataSourceId; | ||
} | ||
return defaultDataSourceId; | ||
}) | ||
) | ||
.pipe(distinctUntilChanged()); | ||
} | ||
|
||
setup({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use the
props.assistantActions.resetChat
without a ref?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested in my local machine, the
props.assistantActions.resetChat
will be changed after chat button render. ThegetDataSourceId$
will be executed multi times. It's OK to change to useprops.assistantActions.resetChat
directly.