Skip to content

Commit

Permalink
run engine2 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
EFF committed Oct 21, 2019
1 parent a011412 commit 31d3e00
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"env": {
"BP_MODULES_PATH": "${workspaceFolder}/modules:${workspaceFolder}/internal-modules",
"NODE_PATH": "${workspaceFolder}/out/bp",
"DEBUG": "bp:none",
"USE_EXPERIMENTAL_NLU_PIPELINE": true
"DEBUG": "bp:none"
},
"smartStep": true,
"outFiles": [
Expand Down
4 changes: 2 additions & 2 deletions modules/nlu/src/backend/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { EngineByBot } from './typings'
import { EntityDefCreateSchema, IntentDefCreateSchema } from './validation'

const SYNC_INTERVAL_MS = ms('5s')
const USE_E2 = yn(process.env.USE_EXPERIMENTAL_NLU_PIPELINE)
const USE_E1 = yn(process.env.USE_LEGACY_NLU)

export default async (bp: typeof sdk, nlus: EngineByBot) => {
const router = bp.http.createRouterForBot('nlu')

const syncByBots: { [key: string]: NodeJS.Timer } = {}

const scheduleSyncNLU = (botId: string) => {
if (USE_E2) {
if (USE_E1) {
return
}
if (syncByBots[botId]) {
Expand Down
8 changes: 4 additions & 4 deletions modules/nlu/src/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Storage from './storage'
import { isPatternValid } from './tools/patterns-utils'
import { EngineByBot, LanguageProvider, NLUHealth } from './typings'

const USE_E2 = yn(process.env.USE_EXPERIMENTAL_NLU_PIPELINE)
const USE_E1 = yn(process.env.USE_LEGACY_NLU)
const nluByBot: EngineByBot = {}
// TODO rethink this for an immutable bot state instead
const e2ByBot: E2ByBot = {}
Expand Down Expand Up @@ -114,7 +114,7 @@ const onBotMount = async (bp: typeof sdk, botId: string) => {
await scoped.init()
nluByBot[botId] = scoped

if (!USE_E2) {
if (USE_E1) {
return
}

Expand Down Expand Up @@ -210,7 +210,7 @@ const onBotMount = async (bp: typeof sdk, botId: string) => {

const onBotUnmount = async (bp: typeof sdk, botId: string) => {
delete nluByBot[botId]
if (!USE_E2) {
if (USE_E1) {
return
}

Expand All @@ -225,7 +225,7 @@ const onModuleUnmount = async (bp: typeof sdk) => {
bp.events.removeMiddleware('nlu.incoming')
bp.http.deleteRouterForBot('nlu')
// if module gets deactivated but server keeps running, we want to destroy bot state
if (USE_E2) {
if (!USE_E1) {
Object.keys(e2ByBot).forEach(botID => () => onBotUnmount(bp, botID))
}
}
Expand Down
10 changes: 5 additions & 5 deletions modules/nlu/src/backend/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ScopedEngine from './engine'
import Engine2, { E2ByBot } from './engine2/engine2'
import { EngineByBot } from './typings'

const USE_E2 = yn(process.env.USE_EXPERIMENTAL_NLU_PIPELINE)
const USE_E1 = yn(process.env.USE_LEGACY_NLU)
const EVENTS_TO_IGNORE = ['session_reference', 'session_reset', 'bp_dialog_timeout', 'visit', 'say_something', '']

export const registerMiddleware = async (bp: typeof sdk, e1ByBot: EngineByBot, e2byBot: E2ByBot) => {
Expand All @@ -23,7 +23,7 @@ export const registerMiddleware = async (bp: typeof sdk, e1ByBot: EngineByBot, e
return next()
}

const botCtx = USE_E2 ? e2byBot[event.botId] : (e1ByBot[event.botId] as ScopedEngine)
const botCtx = USE_E1 ? (e1ByBot[event.botId] as ScopedEngine) : e2byBot[event.botId]

if (
!botCtx ||
Expand All @@ -36,14 +36,14 @@ export const registerMiddleware = async (bp: typeof sdk, e1ByBot: EngineByBot, e

try {
let nlu = {}
if (USE_E2) {
nlu = await (botCtx as Engine2).predict(event.preview, event.nlu.includedContexts)
} else {
if (USE_E1) {
nlu = await (botCtx as ScopedEngine).extract!(
event.preview,
event.state.session.lastMessages.map(message => message.incomingPreview),
event.nlu.includedContexts
)
} else {
nlu = await (botCtx as Engine2).predict(event.preview, event.nlu.includedContexts)
}

_.merge(event, { nlu })
Expand Down

0 comments on commit 31d3e00

Please sign in to comment.