Skip to content
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

Conversation

wanglam
Copy link
Collaborator

@wanglam wanglam commented May 30, 2024

Description

  1. Reset chat after data source change
  2. Reload history and reset search params after data source change
  3. Reset to chat tab when in trace tab

Issues Resolved

#192

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test.
  • New functionality has user manual doc added.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@wanglam wanglam added backport 2.x Trigger the backport flow to 2.x v2.15.0 labels May 30, 2024
Signed-off-by: Lin Wang <[email protected]>
}, [props.shouldRefresh, services.conversations]);

useEffect(() => {
services.conversations.load(bulkGetOptions);
const subscription = services.dataSource
.getDataSourceId$()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible that dataSourceId$ emit the same value one after another? In such case, I think we don't want to reload.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current implementation, the same value will be emit after default data source change. Do you have any suggestions about that? How about add a distinctUntilChanged?

}, [props.shouldRefresh, services.conversations]);

useEffect(() => {
services.conversations.load(bulkGetOptions);
const subscription = services.dataSource
.getDataSourceId$()
.pipe(skip(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave a comment to describe why it should skip the first value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, since the the conversations load will be called after mount. We skip the first value here to avoid duplicate load API request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we say that we are skipping the case that dataSource$ emits the same value? In that case we'd use distinctUntilChanged instead of skip the first value right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the same value. Since dataSourceId$ and defaultDataSourceId$ are BehaviorSubject. The observer will be executed once first subscribed. The observer will reload conversations history. Since we already call conversations.load after mount, skip first value here to avoid duplicate API call.

@@ -106,6 +106,15 @@ export const useChatActions = (): AssistantActions => {
}
};

const resetChat = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you simply call loadChat without any parameter instead of creating a new method? we can call loadChat() to start a new conversation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loadChat only work when current tab is chat tab. The loadChat will set current tab to CHAT in this line. I think we can't change tab to CHAT if user is in history tab. So add a new resetChat here.

@@ -54,6 +56,9 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
const flyoutFullScreen = sidecarDockedMode === SIDECAR_DOCKED_MODE.TAKEOVER;
const flyoutMountPoint = useRef(null);

const resetChatRef = useRef(props.assistantActions.resetChat);
resetChatRef.current = props.assistantActions.resetChat;
Copy link
Member

@SuZhou-Joe SuZhou-Joe Jun 3, 2024

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?

Copy link
Collaborator Author

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. The getDataSourceId$ will be executed multi times. It's OK to change to use props.assistantActions.resetChat directly.

raintygao
raintygao previously approved these changes Jun 3, 2024
@raintygao raintygao self-requested a review June 3, 2024 11:00
Comment on lines -77 to -79
if (this.dataSourceId$.getValue() === newDataSourceId) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already add distinctUntilChanged in getDataSourceId$, the next value won't be the same. Then we can remove the duplicate check here.

@raintygao raintygao self-requested a review June 3, 2024 11:01
Copy link

codecov bot commented Jun 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.50%. Comparing base (3991de2) to head (dc465d2).
Report is 6 commits behind head on main.

Current head dc465d2 differs from pull request most recent head 7981746

Please upload reports for the commit 7981746 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
+ Coverage   90.02%   90.50%   +0.48%     
==========================================
  Files          54       57       +3     
  Lines        1433     1527      +94     
  Branches      347      361      +14     
==========================================
+ Hits         1290     1382      +92     
- Misses        141      143       +2     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hailong-am
Copy link
Collaborator

how about how was it generated(trace) page? I guess that page would need to reset if user in that page and datasource changed.

@wanglam
Copy link
Collaborator Author

wanglam commented Jun 5, 2024

how about how was it generated(trace) page? I guess that page would need to reset if user in that page and datasource changed.

Do you mean refresh how was it generated page when data source changed? I think it's a little bit confused. Because user won't get the trace info in another data source.

@Hailong-am
Copy link
Collaborator

how about how was it generated(trace) page? I guess that page would need to reset if user in that page and datasource changed.

Do you mean refresh how was it generated page when data source changed? I think it's a little bit confused. Because user won't get the trace info in another data source.

right, show existing trace data maybe confusing. how about reset to chat window?

@wanglam
Copy link
Collaborator Author

wanglam commented Jun 6, 2024

how about how was it generated(trace) page? I guess that page would need to reset if user in that page and datasource changed.

Do you mean refresh how was it generated page when data source changed? I think it's a little bit confused. Because user won't get the trace info in another data source.

right, show existing trace data maybe confusing. how about reset to chat window?

Thanks for suggestions, I've already updated this part.

Comment on lines 60 to 61
const bulkGetOptionsRef = useRef(bulkGetOptions);
bulkGetOptionsRef.current = bulkGetOptions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, can be removed.

@wanglam wanglam merged commit a2a98f6 into opensearch-project:main Jun 7, 2024
9 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 7, 2024
* reset chat or reload history when data source change

Signed-off-by: Lin Wang <[email protected]>

* Add change log

Signed-off-by: Lin Wang <[email protected]>

* Address PR comments

Signed-off-by: Lin Wang <[email protected]>

* Set search and page after data source change

Signed-off-by: Lin Wang <[email protected]>

* Remove skip first value when subscribe dataSourceId$

Signed-off-by: Lin Wang <[email protected]>

* Add dataSourceIdUdpates$ and finalDataSourceId

Signed-off-by: Lin Wang <[email protected]>

* Remove data source service mock in chat header button

Signed-off-by: Lin Wang <[email protected]>

* Remove no need useRef

Signed-off-by: Lin Wang <[email protected]>

* Refactor load history after data source change

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>
(cherry picked from commit a2a98f6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
wanglam pushed a commit that referenced this pull request Jun 7, 2024
* reset chat or reload history when data source change

Signed-off-by: Lin Wang <[email protected]>

* Add change log

Signed-off-by: Lin Wang <[email protected]>

* Address PR comments

Signed-off-by: Lin Wang <[email protected]>

* Set search and page after data source change

Signed-off-by: Lin Wang <[email protected]>

* Remove skip first value when subscribe dataSourceId$

Signed-off-by: Lin Wang <[email protected]>

* Add dataSourceIdUdpates$ and finalDataSourceId

Signed-off-by: Lin Wang <[email protected]>

* Remove data source service mock in chat header button

Signed-off-by: Lin Wang <[email protected]>

* Remove no need useRef

Signed-off-by: Lin Wang <[email protected]>

* Refactor load history after data source change

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>
(cherry picked from commit a2a98f6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Trigger the backport flow to 2.x v2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants