Skip to content

Commit 3ee3c7f

Browse files
committed
Sample Fixes
1 parent 2e3061f commit 3ee3c7f

File tree

1 file changed

+73
-78
lines changed
  • articles/cognitive-services/language-service/summarization/includes/quickstarts

1 file changed

+73
-78
lines changed

articles/cognitive-services/language-service/summarization/includes/quickstarts/nodejs-sdk.md

Lines changed: 73 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ npm init
5050
Install the npm packages:
5151

5252
```console
53-
npm install --save @azure/ai-[email protected].0-beta.1
53+
npm install --save @azure/ai-[email protected].0-beta.1
5454
```
5555

5656
> [!div class="nextstepaction"]
@@ -63,88 +63,83 @@ Open the file and copy the below code. Remember to replace the `key` variable wi
6363
[!INCLUDE [find the key and endpoint for a resource](../../../includes/find-azure-resource-info.md)]
6464

6565
```javascript
66-
"use strict";
67-
68-
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
69-
const key = '<paste-your-key-here>';
70-
const endpoint = '<paste-your-endpoint-here>';
71-
// Authenticate the client with your key and endpoint
72-
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
73-
74-
// Example method for summarizing text
75-
async function summarization_example(client) {
76-
const documents = [`The extractive summarization feature uses natural language processing techniques to locate key sentences in an unstructured text document.
77-
These sentences collectively convey the main idea of the document. This feature is provided as an API for developers.
78-
They can use it to build intelligent solutions based on the relevant information extracted to support various use cases.
79-
In the public preview, extractive summarization supports several languages. It is based on pretrained multilingual transformer models, part of our quest for holistic representations.
80-
It draws its strength from transfer learning across monolingual and harness the shared nature of languages to produce models of improved quality and efficiency.`];
81-
82-
console.log("== Analyze Sample For Extract Summary ==");
83-
84-
const actions = {
85-
extractSummaryActions: [{ modelVersion: "latest", orderBy: "Rank", maxSentenceCount: 5 }],
86-
};
87-
const poller = await client.beginAnalyzeActions(documents, actions, "en");
88-
89-
poller.onProgress(() => {
90-
console.log(
91-
`Number of actions still in progress: ${poller.getOperationState().actionsInProgressCount}`
92-
);
93-
});
94-
95-
console.log(`The analyze actions operation created on ${poller.getOperationState().createdOn}`);
96-
66+
/**
67+
* This sample program extracts a summary of two sentences at max from an article.
68+
* For more information, see the feature documentation: {@link https://learn.microsoft.com/azure/cognitive-services/language-service/summarization/overview}
69+
*
70+
* @summary extracts a summary from an article
71+
*/
72+
73+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
74+
75+
// Load the .env file if it exists
76+
require("dotenv").config();
77+
78+
// You will need to set these environment variables or edit the following values
79+
const endpoint = process.env["ENDPOINT"] || "<paste-your-endpoint-here>";
80+
const apiKey = process.env["LANGUAGE_API_KEY"] || "<paste-your-key-here>";
81+
82+
const documents = [
83+
`
84+
Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?”
85+
In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account. From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop.
86+
“And then, when you’re done, you’re done. You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud.
87+
The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise.
88+
“I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization. This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said.
89+
The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure.
90+
We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped. So, we actually had terminated the project and rolled back out to just regular PCs.”
91+
He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly.
92+
“The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said.
93+
“Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”`,
94+
];
95+
96+
async function main() {
97+
console.log("== Extractive Summarization Sample ==");
98+
99+
const client = new TextAnalysisClient(endpoint, new AzureKeyCredential(apiKey));
100+
const actions = [
101+
{
102+
kind: "ExtractiveSummarization",
103+
maxSentenceCount: 2,
104+
},
105+
];
106+
const poller = await client.beginAnalyzeBatch(actions, documents, "en");
107+
108+
poller.onProgress(() => {
97109
console.log(
98-
`The analyze actions operation results will expire on ${poller.getOperationState().expiresOn}`
110+
`Last time the operation was updated was on: ${poller.getOperationState().modifiedOn}`
99111
);
100-
101-
const resultPages = await poller.pollUntilDone();
102-
103-
for await (const page of resultPages) {
104-
const extractSummaryAction = page.extractSummaryResults[0];
105-
if (!extractSummaryAction.error) {
106-
for (const doc of extractSummaryAction.results) {
107-
console.log(`- Document ${doc.id}`);
108-
if (!doc.error) {
109-
console.log("\tSummary:");
110-
for (const sentence of doc.sentences) {
111-
console.log(`\t- ${sentence.text}`);
112-
}
113-
} else {
114-
console.error("\tError:", doc.error);
115-
}
116-
}
117-
}
118-
}
112+
});
113+
console.log(`The operation was created on ${poller.getOperationState().createdOn}`);
114+
console.log(`The operation results will expire on ${poller.getOperationState().expiresOn}`);
115+
116+
const results = await poller.pollUntilDone();
117+
118+
for await (const actionResult of results) {
119+
if (actionResult.kind !== "ExtractiveSummarization") {
120+
throw new Error(`Expected extractive summarization results but got: ${actionResult.kind}`);
121+
}
122+
if (actionResult.error) {
123+
const { code, message } = actionResult.error;
124+
throw new Error(`Unexpected error (${code}): ${message}`);
125+
}
126+
for (const result of actionResult.results) {
127+
console.log(`- Document ${result.id}`);
128+
if (result.error) {
129+
const { code, message } = result.error;
130+
throw new Error(`Unexpected error (${code}): ${message}`);
131+
}
132+
console.log("Summary:");
133+
console.log(result.sentences.map((sentence) => sentence.text).join("\n"));
134+
}
135+
}
119136
}
120-
summarization_example(textAnalyticsClient).catch((err) => {
121-
console.error("The sample encountered an error:", err);
122-
});
123-
```
124-
125-
> [!div class="nextstepaction"]
126-
> <a href="https://github.com/Azure/azure-sdk-for-js/issues/new?title=&body=%0A-%20**Package%20Name**:%20%0A-%20**Package%20Version**:%20%0A-%20**Operating%20System**:%20%0A-%20**Node.js%20version**:%20%0A-%20**Browser%20name%20and%20version**:%20%0A-%20**Typescript%20version**:%20%0A%0A%5BEnter%20feedback%20here%5D%0A%0A%0A---%0A%23%23%23%23%20Document%20details%0A%0A⚠%20*Do%20not%20edit%20this%20section.%20It%20is%20required%20for%20learn.microsoft.com%20➟%20GitHub%20issue%20linking.%0A%0ALanguage%20Quickstart%20Feedback%0A*%20Content:%20%5BQuickstart:%20using%20document%20summarization%20and%20conversation%20summarization%20(preview)%20-%20Azure%20Cognitive%20Services%5D(https:%2F%2Flearn.microsoft.com%2Fazure%2Fcognitive-services%2Flanguage-service%2Fsummarization%2Fquickstart%3Fpivots%3Dprogramming-language-javascript)%0A*%20Content%20Source:%20%5Barticles%2Fcognitive-services%2Flanguage-service%2Fsummarization%2Fquickstart.md%5D(https:%2F%2Fgithub.com%2FMicrosoftDocs%2Fazure-docs%2Fblob%2Fmain%2Farticles%2Fcognitive-services%2Flanguage-service%2Fsummarization%2Fquickstart.md)%0A*%20Section:%20**Code-example**%0A*%20Service:%20**cognitive-services**%0A*%20Sub-service:%20**language-service**%0A&labels=Cognitive%20-%20Language%2CCognitive%20Language%20QS%20Feedback" target="_target">I ran into an issue</a>
127-
128-
### Command
129137

130-
```console
131-
node index.js
132-
```
133-
### Output
138+
main().catch((err) => {
139+
console.error("The sample encountered an error:", err);
140+
});
134141

135-
```console
136-
== Analyze Sample For Extract Summary ==
137-
The analyze actions operation created on Thu Sep 16 2021 13:12:31 GMT-0700 (Pacific Daylight Time)
138-
The analyze actions operation results will expire on Fri Sep 17 2021 13:12:31 GMT-0700 (Pacific Daylight Time)
139-
140-
- Document 0
141-
Summary:
142-
- They can use it to build intelligent solutions based on the relevant information extracted to support various use cases.
143-
- This feature is provided as an API for developers.
144-
- The extractive summarization feature uses natural language processing techniques to locate key sentences in an unstructured
145-
text document.
146-
- These sentences collectively convey the main idea of the document.
147-
- In the public preview, extractive summarization supports several languages.
142+
module.exports = { main };
148143
```
149144

150145
## Clean up resources

0 commit comments

Comments
 (0)