Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 213c424

Browse files
Switch luis sdk to node-fetch (#829)
* Switch luis sdk to node-fetch * Fixing export in lubuild Co-authored-by: Vishwac Sena Kannan <[email protected]>
1 parent 3323a48 commit 213c424

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

packages/lu/src/parser/lubuild/core.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,20 @@ export class LuBuildCore {
126126
}
127127

128128
public async exportApplication(appId: string, versionId: string) {
129-
let response
129+
const url = this.endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/versions/' + versionId + '/export?format=json'
130+
const headers = {
131+
'Content-Type': 'application/json',
132+
'Ocp-Apim-Subscription-Key': this.subscriptionKey
133+
}
134+
135+
let messageData
130136
let retryCount = this.retryCount + 1
131137
let error
132138
while (retryCount > 0) {
133139
if (error === undefined || error.statusCode === rateLimitErrorCode) {
134140
try {
135-
response = await this.client.versions.exportMethod(appId, versionId)
141+
const response = await fetch(url, {method: 'GET', headers})
142+
messageData = await response.json()
136143
break
137144
} catch (e) {
138145
error = e
@@ -148,7 +155,11 @@ export class LuBuildCore {
148155
throw error
149156
}
150157

151-
return response
158+
if (messageData.error) {
159+
throw (new exception(retCode.errorCode.LUIS_API_CALL_FAILED, messageData.error.message))
160+
}
161+
162+
return messageData
152163
}
153164

154165
public compareApplications(currentApp: any, existingApp: any) {

packages/luis/src/commands/luis/version/export.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7+
import fetch from 'node-fetch'
78

89
const utils = require('../../../utils/index')
910

@@ -41,16 +42,25 @@ export default class LuisVersionExport extends Command {
4142
const requiredProps = {appId, versionId, endpoint, subscriptionKey}
4243
utils.validateRequiredProps(requiredProps)
4344

44-
const client = utils.getLUISClient(subscriptionKey, endpoint)
45-
4645
try {
47-
const appJSON = await client.versions.exportMethod(appId, versionId)
48-
if (!appJSON) throw new CLIError('Failed to export file')
46+
let url = endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/versions/' + versionId + '/export?format=json'
47+
const headers = {
48+
'Content-Type': 'application/json',
49+
'Ocp-Apim-Subscription-Key': subscriptionKey
50+
}
51+
52+
const response = await fetch(url, {method: 'GET', headers})
53+
const messageData = await response.json()
54+
55+
if (messageData.error) {
56+
throw new CLIError(messageData.error.message)
57+
}
58+
4959
if (out) {
50-
const writtenFilePath: string = await utils.writeToFile(out, appJSON, force)
60+
const writtenFilePath: string = await utils.writeToFile(out, messageData, force)
5161
this.log(`File successfully written: ${writtenFilePath}`)
5262
} else {
53-
await utils.writeToConsole(appJSON)
63+
await utils.writeToConsole(messageData)
5464
}
5565
} catch (error) {
5666
throw new CLIError(error)

packages/luis/test/commands/luis/version/export.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ describe('luis:version:export', () => {
5151
test
5252
.nock('https://westus.api.cognitive.microsoft.com', api => api
5353
.get(uri => uri.includes('export'))
54-
.reply(200, {name: 'testname'})
54+
.reply(200, {
55+
name: "Utilities.Cancel",
56+
inherits: {
57+
domain_name: "Utilities",
58+
model_name: "Cancel"
59+
},
60+
"features": []
61+
})
5562
)
5663
.stdout()
5764
.command(['luis:version:export', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com'])
5865
.it('exports a luis app and displays the export contents in the console', ctx => {
59-
expect(ctx.stdout).to.contain('testname')
66+
expect(ctx.stdout).to.contain('domain_name')
6067
})
6168

6269
test

0 commit comments

Comments
 (0)