Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 79 additions & 20 deletions sdk/cognitiveservices/cognitiveservices-qnamaker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## An isomorphic javascript sdk for - QnAMakerClient
## An isomorphic javascript sdk for - QnAMakerRuntimeClient

This package contains an isomorphic SDK for QnAMakerClient.
This package contains an isomorphic SDK for QnAMakerRuntimeClient.

### Currently supported environments

Expand All @@ -15,30 +15,62 @@ npm install @azure/cognitiveservices-qnamaker

### How to use

#### nodejs - Authentication, client creation and getKeys endpointKeys as an example written in TypeScript.
#### nodejs - Authentication, client creation and generateAnswer runtime as an example written in TypeScript.

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

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

##### Sample code

```typescript
import * as msRest from "@azure/ms-rest-js";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import { QnAMakerClient, QnAMakerModels, QnAMakerMappers } from "@azure/cognitiveservices-qnamaker";
import { QnAMakerRuntimeClient, QnAMakerRuntimeModels, QnAMakerRuntimeMappers } from "@azure/cognitiveservices-qnamaker";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
const endpoint = "https://westus.api.cognitive.microsoft.com"; // OR some other endpoint.
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscriptionId }});
const client = new QnAMakerClient(creds, endpoint);
client.endpointKeys.getKeys().then((result) => {
console.log("The result is:");
console.log(result);

msRestNodeAuth.interactiveLogin().then((creds) => {
const client = new QnAMakerRuntimeClient(creds, subscriptionId);
const kbId = "testkbId";
const generateAnswerPayload: QnAMakerRuntimeModels.QueryDTO = {
qnaId: "testqnaId",
question: "testquestion",
top: 1,
userId: "testuserId",
isTest: true,
scoreThreshold: 1.01,
context: {
previousQnaId: "testpreviousQnaId",
previousUserQuery: "testpreviousUserQuery"
},
strictFilters: [{
name: "testname",
value: "testvalue"
}]
};
client.runtime.generateAnswer(kbId, generateAnswerPayload).then((result) => {
console.log("The result is:");
console.log(result);
});
}).catch((err) => {
console.error(err);
});
```

#### browser - Authentication, client creation and getKeys endpointKeys as an example written in JavaScript.
#### browser - Authentication, client creation and generateAnswer runtime 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>
Expand All @@ -50,15 +82,40 @@ client.endpointKeys.getKeys().then((result) => {
<script src="node_modules/@azure/cognitiveservices-qnamaker/dist/cognitiveservices-qnamaker.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscriptionId }});
const endpoint = "https://westus.api.cognitive.microsoft.com"; // OR some other endpoint.
const client = new Azure.CognitiveservicesQnamaker.QnAMakerClient(creds, endpoint);
client.endpointKeys.getKeys().then((result) => {
console.log("The result is:");
console.log(result);
}).catch((err) => {
console.log("An error occurred:");
console.error(err);
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.CognitiveservicesQnamaker.QnAMakerRuntimeClient(res.creds, subscriptionId);
const kbId = "testkbId";
const generateAnswerPayload = {
qnaId: "testqnaId",
question: "testquestion",
top: 1,
userId: "testuserId",
isTest: true,
scoreThreshold: 1.01,
context: {
previousQnaId: "testpreviousQnaId",
previousUserQuery: "testpreviousUserQuery"
},
strictFilters: [{
name: "testname",
value: "testvalue"
}]
};
client.runtime.generateAnswer(kbId, generateAnswerPayload).then((result) => {
console.log("The result is:");
console.log(result);
}).catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
Expand All @@ -69,3 +126,5 @@ client.endpointKeys.getKeys().then((result) => {
## Related projects

- [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-qnamaker/README.png)
16 changes: 8 additions & 8 deletions sdk/cognitiveservices/cognitiveservices-qnamaker/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@azure/cognitiveservices-qnamaker",
"author": "Microsoft Corporation",
"description": "QnAMakerClient Library with typescript type definitions for node.js and browser.",
"description": "QnAMakerRuntimeClient Library with typescript type definitions for node.js and browser.",
"version": "2.0.0",
"dependencies": {
"@azure/ms-rest-js": "^1.8.4",
"tslib": "^1.9.3"
"@azure/ms-rest-js": "^2.0.3",
"tslib": "^1.10.0"
},
"keywords": [
"node",
Expand All @@ -16,22 +16,22 @@
],
"license": "MIT",
"main": "./dist/cognitiveservices-qnamaker.js",
"module": "./esm/qnAMakerClient.js",
"types": "./esm/qnAMakerClient.d.ts",
"module": "./esm/qnAMakerRuntimeClient.js",
"types": "./esm/qnAMakerRuntimeClient.d.ts",
"devDependencies": {
"typescript": "^3.1.1",
"rollup": "^0.66.2",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"uglify-js": "^3.4.9"
},
"homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/cognitiveservices/cognitiveservices-qnamaker",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/cognitiveservices/cognitiveservices-qnamaker",
"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 @@ -6,7 +6,7 @@ import sourcemaps from "rollup-plugin-sourcemaps";
* @type {rollup.RollupFileOptions}
*/
const config = {
input: "./esm/qnAMakerClient.js",
input: "./esm/qnAMakerRuntimeClient.js",
external: [
"@azure/ms-rest-js",
"@azure/ms-rest-azure-js"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* 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 {
ActiveLearningSettingsDTO,
EndpointSettingsDTO,
EndpointSettingsDTOActiveLearning,
ErrorModel,
ErrorResponse,
ErrorResponseError,
InnerErrorModel
} from "../models/mappers";
Loading