Skip to content
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

✨ Add native property to NluData #1456

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Entity {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value?: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
native?: any;
native?: any; // raw API response from the NLU service
}

export interface EntityMap<ENTITY_TYPE extends Entity = Entity> {
Expand All @@ -25,6 +25,8 @@ export interface AsrData extends UnknownObject {
export interface NluData extends UnknownObject {
intent?: Intent | string;
entities?: EntityMap;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
native?: any; // raw API response from the NLU service
}

export enum InputType {
Expand Down
5 changes: 4 additions & 1 deletion docs/nlu.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Learn more about natural language understanding (NLU) services that can be integ

Natural language understanding (in short, NLU) is the process of turning raw text into structured meaning. It is part of the `interpretation` step of the [RIDR lifecycle](./ridr-lifecycle.md).

Jovo offers integrations with a variety of NLU services that can either be self-hosted or accessed via an API. [You can find all the current integrations here](#integrations).
Jovo offers integrations with a variety of NLU services that can either be self-hosted or accessed via an API. [You can find all the current integrations below](#integrations).

NLU integrations are helpful for platforms that deal with raw text. The integration then writes the results into an `nlu` object that is part of the [`$input` property](./input.md):

Expand All @@ -27,6 +27,9 @@ NLU integrations are helpful for platforms that deal with raw text. The integrat
value: 'Max',
},
},
native: {
// Raw API response from the NLU service
}
},
}
```
Expand Down
4 changes: 3 additions & 1 deletion integrations/nlu-dialogflow/src/DialogflowNlu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export class DialogflowNlu extends NluPlugin<DialogflowNluConfig> {
jovo.$session.id,
);

const nluData: NluData = {};
const nluData: NluData = {
native: dialogflowResponse.data,
};
const displayName = dialogflowResponse.data.queryResult.intent.displayName;
if (displayName) {
nluData.intent = { name: displayName };
Expand Down
3 changes: 2 additions & 1 deletion integrations/nlu-nlpjs/src/NlpjsNlu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export class NlpjsNlu extends NluPlugin<NlpjsNluConfig> {
name: nlpResult.intent,
},
entities,
raw: nlpResult, // TODO: temporary property
native: nlpResult,
raw: nlpResult, // @deprecated please use 'native' property
}
: undefined;
}
Expand Down
1 change: 1 addition & 0 deletions integrations/nlu-rasa/src/RasaNlu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class RasaNlu extends NluPlugin<RasaNluConfig> {
},
alternativeIntents: this.mapAlternativeIntents(rasaResponse.data.intent_ranking),
entities: this.getEntityMapFromResponse(rasaResponse.data),
native: rasaResponse.data,
};
} catch (e) {
// eslint-disable-next-line no-console
Expand Down
4 changes: 3 additions & 1 deletion integrations/nlu-snips/src/SnipsNlu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class SnipsNlu extends NluPlugin<SnipsNluConfig> {
};

const snipsNluResponse: SnipsNluResponse = await this.sendRequestToSnips(config);
const nluData: NluData = {};
const nluData: NluData = {
native: snipsNluResponse,
};
if (snipsNluResponse.intent.intentName) {
nluData.intent = { name: snipsNluResponse.intent.intentName };
}
Expand Down