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 28, 2024
1 parent 2d95730 commit 2040fff
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/headless/src/api/knowledge/stream-answer-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
EventSourceMessage,
fetchEventSource,
Expand All @@ -17,6 +18,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 +32,7 @@ export type StateNeededByAnswerAPI = {
answer: ReturnType<typeof answerApi.reducer>;
} & ConfigurationSection &
Partial<SearchAppState> &
InsightConfigurationSection &
GeneratedAnswerSection;

export interface GeneratedAnswerStream {
Expand Down Expand Up @@ -176,15 +179,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 2040fff

Please sign in to comment.