From 666c76550315f2ab7f3657a2cdd007f8a3e7135d Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sun, 18 Oct 2020 21:28:19 -0300 Subject: [PATCH] new(core.gbapp): More NLP automation. --- .../services/AzureDeployerService.ts | 41 ++++++++++++++++++- packages/core.gbapp/services/GBDeployer.ts | 29 ++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts index 3b484303..3d46be81 100644 --- a/packages/azuredeployer.gbapp/services/AzureDeployerService.ts +++ b/packages/azuredeployer.gbapp/services/AzureDeployerService.ts @@ -704,7 +704,46 @@ export class AzureDeployerService implements IGBInstallationDeployer { req.headers.set('Content-Type', 'application/json'); req.headers.set('accept-language', '*'); req.headers.set('Ocp-Apim-Subscription-Key', nlpAuthoringKey); - req.body = data; + req.body = JSON.stringify(data); + const httpClient = new ServiceClient(); + + return await httpClient.sendRequest(req); + } + + public async trainNLP( + location: string, + nlpAppId: string, + nlpAuthoringKey: string, + ) { + + const req = new WebResource(); + req.method = 'POST'; + req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/apps/${nlpAppId}/versions/0.1/train`; + req.headers.set('Content-Type', 'application/json'); + req.headers.set('accept-language', '*'); + req.headers.set('Ocp-Apim-Subscription-Key', nlpAuthoringKey); + const httpClient = new ServiceClient(); + + return await httpClient.sendRequest(req); + } + + public async publishNLP( + location: string, + nlpAppId: string, + nlpAuthoringKey: string, + ) { + const body = { + versionId: "0.1", + isStaging: false, + directVersionPublish: false + } + const req = new WebResource(); + req.method = 'POST'; + req.url = `https://${location}.api.cognitive.microsoft.com/luis/api/v2.0/apps/${nlpAppId}/publish`; + req.headers.set('Content-Type', 'application/json'); + req.headers.set('accept-language', '*'); + req.headers.set('Ocp-Apim-Subscription-Key', nlpAuthoringKey); + req.body = body; const httpClient = new ServiceClient(); return await httpClient.sendRequest(req); diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 51be1659..a007fbef 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -245,6 +245,33 @@ export class GBDeployer implements IGBDeployer { return await this.core.saveInstance(instance); } + public async publishNLP(instance: IGBInstance): Promise { + const service = new AzureDeployerService(this); + const res = await service.publishNLP( + instance.cloudLocation, + instance.nlpAppId, + instance.nlpAuthoringKey, + ); + if(res.status !== 200) throw res.bodyAsText; + + } + + public async trainNLP(instance: IGBInstance): Promise { + const service = new AzureDeployerService(this); + const res = await service.trainNLP( + instance.cloudLocation, + instance.nlpAppId, + instance.nlpAuthoringKey, + ); + if(res.status !== 200) throw res.bodyAsText; + let sleep = ms => { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); + }; + sleep(5000); + } + public async refreshNLPEntity(instance: IGBInstance, listName, listData): Promise { const service = new AzureDeployerService(this); const res = await service.refreshEntityList( @@ -255,7 +282,7 @@ export class GBDeployer implements IGBDeployer { listData ); if(res.status !== 200) throw res.bodyAsText; - GBLog.info(res); + } /**