-
Notifications
You must be signed in to change notification settings - Fork 57
[Evals]: Create evaluation #3844
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
Open
priyanshu6238
wants to merge
19
commits into
master
Choose a base branch
from
feat/fix_create_evalution_page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9715331
feat: add create evaluation api + test case
priyanshu6238 6dc7f96
refactor: create evalution page
priyanshu6238 ea96b16
fix: trigger evulation page
priyanshu6238 f729f83
Merge branch 'master' into feat/fix_create_evalution_page
priyanshu6238 521ba67
fix: remove console log
priyanshu6238 bd65113
fix: deep scan
priyanshu6238 31b45ba
fix: reveret the text capital format to normal format
priyanshu6238 59db8c6
refactor: remove cancel button when evalution start
priyanshu6238 95990ef
fix: loading function in fetching assistnat config version
priyanshu6238 2bd31df
add: test case
priyanshu6238 84508a2
Merge remote-tracking branch 'origin/master' into feat/fix_create_eva…
priyanshu6238 a3e06ba
fix: payload
priyanshu6238 9e83a71
fix: test case
priyanshu6238 89b4ed0
fix: graph sql schema
priyanshu6238 bdb4b24
fix: create evaluation logic + test case
priyanshu6238 4eeaa70
fix: test case
priyanshu6238 12f10d9
fix: file format
priyanshu6238 5333756
Merge branch 'master' into feat/fix_create_evalution_page
priyanshu6238 fce4269
add: test case
priyanshu6238 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,21 +7,57 @@ import { | |
| createGoldenQaCustomSuccessMock, | ||
| createGoldenQaSuccessMock, | ||
| getAIEvaluationCreateMocks, | ||
| getAssistantConfigVersionsEmptyMock, | ||
| getAssistantConfigVersionsErrorMock, | ||
| getAssistantConfigVersionsLoadingMock, | ||
| getAssistantConfigVersionsMultipleNamesMock, | ||
| getAssistantConfigVersionsMock, | ||
| getCreateEvaluationSuccessMock, | ||
| getListAiEvaluationsMock, | ||
| } from 'mocks/AIEvaluations'; | ||
| import AIEvaluationCreate, { DUMMY_CREATE, DUMMY_GET_ITEM } from './AIEvaluationCreate'; | ||
| import { setNotification } from 'common/notification'; | ||
| import AIEvaluationCreate from './AIEvaluationCreate'; | ||
|
|
||
| const defaultMocks = getAIEvaluationCreateMocks(DUMMY_GET_ITEM, DUMMY_CREATE); | ||
| vi.mock('common/notification', () => ({ | ||
| setNotification: vi.fn(), | ||
| setErrorMessage: vi.fn(), | ||
| })); | ||
|
|
||
| const defaultMocks = getAIEvaluationCreateMocks(); | ||
|
|
||
| const wrapper = (mocks: any[] = defaultMocks) => ( | ||
| <MockedProvider mocks={mocks}> | ||
| <MemoryRouter initialEntries={['/ai-evaluations/create']}> | ||
| <Routes> | ||
| <Route path="/ai-evaluations/create" element={<AIEvaluationCreate />} /> | ||
| <Route path="/chat" element={<div>Chat Page</div>} /> | ||
| </Routes> | ||
| </MemoryRouter> | ||
| </MockedProvider> | ||
| ); | ||
|
|
||
| const fillAndSubmitForm = async (evaluationName = 'test_evaluation') => { | ||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| fireEvent.change(screen.getByPlaceholderText('Give a unique name for the evaluation experiment'), { | ||
| target: { value: evaluationName }, | ||
| }); | ||
|
|
||
| const assistantDropdown = screen.getAllByTestId('dropdown')[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByRole('option', { name: 'Test Assistant (Version 2)' })).toBeInTheDocument(); | ||
| }); | ||
| fireEvent.click(screen.getByRole('option', { name: 'Test Assistant (Version 2)' })); | ||
|
|
||
| fireEvent.click(screen.getByText('Run Evaluation')); | ||
| }; | ||
|
|
||
| describe('AIEvaluationCreate', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
|
|
@@ -70,9 +106,9 @@ describe('AIEvaluationCreate', () => { | |
| screen.getByText(/Select the Golden QA dataset from the existing list or upload a new set/) | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText('Expected CSV Format:')).toBeInTheDocument(); | ||
| expect(screen.getByText('Question,Answer')).toBeInTheDocument(); | ||
| expect(screen.getByText('What is the capital of France?,Paris')).toBeInTheDocument(); | ||
| expect(screen.getByText('Click here for the template CSV')).toBeInTheDocument(); | ||
| expect(screen.getByText('Question, Answer')).toBeInTheDocument(); | ||
| expect(screen.getByText('{"What Is X"},{"Answer"}')).toBeInTheDocument(); | ||
| expect(screen.getByText('Click Here For The Template Csv')).toBeInTheDocument(); | ||
|
Contributor
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. @priyanshu6238 why do these values keep changing?
Collaborator
Author
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. i change it according to the noopur design |
||
| }); | ||
|
|
||
| test('renders Upload Golden QA button', async () => { | ||
|
|
@@ -150,10 +186,10 @@ describe('AIEvaluationCreate', () => { | |
| render(wrapper()); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment.')).toBeInTheDocument(); | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment.'); | ||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment'); | ||
| fireEvent.change(nameInput, { target: { value: 'valid_name' } }); | ||
| fireEvent.click(screen.getByText('Run Evaluation')); | ||
|
|
||
|
|
@@ -162,43 +198,53 @@ describe('AIEvaluationCreate', () => { | |
| }); | ||
| }); | ||
|
|
||
| test('shows validation error for invalid evaluation name pattern', async () => { | ||
| test('shows validation error when evaluation name is cleared after being typed', async () => { | ||
| render(wrapper()); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment.')).toBeInTheDocument(); | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment.'); | ||
| fireEvent.change(nameInput, { target: { value: 'invalid name with spaces' } }); | ||
| fireEvent.click(screen.getByText('Run Evaluation')); | ||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment'); | ||
| fireEvent.change(nameInput, { target: { value: 'some_name' } }); | ||
| fireEvent.change(nameInput, { target: { value: '' } }); | ||
| fireEvent.blur(nameInput); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Invalid evaluation name')).toBeInTheDocument(); | ||
| expect(screen.getByText('Evaluation name is required')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('accepts valid evaluation name with alphanumeric, underscore and hyphen', async () => { | ||
| test('accepts any non-empty evaluation name', async () => { | ||
priyanshu6238 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| render(wrapper()); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment.')).toBeInTheDocument(); | ||
| expect(screen.getByPlaceholderText('Give a unique name for the evaluation experiment')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment.'); | ||
| const nameInput = screen.getByPlaceholderText('Give a unique name for the evaluation experiment'); | ||
| fireEvent.change(nameInput, { target: { value: 'valid_evaluation-name123' } }); | ||
|
|
||
| expect((nameInput as HTMLInputElement).value).toBe('valid_evaluation-name123'); | ||
| }); | ||
|
|
||
| test('shows assistant helper text', async () => { | ||
| render(wrapper()); | ||
| test('shows assistant options from query using assistantName and versionNumber', async () => { | ||
priyanshu6238 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| render(wrapper([...defaultMocks])); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| expect(screen.getByText("This list includes all assistants and versions you've created.")).toBeInTheDocument(); | ||
| const dropdowns = screen.getAllByTestId('dropdown'); | ||
| const assistantDropdown = dropdowns[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Test Assistant (Version 2)')).toBeInTheDocument(); | ||
| expect(screen.getByText('Test Assistant (Version 1)')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('Run Evaluation submit button is visible and enabled', async () => { | ||
|
|
@@ -211,6 +257,137 @@ describe('AIEvaluationCreate', () => { | |
| }); | ||
| }); | ||
|
|
||
| test('shows Fetching assistants... while assistant config versions are loading', async () => { | ||
| const mocks = [getAssistantConfigVersionsLoadingMock]; | ||
| render(wrapper(mocks)); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const dropdowns = screen.getAllByTestId('dropdown'); | ||
| const assistantDropdown = dropdowns[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Fetching assistants...')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('shows error notification when fetching assistant config versions fails', async () => { | ||
| render(wrapper([getAssistantConfigVersionsErrorMock])); | ||
|
|
||
| await waitFor(() => { | ||
| expect(setNotification).toHaveBeenCalledWith('Failed to fetch assistants', 'warning'); | ||
| }); | ||
| }); | ||
|
|
||
| test('shows No assistants available when assistant config versions list is empty', async () => { | ||
| const mocks = [getAssistantConfigVersionsEmptyMock]; | ||
| render(wrapper(mocks)); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const dropdowns = screen.getAllByTestId('dropdown'); | ||
| const assistantDropdown = dropdowns[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('No assistants available')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('renders assistant options in the order of their version numbers', async () => { | ||
| render(wrapper([getAssistantConfigVersionsMultipleNamesMock])); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const dropdowns = screen.getAllByTestId('dropdown'); | ||
| const assistantDropdown = dropdowns[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| const options = screen.getAllByRole('option'); | ||
| expect(options[0]).toHaveTextContent('Alpha Assistant (Version 1)'); | ||
| expect(options[1]).toHaveTextContent('Beta Assistant (Version 1)'); | ||
| expect(options[2]).toHaveTextContent('Beta Assistant (Version 2)'); | ||
| }); | ||
| }); | ||
|
|
||
| test('shows all assistant config versions with correct labels for multiple assistant names', async () => { | ||
| const mocks = [getAssistantConfigVersionsMultipleNamesMock]; | ||
| render(wrapper(mocks)); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Create AI Evaluation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const dropdowns = screen.getAllByTestId('dropdown'); | ||
| const assistantDropdown = dropdowns[1]; | ||
| const selectTrigger = | ||
| assistantDropdown.querySelector('[role="combobox"]') ?? assistantDropdown.querySelector('button'); | ||
| fireEvent.mouseDown(selectTrigger!); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Alpha Assistant (Version 1)')).toBeInTheDocument(); | ||
| expect(screen.getByText('Beta Assistant (Version 1)')).toBeInTheDocument(); | ||
| expect(screen.getByText('Beta Assistant (Version 2)')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
priyanshu6238 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test('calls createEvaluation with correct parameters when form is submitted', async () => { | ||
| let capturedVariables: any = null; | ||
| const captureMock = { | ||
| request: { query: getCreateEvaluationSuccessMock.request.query }, | ||
| variableMatcher: (vars: any) => { | ||
| capturedVariables = vars; | ||
| return true; | ||
| }, | ||
| result: { | ||
| data: { | ||
| createEvaluation: { | ||
| __typename: 'EvaluationResult', | ||
| evaluation: { __typename: 'CreateEvaluationResult', status: 'queued' }, | ||
| errors: null, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| render(wrapper([getListAiEvaluationsMock, getAssistantConfigVersionsMock, captureMock])); | ||
|
|
||
| await fillAndSubmitForm('test_evaluation'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(capturedVariables?.input).toMatchObject({ | ||
| datasetId: 0, | ||
| experimentName: 'test_evaluation', | ||
| configId: 'kaapi-uuid-a1', | ||
| configVersion: '1', | ||
priyanshu6238 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test('shows success notification and navigates to chat on successful submission', async () => { | ||
| render(wrapper([getListAiEvaluationsMock, getAssistantConfigVersionsMock, getCreateEvaluationSuccessMock])); | ||
|
|
||
| await fillAndSubmitForm(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(setNotification).toHaveBeenCalledWith('AI evaluation created successfully!'); | ||
| expect(screen.getByText('Chat Page')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('back button is present and navigates away when clicked', async () => { | ||
| render(wrapper()); | ||
|
|
||
|
|
@@ -284,8 +461,8 @@ describe('AIEvaluationCreate', () => { | |
| render( | ||
| wrapper([ | ||
| ...defaultMocks, | ||
| createGoldenQaCustomSuccessMock('first_qa', 1), | ||
| createGoldenQaCustomSuccessMock('second_qa', 1), | ||
| createGoldenQaCustomSuccessMock('first_qa', 1, '100'), | ||
| createGoldenQaCustomSuccessMock('second_qa', 1, '200'), | ||
| ]) | ||
| ); | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.