Skip to content

Commit

Permalink
feat(answerAPI): insight generate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Gauthier authored and Danny Gauthier committed Oct 29, 2024
1 parent 91a2538 commit 972d40c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/headless/src/api/knowledge/stream-answer-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {SearchAppState} from '../../state/search-app-state.js';
import {
ConfigurationSection,
GeneratedAnswerSection,
InsightConfigurationSection,
} from '../../state/state-sections.js';
import {getFacets} from '../../utils/facet-utils.js';
import {GeneratedAnswerCitation} from '../generated-answer/generated-answer-event-payload.js';
Expand All @@ -30,6 +31,7 @@ export type StateNeededByAnswerAPI = {
answer: ReturnType<typeof answerApi.reducer>;
} & ConfigurationSection &
Partial<SearchAppState> &
InsightConfigurationSection &
GeneratedAnswerSection;

export interface GeneratedAnswerStream {
Expand Down Expand Up @@ -176,15 +178,17 @@ export const answerApi = answerSlice.injectEndpoints({
* It cannot use the inferred state used by Redux, thus the casting.
* https://redux-toolkit.js.org/rtk-query/usage-with-typescript#typing-dispatch-and-getstate
*/
const {configuration, generatedAnswer} =
const {configuration, generatedAnswer, insightConfiguration} =
getState() as unknown as StateNeededByAnswerAPI;
const {organizationId, environment, accessToken} = configuration;
const platformEndpoint = getOrganizationEndpoint(
organizationId,
environment
);
const insightGenerateEndpoint = `${platformEndpoint}/rest/organizations/${organizationId}/insight/v1/configs/${insightConfiguration.insightId}/answer/${generatedAnswer.answerConfigurationId}/generate`;
const generateEndpoint = `${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${generatedAnswer.answerConfigurationId}/generate`;
await fetchEventSource(
`${platformEndpoint}/rest/organizations/${organizationId}/answer/v1/configs/${generatedAnswer.answerConfigurationId}/generate`,
insightConfiguration ? insightGenerateEndpoint : generateEndpoint,
{
method: 'POST',
body: JSON.stringify(args),
Expand Down

0 comments on commit 972d40c

Please sign in to comment.