From 3df40fc3da53821cdb42f85beda5d25f4131ad48 Mon Sep 17 00:00:00 2001 From: Marc Rabat Pla <35448568+vanbasten17@users.noreply.github.com> Date: Fri, 9 Jul 2021 16:49:03 +0200 Subject: [PATCH] chore(ner/intent): support for botonic full-stack (#1644) * chore(ner/intent): support for botonic full-stack * refactor(plugin-ner, plugin-ic): baseUrl typed Co-authored-by: Eric Lozano --- .../src/index.ts | 5 +---- .../src/model/model-selector.ts | 12 +++++++----- .../src/options.ts | 2 +- packages/botonic-plugin-ner/src/index.ts | 5 +---- .../botonic-plugin-ner/src/model/model-selector.ts | 12 +++++++----- packages/botonic-plugin-ner/src/options.ts | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/botonic-plugin-intent-classification/src/index.ts b/packages/botonic-plugin-intent-classification/src/index.ts index 0f7e79ddcc..4fc4ece909 100644 --- a/packages/botonic-plugin-intent-classification/src/index.ts +++ b/packages/botonic-plugin-intent-classification/src/index.ts @@ -9,10 +9,7 @@ export default class BotonicPluginIntentClassification implements Plugin { private readonly modelsSelector: Promise constructor(readonly options: PluginOptions) { - this.modelsSelector = IntentModelSelector.build( - this.options.locales, - this.options.modelsBaseUrl - ) + this.modelsSelector = IntentModelSelector.build(this.options.locales) } async pre(request: PluginPreRequest): Promise { diff --git a/packages/botonic-plugin-intent-classification/src/model/model-selector.ts b/packages/botonic-plugin-intent-classification/src/model/model-selector.ts index e70c6fe30a..d32b7527ad 100644 --- a/packages/botonic-plugin-intent-classification/src/model/model-selector.ts +++ b/packages/botonic-plugin-intent-classification/src/model/model-selector.ts @@ -9,11 +9,13 @@ export class IntentModelSelector extends ModelSelector< IntentClassifier, IntentClassifierConfig > { - static async build( - locales: Locale[], - modelsBaseUrl: string - ): Promise { - const selector = new IntentModelSelector(locales, modelsBaseUrl) + static async build(locales: Locale[]): Promise { + const baseUrl: string = + // @ts-ignore + (typeof MODELS_BASE_URL !== 'undefined' && MODELS_BASE_URL) || + process.env.MODELS_BASE_URL + const intentModelsUrl = `${baseUrl}/intent-classification/models` + const selector = new IntentModelSelector(locales, intentModelsUrl) return await selector.load() } diff --git a/packages/botonic-plugin-intent-classification/src/options.ts b/packages/botonic-plugin-intent-classification/src/options.ts index 6838dc6ce4..87becec8da 100644 --- a/packages/botonic-plugin-intent-classification/src/options.ts +++ b/packages/botonic-plugin-intent-classification/src/options.ts @@ -1,3 +1,3 @@ import { Locale } from '@botonic/nlp/lib/types' -export type PluginOptions = { locales: Locale[]; modelsBaseUrl: string } +export type PluginOptions = { locales: Locale[] } diff --git a/packages/botonic-plugin-ner/src/index.ts b/packages/botonic-plugin-ner/src/index.ts index ec1dd2b348..90cb8f4412 100644 --- a/packages/botonic-plugin-ner/src/index.ts +++ b/packages/botonic-plugin-ner/src/index.ts @@ -9,10 +9,7 @@ export default class BotonicPluginNER implements Plugin { private modelsSelector: Promise constructor(readonly options: PluginOptions) { - this.modelsSelector = NerModelSelector.build( - this.options.locales, - this.options.modelsBaseUrl - ) + this.modelsSelector = NerModelSelector.build(this.options.locales) } async pre(request: PluginPreRequest): Promise { diff --git a/packages/botonic-plugin-ner/src/model/model-selector.ts b/packages/botonic-plugin-ner/src/model/model-selector.ts index e721401be2..4c2da535a6 100644 --- a/packages/botonic-plugin-ner/src/model/model-selector.ts +++ b/packages/botonic-plugin-ner/src/model/model-selector.ts @@ -9,11 +9,13 @@ export class NerModelSelector extends ModelSelector< NamedEntityRecognizer, NerConfig > { - static async build( - locales: Locale[], - modelsBaseUrl: string - ): Promise { - const selector = new NerModelSelector(locales, modelsBaseUrl) + static async build(locales: Locale[]): Promise { + const baseUrl: string = + // @ts-ignore + (typeof MODELS_BASE_URL !== 'undefined' && MODELS_BASE_URL) || + process.env.MODELS_BASE_URL + const nerModelsUrl = `${baseUrl}/ner/models` + const selector = new NerModelSelector(locales, nerModelsUrl) return await selector.load() } diff --git a/packages/botonic-plugin-ner/src/options.ts b/packages/botonic-plugin-ner/src/options.ts index 6838dc6ce4..87becec8da 100644 --- a/packages/botonic-plugin-ner/src/options.ts +++ b/packages/botonic-plugin-ner/src/options.ts @@ -1,3 +1,3 @@ import { Locale } from '@botonic/nlp/lib/types' -export type PluginOptions = { locales: Locale[]; modelsBaseUrl: string } +export type PluginOptions = { locales: Locale[] }