Skip to content

Commit

Permalink
feat(quantic): new public property fieldsToIncludeInCitations added t…
Browse files Browse the repository at this point in the history
…o the QuanticGeneratedAnswer component (#3467)

* public property fieldsToIncludeInCitations added to the QuanticGeneratedAnswer component

* public property fieldsToIncludeInCitations added to the QuanticGeneratedAnswer component

* Update packages/quantic/cypress/e2e/default-2/generatedAnswer/generated-answer.cypress.ts

Co-authored-by: Etienne Rocheleau <[email protected]>

* error template added

---------

Co-authored-by: Etienne Rocheleau <[email protected]>
  • Loading branch information
mmitiche and erocheleau authored Dec 8, 2023
1 parent b653a47 commit f80d3b4
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ function generatedAnswerExpectations(selector: GeneratedAnswerSelector) {
);
},

searchQueryContainsCorrectFieldsToIncludeInCitations: (
expectedFields: string[]
) => {
cy.get<Interception>(InterceptAliases.Search)
.then((interception) => {
const fieldsToIncludeInCitations =
interception?.request?.body?.pipelineRuleParameters
?.mlGenerativeQuestionAnswering?.citationsFieldToInclude;
expect(fieldsToIncludeInCitations).to.eql(expectedFields);
})
.log(
'the search query should contain the correct fields to include in citations parameter'
);
},

logStreamIdInAnalytics(streamId: string) {
cy.wait(InterceptAliases.UA.Load)
.then((interception) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {GeneratedAnswerExpectations as Expect} from './generated-answer-expectat
interface GeneratedAnswerOptions {
answerStyle: string;
multilineFooter: boolean;
fieldsToIncludeInCitations: string;
}

const GENERATED_ANSWER_DATA_KEY = 'coveo-generated-answer-data';
Expand All @@ -29,6 +30,7 @@ const feedbackOptions = [
otherOption,
];

const defaultFieldsToIncludeInCitations = 'sfid,sfkbid,sfkavid';
const defaultRephraseOption = 'default';
const stepRephraseOption = 'step';
const bulletRephraseOption = 'bullet';
Expand Down Expand Up @@ -100,6 +102,13 @@ describe('quantic-generated-answer', () => {
Expect.searchQueryContainsCorrectRephraseOption(defaultRephraseOption);
});

it('should perform a search query with the default fields to include in citations', () => {
cy.wait(InterceptAliases.Search);
Expect.searchQueryContainsCorrectFieldsToIncludeInCitations(
defaultFieldsToIncludeInCitations.split(',')
);
});

it(
'should display rephrase buttons',
{
Expand Down Expand Up @@ -359,6 +368,27 @@ describe('quantic-generated-answer', () => {
});
});

describe('when a custom value is provided to the fields to include in citations attribute', () => {
const streamId = crypto.randomUUID();
const customFields = 'foo,bar';

beforeEach(() => {
mockSearchWithGeneratedAnswer(streamId);
mockStreamResponse(streamId, genQaMessageTypePayload);
visitGeneratedAnswer({fieldsToIncludeInCitations: customFields});
});

it('should send a search query with the right fields to include in citations option as a parameter', () => {
scope('when loading the page', () => {
Expect.displayGeneratedAnswerContent(true);
Expect.displayRephraseButtons(true);
Expect.searchQueryContainsCorrectFieldsToIncludeInCitations(
customFields.split(',')
);
});
});
});

describe('when the property multilineFooter is set to true', () => {
const streamId = crypto.randomUUID();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
</div>

<c-quantic-search-interface slot="preview" engine-id={engineId}>
<c-quantic-generated-answer engine-id={engineId} answer-style={config.answerStyle} multiline-footer={config.multilineFooter}>
<c-quantic-generated-answer engine-id={engineId} answer-style={config.answerStyle}
fields-to-include-in-citations={config.fieldsToIncludeInCitations} multiline-footer={config.multilineFooter}>
</c-quantic-generated-answer>
</c-quantic-search-interface>
</c-example-layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export default class ExampleQuanticGeneratedAnswer extends LightningElement {
description: 'The answer style to apply when the component first loads.',
defaultValue: 'default',
},
{
attribute: 'fieldsToIncludeInCitations',
label: 'Fields to include in citations',
description:
'A list of fields to fetch with the citations used to generate the answer, separated by commas.',
defaultValue: 'sfid,sfkbid,sfkavid',
},
{
attribute: 'multilineFooter',
label: 'Multiline footer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class QuanticFoldedResultList extends LightningElement {
* A list of fields to include in the query results, separated by commas.
* @api
* @type {string}
* @defaultValue `'date,author,source,language,filetype,parents,sfknowledgearticleid'`
* @defaultValue `'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid'`
*/
@api fieldsToInclude =
'date,author,source,language,filetype,parents,sfknowledgearticleid,sfid,sfkbid,sfkavid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
import {AriaLiveRegion, I18nUtils} from 'c/quanticUtils';
import {LightningElement, api} from 'lwc';
// @ts-ignore
import errorTemplate from './templates/errorTemplate.html';
// @ts-ignore
import generatedAnswerTemplate from './templates/generatedAnswer.html';
// @ts-ignore
import loadingTemplate from './templates/loading.html';
Expand Down Expand Up @@ -68,6 +70,13 @@ export default class QuanticGeneratedAnswer extends LightningElement {
* @default {'default'}
*/
@api answerStyle = 'default';
/**
* A list of fields to fetch with the citations used to generate the answer.
* @api
* @type {string}
* @defaultValue `'sfid,sfkbid,sfkavid'`
*/
@api fieldsToIncludeInCitations = 'sfid,sfkbid,sfkavid';
/**
* Indicates whether footer sections should be displayed on multiple lines.
* @api
Expand Down Expand Up @@ -109,6 +118,8 @@ export default class QuanticGeneratedAnswer extends LightningElement {
feedbackSubmitted = false;
/** @type {import('c/quanticUtils').AriaLiveUtils} */
ariaLiveMessage;
/** @type {boolean} */
hasInitializationError = false;

connectedCallback() {
registerComponentForInit(this, this.engineId);
Expand Down Expand Up @@ -156,6 +167,7 @@ export default class QuanticGeneratedAnswer extends LightningElement {
isVisible: storedGeneratedAnswerVisibility === false ? false : true,
responseFormat: {answerStyle: this.answerStyle},
},
fieldsToIncludeInCitations: this.citationFields,
});
}

Expand Down Expand Up @@ -396,7 +408,24 @@ export default class QuanticGeneratedAnswer extends LightningElement {
return this.multilineFooter ? false : true;
}

get citationFields() {
return this.fieldsToIncludeInCitations
?.split(',')
.map((field) => field.trim())
.filter((field) => field.length > 0);
}

/**
* Sets the component in the initialization error state.
*/
setInitializationError() {
this.hasInitializationError = true;
}

render() {
if (this.hasInitializationError) {
return errorTemplate;
}
if (this.isLoading) {
return loadingTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template>
<c-quantic-component-error component-name={template.host.localName}>
</c-quantic-component-error>
</template>

0 comments on commit f80d3b4

Please sign in to comment.