fix(basic.gblib): update ChatServices.ts #420

Closed
eltociear wants to merge 2540 commits from patch-1 into main
2 changed files with 68 additions and 2 deletions
Showing only changes of commit 666c765503 - Show all commits

View file

@ -704,7 +704,46 @@ export class AzureDeployerService implements IGBInstallationDeployer {
req.headers.set('Content-Type', 'application/json'); req.headers.set('Content-Type', 'application/json');
req.headers.set('accept-language', '*'); req.headers.set('accept-language', '*');
req.headers.set('Ocp-Apim-Subscription-Key', nlpAuthoringKey); 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(); const httpClient = new ServiceClient();
return await httpClient.sendRequest(req); return await httpClient.sendRequest(req);

View file

@ -245,6 +245,33 @@ export class GBDeployer implements IGBDeployer {
return await this.core.saveInstance(instance); return await this.core.saveInstance(instance);
} }
public async publishNLP(instance: IGBInstance): Promise<void> {
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<void> {
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<void> { public async refreshNLPEntity(instance: IGBInstance, listName, listData): Promise<void> {
const service = new AzureDeployerService(this); const service = new AzureDeployerService(this);
const res = await service.refreshEntityList( const res = await service.refreshEntityList(
@ -255,7 +282,7 @@ export class GBDeployer implements IGBDeployer {
listData listData
); );
if(res.status !== 200) throw res.bodyAsText; if(res.status !== 200) throw res.bodyAsText;
GBLog.info(res);
} }
/** /**