Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating cognitiveservices-luis-authoring SDK #4792

Merged
Merged
94 changes: 48 additions & 46 deletions sdk/cognitiveservices/cognitiveservices-luis-authoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,85 @@ npm install @azure/cognitiveservices-luis-authoring

### How to use

#### nodejs - Authentication, client creation and listPhraseLists features as an example written in TypeScript.
#### nodejs - Authentication, client creation and listApplicationVersionPatternFeatures features as an example written in TypeScript.

##### Install @azure/ms-rest-nodeauth
##### Install @azure/ms-rest-azure-js

```bash
npm install @azure/ms-rest-nodeauth
npm install @azure/ms-rest-azure-js
```

##### Sample code

```typescript
import * as msRest from "@azure/ms-rest-js";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import { LUISAuthoringClient, LUISAuthoringModels, LUISAuthoringMappers } from "@azure/cognitiveservices-luis-authoring";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];

msRestNodeAuth.interactiveLogin().then((creds) => {
const client = new LUISAuthoringClient(creds, subscriptionId);
const appId = ec7b1657-199d-4d8a-bbb2-89a11a42e02a;
const versionId = "testversionId";
const skip = 1;
const take = 1;
client.features.listPhraseLists(appId, versionId, skip, take).then((result) => {
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
import { LUISAuthoringClient } from "@azure/cognitiveservices-luis-authoring";

let authoringKey = process.env["luis-authoring-key"];
const creds = new CognitiveServicesCredentials(authoringKey);

// check the following link to find your region
// https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-reference-regions
const region = "<your-region>";
const client = new LUISAuthoringClient(
creds,
"https://" + region + ".api.cognitive.microsoft.com/"
);

const appId = "<your-app-id>"; // replace this with your appId.
const versionId = "0.1"; // replace with version of your luis application. Initial value will be 0.1

const skip = 1;
const take = 1;

client.features
.listApplicationVersionPatternFeatures(appId, versionId, { skip, take })
.then((result) => {
console.log("The result is:");
console.log(result);
})
.catch((err) => {
console.error(err);
});
}).catch((err) => {
console.error(err);
});
```

#### browser - Authentication, client creation and listPhraseLists features as an example written in JavaScript.
#### browser - Authentication, client creation and listApplicationVersionPatternFeatures features as an example written in JavaScript.

##### Install @azure/ms-rest-browserauth

```bash
npm install @azure/ms-rest-browserauth
```

##### Sample code

See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.

- index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-luis-authoring sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/cognitiveservices-luis-authoring/dist/cognitiveservices-luis-authoring.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.CognitiveservicesLuisAuthoring.LUISAuthoringClient(res.creds, subscriptionId);
const appId = ec7b1657-199d-4d8a-bbb2-89a11a42e02a;
const versionId = "testversionId";
const skip = 1;
const take = 1;
client.features.listPhraseLists(appId, versionId, skip, take).then((result) => {
let authoringKey = process.env["luis-authoring-key"];
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': authoringKey } });

const region = "<your-region>";
const client = new Azure.CognitiveservicesLuisAuthoring.LUISAuthoringClient(
creds,
"https://" + region + ".api.cognitive.microsoft.com/"
);
const appId = "<your-app-id>"; // replace this with your appId.
const versionId = "0.1"; // replace with version of your luis application. Initial value will be 0.1
const skip = 1;
const take = 1;
client.features
.listApplicationVersionPatternFeatures(appId, versionId, { skip, take })
.then((result) => {
console.log("The result is:");
console.log(result);
}).catch((err) => {
})
.catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
Expand All @@ -101,5 +104,4 @@ See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)


![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-luis-authoring/README.png)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "@azure/cognitiveservices-luis-authoring",
"author": "Microsoft Corporation",
"description": "LUISAuthoringClient Library with typescript type definitions for node.js and browser.",
"version": "2.1.0",
"version": "3.0.0",
"dependencies": {
"@azure/ms-rest-js": "^1.6.0",
"tslib": "^1.9.3"
"@azure/ms-rest-js": "^2.0.3",
"tslib": "^1.10.0"
},
"keywords": [
"node",
Expand All @@ -28,10 +28,10 @@
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/cognitiveservices/cognitiveservices-luis-authoring",
"repository": {
"type": "git",
"url": "https://github.com/azure/azure-sdk-for-js.git"
"url": "https://github.com/Azure/azure-sdk-for-js.git"
},
"bugs": {
"url": "https://github.com/azure/azure-sdk-for-js/issues"
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"files": [
"dist/**/*.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import sourcemaps from "rollup-plugin-sourcemaps";
*/
const config = {
input: "./esm/lUISAuthoringClient.js",
external: [
"@azure/ms-rest-js",
"@azure/ms-rest-azure-js"
],
external: ["@azure/ms-rest-js", "@azure/ms-rest-azure-js"],
output: {
file: "./dist/cognitiveservices-luis-authoring.js",
format: "umd",
Expand All @@ -22,16 +19,14 @@ const config = {
},
banner: `/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*
ahmedabuamra marked this conversation as resolved.
Show resolved Hide resolved
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/`
},
plugins: [
nodeResolve({ module: true }),
sourcemaps()
]
plugins: [nodeResolve({ module: true }), sourcemaps()]
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/


import * as msRest from "@azure/ms-rest-js";
import * as Models from "./models";
import * as Mappers from "./models/mappers";
Expand All @@ -34,8 +34,8 @@ class LUISAuthoringClient extends LUISAuthoringClientContext {
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) {
super(endpoint, credentials, options);
constructor(credentials: msRest.ServiceClientCredentials, endpoint: string, options?: msRest.ServiceClientOptions) {
super(credentials, endpoint, options);
ramya-rao-a marked this conversation as resolved.
Show resolved Hide resolved
this.features = new operations.Features(this);
this.examples = new operations.Examples(this);
this.model = new operations.Model(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import * as msRest from "@azure/ms-rest-js";
Expand All @@ -24,12 +23,16 @@ export class LUISAuthoringClientContext extends msRest.ServiceClient {
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param [options] The parameter options
*/
constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) {
if (endpoint === null || endpoint === undefined) {
throw new Error('\'endpoint\' cannot be null.');
constructor(
credentials: msRest.ServiceClientCredentials,
endpoint: string,
options?: msRest.ServiceClientOptions
) {
if (endpoint == undefined) {
throw new Error("'endpoint' cannot be null.");
}
if (credentials === null || credentials === undefined) {
throw new Error('\'credentials\' cannot be null.');
if (credentials == undefined) {
throw new Error("'credentials' cannot be null.");
}

if (!options) {
Expand All @@ -43,7 +46,7 @@ export class LUISAuthoringClientContext extends msRest.ServiceClient {

super(credentials, options);

this.baseUri = "{Endpoint}";
this.baseUri = "{Endpoint}/luis/api/v2.0";
this.requestContentType = "application/json; charset=utf-8";
this.endpoint = endpoint;
this.credentials = credentials;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/


export {
AzureAccountInfoObject,
ErrorResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/


export {
ErrorResponse,
FeatureInfoObject,
Expand Down
Loading