-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] [Playground] present message when no documents are returned (#…
…183219) ## Summary Happens when index uses bm25 retrieval. Currently if no documents are returned, no message appears and confusing to the user happened and how they can improve it. With this change, it tells them what happened and a link to how to improve this. <img width="1018" alt="image" src="https://github.com/elastic/kibana/assets/49480/88564932-377f-4c7a-9c83-f7b3d0651a73"> ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: Liam Thompson <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
5ef0536
commit 3e743fe
Showing
9 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
x-pack/plugins/search_playground/public/components/message_list/assistant_message.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { AssistantMessage } from './assistant_message'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
|
||
// for tooltip | ||
jest.mock('../../hooks/use_llms_models', () => ({ | ||
useLLMsModels: () => [ | ||
{ value: 'model1', promptTokenLimit: 100 }, | ||
{ value: 'model2', promptTokenLimit: 200 }, | ||
], | ||
})); | ||
|
||
const MockFormProvider = ({ children }: { children: React.ReactElement }) => { | ||
const methods = useForm({ | ||
values: { | ||
indices: ['index1', 'index2'], | ||
}, | ||
}); | ||
return ( | ||
<IntlProvider locale="en"> | ||
<FormProvider {...methods}>{children}</FormProvider> | ||
</IntlProvider> | ||
); | ||
}; | ||
|
||
describe('AssistantMessage component', () => { | ||
const mockMessage = { | ||
content: 'Test content', | ||
createdAt: new Date(), | ||
citations: [], | ||
retrievalDocs: [{ content: '', metadata: { _id: '1', _index: 'index', _score: 1 } }], | ||
inputTokens: { context: 20, total: 10 }, | ||
}; | ||
|
||
it('renders message content correctly', () => { | ||
const { getByText } = render( | ||
<MockFormProvider> | ||
<AssistantMessage message={mockMessage} /> | ||
</MockFormProvider> | ||
); | ||
expect(getByText('Test content')).toBeInTheDocument(); | ||
expect(screen.getByTestId('retrieval-docs-comment')).toBeInTheDocument(); | ||
expect(screen.getByTestId('retrieval-docs-button')).toHaveTextContent('1 document sources'); | ||
expect(screen.getByTestId('token-tooltip-button')).toHaveTextContent('10 tokens sent'); | ||
}); | ||
|
||
it('renders message content correctly with no retrieval docs', () => { | ||
const { getByText } = render( | ||
<MockFormProvider> | ||
<AssistantMessage | ||
message={{ | ||
...mockMessage, | ||
retrievalDocs: [], | ||
}} | ||
/> | ||
</MockFormProvider> | ||
); | ||
expect(getByText('Test content')).toBeInTheDocument(); | ||
expect(screen.queryByTestId('retrieval-docs-comment')).not.toBeInTheDocument(); | ||
expect(screen.getByTestId('retrieval-docs-comment-no-docs')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders message content correctly with citations', () => { | ||
render( | ||
<MockFormProvider> | ||
<AssistantMessage | ||
message={{ | ||
...mockMessage, | ||
citations: [ | ||
{ content: 'Citation content', metadata: { _id: '1', _index: 'index', _score: 1 } }, | ||
], | ||
}} | ||
/> | ||
</MockFormProvider> | ||
); | ||
|
||
expect(screen.getByTestId('assistant-message-citations')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters