Skip to content

Commit

Permalink
feat(headless): add answerTextIsEmpty to genQA UA stream event (#3722)
Browse files Browse the repository at this point in the history
[SVCC-3542](https://coveord.atlassian.net/browse/SVCC-3542)

Add `answerTextIsEmpty` to genQA UA events In order to check whether
there was a message or not.

open PR in Coveo.analytics to add this new parameter to the interface
here: [PR](coveo/coveo.analytics.js#452)
In the meantine added a Type checker .

<img width="805" alt="Screenshot 2024-03-15 at 2 31 06 PM"
src="https://github.com/coveo/ui-kit/assets/119955059/f6bc8327-d72f-40de-b874-dfa0b24689dc">


[SVCC-3542]:
https://coveord.atlassian.net/browse/SVCC-3542?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
jelmedini authored Apr 2, 2024
1 parent 1310105 commit 56e4318
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 35 deletions.
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@microsoft/fetch-event-source": "2.0.1",
"@reduxjs/toolkit": "2.2.2",
"abab": "2.0.6",
"coveo.analytics": "2.29.3",
"coveo.analytics": "2.29.6",
"dayjs": "1.11.10",
"exponential-backoff": "3.1.0",
"fast-equals": "5.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('generated answer analytics actions', () => {
});

[false, true].map((answerGenerated) => {
it(`should log #logGeneratedAnswerStreamEnd with ${answerGenerated ? 'generated' : 'not generated'} answer`, async () => {
it(`should log #logGeneratedAnswerStreamEnd with ${answerGenerated ? 'generated' : 'not generated'} and 'empty' answer`, async () => {
await logGeneratedAnswerStreamEnd(answerGenerated)()(
engine.dispatch,
() => engine.state,
Expand All @@ -298,11 +298,46 @@ describe('generated answer analytics actions', () => {
expect(mockToUse).toHaveBeenCalledWith({
generativeQuestionAnsweringId: exampleGenerativeQuestionAnsweringId,
answerGenerated,
answerTextIsEmpty: answerGenerated || undefined,
});
expect(mockLogFunction).toHaveBeenCalledTimes(1);
});
});

it("should log #logGeneratedAnswerStreamEnd with 'non empty' answer", async () => {
const newEngine = buildMockSearchEngine(
createMockState({
configuration: {
...getConfigurationInitialState(),
analytics: {
...getConfigurationInitialState().analytics,
analyticsMode: 'legacy',
},
},
search: searchState,
generatedAnswer: {
...generatedAnswerState,
answer: 'generated answer',
},
})
);
await logGeneratedAnswerStreamEnd(true)()(
newEngine.dispatch,
() => newEngine.state,
{} as ThunkExtraArguments
);

const mockToUse = mockMakeGeneratedAnswerStreamEnd;

expect(mockToUse).toHaveBeenCalledTimes(1);
expect(mockToUse).toHaveBeenCalledWith({
generativeQuestionAnsweringId: exampleGenerativeQuestionAnsweringId,
answerGenerated: true,
answerTextIsEmpty: false,
});
expect(mockLogFunction).toHaveBeenCalledTimes(1);
});

it('should log #logGeneratedAnswerShowAnswers with the right payload', async () => {
await logGeneratedAnswerShowAnswers()()(
engine.dispatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,17 @@ export const logGeneratedAnswerStreamEnd = (
(client, state) => {
const generativeQuestionAnsweringId =
generativeQuestionAnsweringIdSelector(state);
const answerTextIsEmpty = answerGenerated
? !state.generatedAnswer?.answer ||
!state.generatedAnswer?.answer.length
: undefined;
if (!generativeQuestionAnsweringId) {
return null;
}
return client.makeGeneratedAnswerStreamEnd({
generativeQuestionAnsweringId,
answerGenerated,
answerTextIsEmpty,
});
}
);
Expand Down

0 comments on commit 56e4318

Please sign in to comment.