Skip to content

Commit

Permalink
feat(nlu-client): added 2 methods in nlu-client for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur committed Jan 11, 2022
1 parent 46cc134 commit 5455dd0
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 89 deletions.
23 changes: 21 additions & 2 deletions packages/nlu-client/src/client.ts
Expand Up @@ -15,7 +15,10 @@ import {
PredictRequestBody,
PredictResponseBody,
ErrorResponse,
ListTrainingsResponseBody
ListTrainingsResponseBody,
LintRequestBody,
LintResponseBody,
LintProgressResponseBody
} from './typings/http'
import { validateResponse, HTTPCall, HTTPVerb, ClientResponseError } from './validation'

Expand All @@ -35,7 +38,7 @@ export class NLUClient implements IClient {
}

public async getInfo(): Promise<InfoResponseBody | ErrorResponse> {
const ressource = 'data'
const ressource = 'info'
const call: HTTPCall<'GET'> = { verb: 'GET', ressource }
const res = await this._get(call)
return validateResponse<InfoResponseBody>(call, res)
Expand All @@ -49,6 +52,14 @@ export class NLUClient implements IClient {
return validateResponse<TrainResponseBody>(call, res)
}

public async startLinting(appId: string, body: LintRequestBody): Promise<LintResponseBody | ErrorResponse> {
const headers = this._appIdHeader(appId)
const ressource = 'lint'
const call: HTTPCall<'POST'> = { verb: 'POST', ressource }
const res = await this._post(call, body, { headers })
return validateResponse<LintResponseBody>(call, res)
}

public async listTrainings(appId: string, lang?: string): Promise<ListTrainingsResponseBody | ErrorResponse> {
const headers = this._appIdHeader(appId)
const ressource = 'train'
Expand All @@ -66,6 +77,14 @@ export class NLUClient implements IClient {
return validateResponse<TrainProgressResponseBody>(call, res)
}

public async getLintingStatus(appId: string, modelId: string): Promise<LintProgressResponseBody | ErrorResponse> {
const headers = this._appIdHeader(appId)
const ressource = `lint/${modelId}`
const call: HTTPCall<'GET'> = { verb: 'GET', ressource }
const res = await this._get(call, { headers })
return validateResponse<LintProgressResponseBody>(call, res)
}

public async cancelTraining(appId: string, modelId: string): Promise<SuccessReponse | ErrorResponse> {
const headers = this._appIdHeader(appId)
const ressource = `train/${modelId}/cancel`
Expand Down
15 changes: 4 additions & 11 deletions packages/nlu-client/src/typings/http.d.ts
Expand Up @@ -4,17 +4,10 @@
* ############
*/

import { DatasetIssue, IssueCode, LintingState } from './linting'
import {
TrainingState,
PredictOutput,
IntentDefinition,
EntityDefinition,
Specifications,
Health,
ServerInfo,
Training
} from './sdk'
import { ServerInfo } from './info'
import { LintingState } from './linting'
import { PredictOutput } from './prediction'
import { TrainingState, IntentDefinition, EntityDefinition, Training } from './training'

export type TrainRequestBody = {
language: string
Expand Down
19 changes: 15 additions & 4 deletions packages/nlu-client/src/typings/index.d.ts
@@ -1,32 +1,41 @@
import { AxiosRequestConfig, AxiosInstance } from 'axios'
import {
TrainRequestBody,
LintRequestBody,
PredictRequestBody,
DetectLangRequestBody,
ErrorResponse,
SuccessReponse,
InfoResponseBody,
TrainResponseBody,
LintResponseBody,
TrainProgressResponseBody,
ListModelsResponseBody,
PruneModelsResponseBody,
PredictResponseBody,
DetectLangResponseBody,
ListTrainingsResponseBody
ListTrainingsResponseBody,
LintProgressResponseBody
} from './http'
import { AxiosRequestConfig, AxiosInstance } from 'axios'

export class Client {
readonly axios: AxiosInstance

constructor(config: AxiosRequestConfig)

getInfo(): Promise<InfoResponseBody | ErrorResponse>

startTraining(appId: string, trainRequestBody: TrainRequestBody): Promise<TrainResponseBody | ErrorResponse>
listTrainings(appId: string, lang?: string): Promise<ListTrainingsResponseBody | ErrorResponse>
getTrainingStatus(appId: string, modelId: string): Promise<TrainProgressResponseBody | ErrorResponse>
listTrainings(appId: string, lang?: string): Promise<ListTrainingsResponseBody | ErrorResponse>
cancelTraining(appId: string, modelId: string): Promise<SuccessReponse | ErrorResponse>

startLinting(appId: string, lintRequestBody: LintRequestBody): Promise<LintResponseBody | ErrorResponse>
getLintingStatus(appId: string, modelId: string): Promise<LintProgressResponseBody | ErrorResponse>

listModels(appId: string): Promise<ListModelsResponseBody | ErrorResponse>
pruneModels(appId: string): Promise<PruneModelsResponseBody | ErrorResponse>

detectLanguage(
appId: string,
detectLangRequestBody: DetectLangRequestBody
Expand All @@ -39,5 +48,7 @@ export class Client {
}

export * as http from './http'
export * from './sdk'
export * from './training'
export * from './prediction'
export * from './linting'
export * from './info'
14 changes: 14 additions & 0 deletions packages/nlu-client/src/typings/info.d.ts
@@ -0,0 +1,14 @@
export type ServerInfo = {
specs: Specifications
languages: string[]
version: string
}

export type Specifications = {
engineVersion: string // semver string
languageServer: {
dimensions: number
domain: string
version: string // semver string
}
}
2 changes: 1 addition & 1 deletion packages/nlu-client/src/typings/linting.d.ts
Expand Up @@ -73,7 +73,7 @@ export type LintingStatus = 'done' | 'linting-pending' | 'linting' | 'canceled'
export type LintingErrorType = 'lang-server' | 'duckling-server' | 'zombie-linting' | 'internal'

export type LintingError = {
type: TrainingErrorType
type: LintingErrorType
message: string
stack?: string
}
Expand Down
44 changes: 44 additions & 0 deletions packages/nlu-client/src/typings/prediction.d.ts
@@ -0,0 +1,44 @@
export type PredictOutput = {
entities: EntityPrediction[]
contexts: ContextPrediction[]
spellChecked: string
}

export type EntityType = 'pattern' | 'list' | 'system'

export type EntityPrediction = {
name: string
type: string // ex: ['custom.list.fruits', 'system.time']
value: string
confidence: number
source: string
start: number
end: number
unit?: string

sensitive?: boolean
}

export type ContextPrediction = {
name: string
oos: number
confidence: number
intents: IntentPrediction[]
}

export type IntentPrediction = {
name: string
confidence: number
slots: SlotPrediction[]
extractor: string
}

export type SlotPrediction = {
name: string
value: string
confidence: number
source: string
start: number
end: number
entity: EntityPrediction | null
}
@@ -1,24 +1,3 @@
export type ServerInfo = {
specs: Specifications
languages: string[]
version: string
}

export type Specifications = {
engineVersion: string // semver string
languageServer: {
dimensions: number
domain: string
version: string // semver string
}
}

/**
* ##################################
* ############ TRAINING ############
* ##################################
*/

export type TrainInput = {
language: string
intents: IntentDefinition[]
Expand Down Expand Up @@ -85,53 +64,3 @@ export type TrainingState = {
export type Training = TrainingState & {
modelId: string
}

/**
* ####################################
* ############ PREDICTION ############
* ####################################
*/
export type PredictOutput = {
entities: EntityPrediction[]
contexts: ContextPrediction[]
spellChecked: string
}

export type EntityType = 'pattern' | 'list' | 'system'

export type EntityPrediction = {
name: string
type: string // ex: ['custom.list.fruits', 'system.time']
value: string
confidence: number
source: string
start: number
end: number
unit?: string

sensitive?: boolean
}

export type ContextPrediction = {
name: string
oos: number
confidence: number
intents: IntentPrediction[]
}

export type IntentPrediction = {
name: string
confidence: number
slots: SlotPrediction[]
extractor: string
}

export type SlotPrediction = {
name: string
value: string
confidence: number
source: string
start: number
end: number
entity: EntityPrediction | null
}

0 comments on commit 5455dd0

Please sign in to comment.