Skip to content

Commit

Permalink
fix(misunderstood): train all modified languages (#4671)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur committed Mar 10, 2021
1 parent 208a7a2 commit f0894a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/misunderstood/src/backend/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export default async (bp: typeof sdk, db: Db) => {
const { botId } = req.params

try {
await db.applyChanges(botId)
const modifiedLanguages = await db.applyChanges(botId)
const axiosConfig = await bp.http.getAxiosConfigForBot(botId, { localUrl: true })
setTimeout(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
axios.post('/mod/nlu/train', {}, axiosConfig)
Promise.map(modifiedLanguages, lang => axios.post(`/mod/nlu/train/${lang}`, {}, axiosConfig))
}, 1000)
res.sendStatus(200)
} catch (err) {
Expand Down
7 changes: 6 additions & 1 deletion modules/misunderstood/src/backend/applyChanges.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import Bluebird from 'bluebird'
import * as sdk from 'botpress/sdk'
import _ from 'lodash'
import memoize from 'lodash/memoize'
import uniq from 'lodash/uniq'

Expand Down Expand Up @@ -75,6 +75,11 @@ const applyChanges = (bp: typeof sdk, botId: string, tableName: string) => {
'id',
events.map(({ id }) => id)
)

return _(events)
.map(e => e.language)
.uniq()
.value()
})
}

Expand Down
4 changes: 1 addition & 3 deletions modules/nlu/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const makeApi = (bp: { axios: AxiosInstance }) => ({
createEntity: (entity: sdk.NLU.EntityDefinition): Promise<void> => bp.axios.post('/nlu/entities/', entity),
updateEntity: (targetEntityId: string, entity: sdk.NLU.EntityDefinition): Promise<void> =>
bp.axios.post(`/nlu/entities/${targetEntityId}`, entity),
deleteEntity: (entityId: string): Promise<void> => bp.axios.post(`/nlu/entities/${entityId}/delete`),
train: (): Promise<void> => bp.axios.post('/mod/nlu/train'),
cancelTraining: (): Promise<void> => bp.axios.post('/mod/nlu/train/delete')
deleteEntity: (entityId: string): Promise<void> => bp.axios.post(`/nlu/entities/${entityId}/delete`)
})

export const createApi = async (bp: typeof sdk, botId: string) => {
Expand Down

0 comments on commit f0894a9

Please sign in to comment.