一个异形的 Javascript sdk 用于 - LUISRuntime Client
这个软件包中包含LUISRuntimeClient的同位素 SDK.
目前得到支持的环境
- 节点.js 6.x.x 或更高版本
- 浏览器 JavaScript
如何安装
npm install @azure/cognitiveservices-luis-runtime
如何使用
nodejs - 认证,客户端创建并获得Version预测作为TypeScript所写的示例.
安装@azure/ ms-rest-azure-js
npm install @azure/ms-rest-azure-js
样本代码
import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js";
import { LUISRuntimeClient } from "@azure/cognitiveservices-luis-runtime";
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 LUISRuntimeClient(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 predictionRequest = {
query: "testquery",
options: {
datetimeReference: new Date(),
preferExternalEntities: true
},
externalEntities: [
{
entityName: "testentityName",
startIndex: 1,
entityLength: 1,
score: 0.86,
resolution: {}
}
],
dynamicLists: [
{
listEntityName: "testlistEntityName",
requestLists: [
{
name: "testname",
canonicalForm: "testcanonicalForm",
synonyms: ["testsynonyms"]
}
]
}
]
};
const verbose = true;
const showAllIntents = true;
client.prediction
.getVersionPrediction(appId, versionId, predictionRequest, { verbose, showAllIntents })
.then((result) => {
console.log("The result is:");
console.log(result);
})
.catch((err) => {
console.error(err);
});
浏览器 - 认证,客户端创建并获得Version预测作为JavaScript所写的示例.
样本代码
- 索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-luis-runtime sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/cognitiveservices-luis-runtime/dist/cognitiveservices-luis-runtime.js"></script>
<script type="text/javascript">
let authoringKey = process.env["luis-authoring-key"];
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': 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 Azure.CognitiveservicesLuisRuntime.LUISRuntimeClient(
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 predictionRequest = {
query: "testquery",
options: {
datetimeReference: new Date(),
preferExternalEntities: true
},
externalEntities: [
{
entityName: "testentityName",
startIndex: 1,
entityLength: 1,
score: 0.9,
resolution: {}
}
],
dynamicLists: [
{
listEntityName: "testlistEntityName",
requestLists: [
{
name: "testname",
canonicalForm: "testcanonicalForm",
synonyms: ["testsynonyms"]
}
]
}
]
};
const verbose = true;
const showAllIntents = true;
client.prediction
.getVersionPrediction(appId, versionId, predictionRequest, { verbose, showAllIntents })
.then((result) => {
console.log("The result is:");
console.log(result);
})
.catch((err) => {
console.error(err);
});
</script>
</head>
<body></body>
</html>
相关项目
