Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed May 31, 2024
1 parent d61989c commit a8504f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/services/classification/classification.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export const LEGACY_LLM_INTENT_CLASSIFICATION: IntentClassificationLLMSettings =
content: DEFAULT_INTENT_CLASSIFICATION_PROMPT_WRAPPER_CODE,
},
};

export const NLU_LIMIT = 10;
18 changes: 8 additions & 10 deletions lib/services/classification/interfaces/nlu.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,7 @@ export interface PredictRequest {
dmRequest?: BaseRequest.IntentRequestPayload;
}

export interface PredictOptions {
filteredIntents?: string[];
filteredEntities?: string[];
excludeFilteredIntents?: boolean;
excludeFilteredEntities?: boolean;
// Legacy options for NLC
hasChannelIntents?: boolean;
locale: VoiceflowConstants.Locale;
platform: VoiceflowConstants.PlatformType;
}
export type PredictOptions = NLUPredictOptions & NLCPredictOptions;

export interface NLUPredictOptions {
filteredIntents?: string[];
Expand All @@ -91,3 +82,10 @@ export interface NLUPredictOptions {
excludeFilteredEntities?: boolean;
limit?: number;
}

/** @deprecated */
export interface NLCPredictOptions {
hasChannelIntents?: boolean;
locale: VoiceflowConstants.Locale;
platform: VoiceflowConstants.PlatformType;
}
15 changes: 10 additions & 5 deletions lib/services/classification/predictor.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import logger from '@/logger';

import { handleNLCCommand } from '../nlu/nlc';
import { mapChannelIntent } from '../nlu/utils';
import { NLU_LIMIT } from './classification.const';
import { isIntentClassificationLLMSettings, isIntentClassificationNLUSettings } from './classification.utils';
import {
ClassificationResult,
Expand Down Expand Up @@ -127,19 +128,19 @@ export class Predictor extends EventEmitter {
return response;
}

private async nluGatewayPrediction(utterance: string, options: Partial<NLUPredictOptions>) {
private async nluGatewayPrediction(utterance: string, options: NLUPredictOptions) {
const { limit, excludeFilteredEntities, excludeFilteredIntents, filteredEntities, filteredIntents } = options;

const { data: prediction } = await this.config.axios
.post<NLUIntentPrediction | null>(`${this.nluGatewayURL}/v1/predict/${this.props.versionID}`, {
utterance,
tag: this.props.tag,
workspaceID: this.props.workspaceID,
limit: limit ?? NLU_LIMIT,
...(excludeFilteredEntities ? { excludeFilteredEntities } : {}),
...(excludeFilteredIntents ? { excludeFilteredIntents } : {}),
...(filteredEntities ? { filteredEntities } : {}),
...(filteredIntents ? { filteredIntents } : {}),
...(limit ? { limit } : {}),
})
.catch((err: Error) => {
logger.error(err, 'Something went wrong with NLU prediction');
Expand All @@ -148,7 +149,7 @@ export class Predictor extends EventEmitter {
return prediction;
}

public async nlu(utterance: string, options: Partial<NLUPredictOptions>): Promise<NLUIntentPrediction | null> {
public async nlu(utterance: string, options: NLUPredictOptions): Promise<NLUIntentPrediction | null> {
const prediction = await this.nluGatewayPrediction(utterance, options);
if (!prediction) {
this.predictions.nlu = {
Expand Down Expand Up @@ -296,7 +297,7 @@ export class Predictor extends EventEmitter {
return nlcPrediction;
}

const nluPrediction = this.props.isTrained && (await this.nlu(utterance, { limit: 10 }));
const nluPrediction = this.props.isTrained && (await this.nlu(utterance, this.options));

if (!nluPrediction) {
if (isIntentClassificationLLMSettings(this.settings)) {
Expand Down Expand Up @@ -357,7 +358,11 @@ export class Predictor extends EventEmitter {
}

public hasErrors() {
return this.predictions.nlc?.error || this.predictions.nlu?.error || this.predictions.llm?.error;
return (
(this.predictions.nlc && 'error' in this.predictions.nlc) ||
(this.predictions.nlu && 'error' in this.predictions.nlu) ||
(this.predictions.llm && 'error' in this.predictions.llm)
);
}

public get classificationType() {
Expand Down

0 comments on commit a8504f2

Please sign in to comment.