Skip to content

Commit 8593d06

Browse files
authored
Merge pull request #215456 from aahill/resource-test
quickstart update - resource provisioning + environment variables
2 parents 197c05b + f55d23e commit 8593d06

File tree

13 files changed

+229
-65
lines changed

13 files changed

+229
-65
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
services: cognitive-services
3+
author: aahill
4+
manager: nitinme
5+
ms.service: cognitive-services
6+
ms.subservice: language-service
7+
ms.topic: include
8+
ms.date: 10/21/2022
9+
ms.author: aahi
10+
---
11+
12+
Use the following commands to delete the environment variables you created for this quickstart.
13+
14+
#### [Windows](#tab/windows)
15+
16+
```console
17+
reg delete "HKCU\Environment" /v LANGUAGE_KEY /f
18+
```
19+
20+
```console
21+
reg delete "HKCU\Environment" /v LANGUAGE_ENDPOINT /f
22+
```
23+
24+
#### [Linux](#tab/linux)
25+
26+
```bash
27+
unset LANGUAGE_KEY
28+
```
29+
30+
```bash
31+
unset LANGUAGE_ENDPOINT
32+
```
33+
34+
#### [macOS](#tab/macos)
35+
36+
```bash
37+
unset LANGUAGE_KEY
38+
```
39+
40+
```bash
41+
unset LANGUAGE_ENDPOINT
42+
```
43+
44+
---
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
services: cognitive-services
3+
author: aahill
4+
manager: nitinme
5+
ms.service: cognitive-services
6+
ms.subservice: language-service
7+
ms.topic: include
8+
ms.date: 10/21/2022
9+
ms.author: aahi
10+
---
11+
12+
### Create an Azure resource
13+
14+
To use the code sample below, you'll need to deploy an Azure resource. This resource will contain a key and endpoint you'll use to authenticate the API calls you send to the Language service.
15+
16+
1. Use the following link to [create a language resource](https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics) using the Azure portal. You will need to sign in using your Azure subscription.
17+
1. On the **Select additional features** screen that appears, select **Continue to create your resource**.
18+
19+
:::image type="content" source="../media/portal-resource-additional-features.png" alt-text="A screenshot showing additional feature options in the Azure portal." lightbox="../media/portal-resource-additional-features.png":::
20+
21+
1. In the **Create language** screen, provide the following information:
22+
23+
|Detail |Description |
24+
|---------|---------|
25+
|Subscription | The subscription account that your resource will be associated with. Select your Azure subscription from the drop-down menu. |
26+
|Resource group | A resource group is a container that stores the resources you create. Select **Create new** to create a new resource group. |
27+
|Region | The location of your Language resource. Different regions may introduce latency depending on your physical location, but have no impact on the runtime availability of your resource. For this quickstart, either select an available region near you, or choose **East US**. |
28+
|Name | The name for your Language resource. This name will also be used to create an endpoint URL that your applications will use to send API requests. |
29+
|Pricing tier | The [pricing tier](https://azure.microsoft.com/pricing/details/cognitive-services/language-service/) for your Language resource. You can use the **Free F0** tier to try the service and upgrade later to a paid tier for production. |
30+
31+
:::image type="content" source="../media/portal-resource-creation-details.png" alt-text="A screenshot showing resource creation details in the Azure portal." lightbox="../media/portal-resource-creation-details.png":::
32+
33+
1. Make sure the **Responsible AI Notice** checkbox is checked.
34+
1. Select **Review + Create** at the bottom of the page.
35+
36+
1. In the screen that appears, make sure the validation has passed, and that you entered your information correctly. Then click **Create**.
37+
38+
### Get your key and endpoint
39+
40+
Next you will need the key and endpoint from the resource to connect your application to the API. You'll paste your key and endpoint into the code later in the quickstart.
41+
42+
1. After the Language resource deploys successfully, click the **Go to Resource** button under **Next Steps**.
43+
44+
:::image type="content" source="../media/portal-resource-next-steps.png" alt-text="A screenshot showing the next steps after a resource has deployed." lightbox="../media/portal-resource-next-steps.png":::
45+
46+
1. On the screen for your resource, select **Keys and endpoint** on the left navigation menu. You will use one of your keys and your endpoint in the steps below.
47+
48+
:::image type="content" source="../media/azure-portal-resource-credentials.png" alt-text="A screenshot showing the keys and endpoint section for a resource." lightbox="../media/azure-portal-resource-credentials.png":::
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
services: cognitive-services
3+
author: aahill
4+
manager: nitinme
5+
ms.service: cognitive-services
6+
ms.subservice: language-service
7+
ms.topic: include
8+
ms.date: 10/21/2022
9+
ms.author: aahi
10+
---
11+
12+
### Create environment variables
13+
14+
Your application must be authenticated to send API requests. For production, use a secure way of storing and accessing your credentials. In this example, you will write your credentials to environment variables on the local machine running the application.
15+
16+
> [!TIP]
17+
> Don't include the key directly in your code, and never post it publicly. See the Cognitive Services [security](../../security-features.md) article for more authentication options like [Azure Key Vault](../../use-key-vault.md).
18+
19+
To set the environment variable for your Language resource key, open a console window, and follow the instructions for your operating system and development environment.
20+
21+
1. To set the `LANGUAGE_KEY` environment variable, replace `your-key` with one of the keys for your resource.
22+
2. To set the `LANGUAGE_ENDPOINT` environment variable, replace `your-endpoint` with the endpoint for your resource.
23+
24+
#### [Windows](#tab/windows)
25+
26+
```console
27+
setx LANGUAGE_KEY your-key
28+
```
29+
30+
```console
31+
setx LANGUAGE_ENDPOINT your-endpoint
32+
```
33+
34+
> [!NOTE]
35+
> If you only need to access the environment variables in the current running console, you can set the environment variable with `set` instead of `setx`.
36+
37+
After you add the environment variables, you may need to restart any running programs that will need to read the environment variables, including the console window. For example, if you are using Visual Studio as your editor, restart Visual Studio before running the example.
38+
39+
#### [Linux](#tab/linux)
40+
41+
```bash
42+
export LANGUAGE_KEY=your-key
43+
```
44+
45+
```bash
46+
export LANGUAGE_ENDPOINT=your-endpoint
47+
```
48+
49+
After you add the environment variables, run `source ~/.bashrc` from your console window to make the changes effective.
50+
51+
#### [macOS](#tab/macos)
52+
53+
##### Bash
54+
55+
Edit your `.bash_profile`, and add the environment variables:
56+
57+
```bash
58+
export LANGUAGE_KEY=your-key
59+
```
60+
61+
```bash
62+
export LANGUAGE_ENDPOINT=your-endpoint
63+
```
64+
65+
After you add the environment variables, run `source ~/.bash_profile` from your console window to make the changes effective.
66+
67+
##### Xcode
68+
69+
For iOS and macOS development, you set the environment variables in Xcode. For example, follow these steps to set the environment variable in Xcode 13.4.1.
70+
71+
1. Select **Product** > **Scheme** > **Edit scheme**
72+
1. Select **Arguments** on the **Run** (Debug Run) page
73+
1. Under **Environment Variables** select the plus (+) sign to add a new environment variable.
74+
1. Enter `LANGUAGE_KEY` for the **Name** and enter your Language resource key for the **Value**.
75+
1. Perform these steps for your resource endpoint. Name the new environment variable `LANGUAGE_ENDPOINT`.
76+
77+
For more configuration options, see the [Xcode documentation](https://help.apple.com/xcode/#/dev745c5c974).
78+
79+
---
-13 KB
Loading
189 KB
Loading
215 KB
Loading
146 KB
Loading

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/csharp-sdk.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ manager: nitinme
44
ms.service: cognitive-services
55
ms.subservice: language-service
66
ms.topic: include
7-
ms.date: 09/15/2022
7+
ms.date: 10/21/2022
88
ms.author: aahi
99
ms.custom: ignite-fall-2021
1010
---
@@ -13,24 +13,20 @@ ms.custom: ignite-fall-2021
1313

1414
Use this quickstart to create a sentiment analysis application with the client library for .NET. In the following example, you will create a C# application that can identify the sentiment(s) expressed in a text sample, and perform aspect-based sentiment analysis.
1515

16-
17-
[!INCLUDE [Use Language Studio](../../../includes/use-language-studio.md)]
18-
19-
2016
## Prerequisites
2117

2218
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
2319
* The [Visual Studio IDE](https://visualstudio.microsoft.com/vs/)
24-
* Once you have your Azure subscription, <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics" title="Create a Language resource" target="_blank">create a Language resource </a> in the Azure portal to get your key and endpoint. After it deploys, click **Go to resource**.
25-
* You will need the key and endpoint from the resource you create to connect your application to the API. You'll paste your key and endpoint into the code below later in the quickstart.
26-
* You can use the free pricing tier (`Free F0`) to try the service, and upgrade later to a paid tier for production.
27-
* To use the Analyze feature, you will need a Language resource with the standard (S) pricing tier.
2820

2921
> [!div class="nextstepaction"]
3022
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=CSHARP&Pillar=Language&Product=Sentiment-analysis&Page=quickstart&Section=Prerequisites" target="_target">I ran into an issue</a>
3123
3224
## Setting up
3325

26+
[!INCLUDE [Create an Azure resource](../../../includes/create-resource.md)]
27+
28+
[!INCLUDE [Create environment variables](../../../includes/environment-variables.md)]
29+
3430
### Create a new .NET Core application
3531

3632
Using the Visual Studio IDE, create a new .NET Core console app. This will create a "Hello World" project with a single C# source file: *program.cs*.
@@ -42,9 +38,7 @@ Install the client library by right-clicking on the solution in the **Solution E
4238
4339
## Code example
4440

45-
Copy the following code into your *program.cs* file. Remember to replace the `key` variable with the key for your resource, and replace the `endpoint` variable with the endpoint for your resource.
46-
47-
[!INCLUDE [find the key and endpoint for a resource](../../../includes/find-azure-resource-info.md)]
41+
Copy the following code into your *program.cs* file.
4842

4943
```csharp
5044
using Azure;
@@ -56,8 +50,12 @@ namespace Example
5650
{
5751
class Program
5852
{
59-
private static readonly AzureKeyCredential credentials = new AzureKeyCredential("replace-with-your-key-here");
60-
private static readonly Uri endpoint = new Uri("replace-with-your-endpoint-here");
53+
// This example requires environment variables named "LANGUAGE_KEY" and "LANGUAGE_ENDPOINT"
54+
static string languageKey = Environment.GetEnvironmentVariable("LANGUAGE_KEY");
55+
static string languageEndpoint = Environment.GetEnvironmentVariable("LANGUAGE_ENDPOINT");
56+
57+
private static readonly AzureKeyCredential credentials = new AzureKeyCredential(languageKey);
58+
private static readonly Uri endpoint = new Uri(languageEndpoint);
6159

6260
// Example method for detecting opinions text.
6361
static void SentimentAnalysisWithOpinionMiningExample(TextAnalyticsClient client)
@@ -163,6 +161,8 @@ Document sentiment: Mixed
163161

164162
[!INCLUDE [clean up resources](../../../includes/clean-up-resources.md)]
165163

164+
[!INCLUDE [clean up environment variables](../../../includes/clean-up-variables.md)]
165+
166166
> [!div class="nextstepaction"]
167167
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=REST API&Pillar=Language&Product=Entity-linking&Page=quickstart&Section=Clean-up-resources" target="_target">I ran into an issue</a>
168168

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/java-sdk.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ manager: nitinme
44
ms.service: cognitive-services
55
ms.subservice: language-service
66
ms.topic: include
7-
ms.date: 09/15/2022
7+
ms.date: 10/21/2022
88
ms.custom: devx-track-java, ignite-fall-2021
99
ms.author: aahi
1010
---
@@ -13,23 +13,21 @@ ms.author: aahi
1313

1414
Use this quickstart to create a sentiment analysis application with the client library for Java. In the following example, you will create a Java application that can identify the sentiment(s) expressed in a text sample, and perform aspect-based sentiment analysis.
1515

16-
[!INCLUDE [Use Language Studio](../../../includes/use-language-studio.md)]
17-
1816
## Prerequisites
1917

2018
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
2119
* [Java Development Kit](https://www.oracle.com/technetwork/java/javase/downloads/index.html) (JDK) with version 8 or above
22-
* Once you have your Azure subscription, <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics" title="Create a Language resource" target="_blank">create a Language resource </a> in the Azure portal to get your key and endpoint. After it deploys, click **Go to resource**.
23-
* You will need the key and endpoint from the resource you create to connect your application to the API. You'll paste your key and endpoint into the code below later in the quickstart.
24-
* You can use the free pricing tier (`Free F0`) to try the service, and upgrade later to a paid tier for production.
25-
* To use the Analyze feature, you will need a Language resource with the standard (S) pricing tier.
2620

2721
> [!div class="nextstepaction"]
2822
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=JAVA&Pillar=Language&Product=Sentiment-analysis&Page=quickstart&Section=Prerequisites" target="_target">I ran into an issue</a>
2923
3024

3125
## Setting up
3226

27+
[!INCLUDE [Create an Azure resource](../../../includes/create-resource.md)]
28+
29+
[!INCLUDE [Create environment variables](../../../includes/environment-variables.md)]
30+
3331
### Add the client library
3432

3533
Create a Maven project in your preferred IDE or development environment. Then add the following dependency to your project's *pom.xml* file. You can find the implementation syntax [for other build tools](https://mvnrepository.com/artifact/com.azure/azure-ai-textanalytics/5.2.0) online.
@@ -50,9 +48,7 @@ Create a Maven project in your preferred IDE or development environment. Then ad
5048

5149
## Code example
5250

53-
Create a Java file named `Example.java`. Open the file and copy the below code. Remember to replace the `key` variable with the key for your resource, and replace the `endpoint` variable with the endpoint for your resource.
54-
55-
[!INCLUDE [find the key and endpoint for a resource](../../../includes/find-azure-resource-info.md)]
51+
Create a Java file named `Example.java`. Open the file and copy the below code.
5652

5753
```java
5854
import com.azure.core.credential.AzureKeyCredential;
@@ -61,12 +57,13 @@ import com.azure.ai.textanalytics.TextAnalyticsClientBuilder;
6157
import com.azure.ai.textanalytics.TextAnalyticsClient;
6258

6359
public class Example {
64-
65-
private static String KEY = "replace-with-your-key-here";
66-
private static String ENDPOINT = "replace-with-your-endpoint-here";
60+
61+
// This example requires environment variables named "LANGUAGE_KEY" and "LANGUAGE_ENDPOINT"
62+
private static String languageKey = System.getenv("LANGUAGE_KEY");
63+
private static String languageEndpoint = System.getenv("LANGUAGE_ENDPOINT");
6764

6865
public static void main(String[] args) {
69-
TextAnalyticsClient client = authenticateClient(KEY, ENDPOINT);
66+
TextAnalyticsClient client = authenticateClient(languageKey, languageEndpoint);
7067
sentimentAnalysisWithOpinionMiningExample(client);
7168
}
7269
// Method to authenticate the client object with your key and endpoint.
@@ -130,6 +127,8 @@ Recognized document sentiment: mixed, positive score: 0.470000, neutral score: 0
130127

131128
[!INCLUDE [clean up resources](../../../includes/clean-up-resources.md)]
132129

130+
[!INCLUDE [clean up environment variables](../../../includes/clean-up-variables.md)]
131+
133132
> [!div class="nextstepaction"]
134133
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=REST API&Pillar=Language&Product=Entity-linking&Page=quickstart&Section=Clean-up-resources" target="_target">I ran into an issue</a>
135134

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/nodejs-sdk.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ manager: nitinme
44
ms.service: cognitive-services
55
ms.subservice: language-service
66
ms.topic: include
7-
ms.date: 08/15/2022
7+
ms.date: 10/21/2022
88
ms.author: aahi
99
ms.custom: devx-track-js, ignite-fall-2021
1010
---
@@ -13,22 +13,20 @@ ms.custom: devx-track-js, ignite-fall-2021
1313

1414
Use this quickstart to create a sentiment analysis application with the client library for Node.js. In the following example, you will create a JavaScript application that can identify the sentiment(s) expressed in a text sample, and perform aspect-based sentiment analysis.
1515

16-
[!INCLUDE [Use Language Studio](../../../includes/use-language-studio.md)]
17-
1816
## Prerequisites
1917

2018
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
2119
* [Node.js](https://nodejs.org/) v14 LTS or later
22-
* Once you have your Azure subscription, <a href="https://portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics" title="Create a Language resource" target="_blank">create a Language resource </a> in the Azure portal to get your key and endpoint. After it deploys, click **Go to resource**.
23-
* You will need the key and endpoint from the resource you create to connect your application to the API. You'll paste your key and endpoint into the code below later in the quickstart.
24-
* You can use the free pricing tier (`Free F0`) to try the service, and upgrade later to a paid tier for production.
25-
* To use the Analyze feature, you will need a Language resource with the standard (S) pricing tier.
2620

2721
> [!div class="nextstepaction"]
2822
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=JAVASCRIPT&Pillar=Language&Product=Sentiment-analysis&Page=quickstart&Section=Prerequisites" target="_target">I ran into an issue</a>
2923
3024
## Setting up
3125

26+
[!INCLUDE [Create an Azure resource](../../../includes/create-resource.md)]
27+
28+
[!INCLUDE [Create environment variables](../../../includes/environment-variables.md)]
29+
3230
### Create a new Node.js application
3331

3432
In a console window (such as cmd, PowerShell, or Bash), create a new directory for your app, and navigate to it.
@@ -60,16 +58,17 @@ npm install @azure/[email protected]
6058

6159
Open the file and copy the below code. Remember to replace the `key` variable with the key for your resource, and replace the `endpoint` variable with the endpoint for your resource.
6260

63-
[!INCLUDE [find the key and endpoint for a resource](../../../includes/find-azure-resource-info.md)]
64-
6561
```javascript
6662
"use strict";
6763

6864
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
69-
const key = '<paste-your-key-here>';
70-
const endpoint = '<paste-your-endpoint-here>';
65+
66+
// This example requires environment variables named "LANGUAGE_KEY" and "LANGUAGE_ENDPOINT"
67+
const languageKey = process.env.LANGUAGE_KEY;
68+
const languageEndpoint = process.env.LANGUAGE_ENDPOINT;
69+
7170
// Authenticate the client with your key and endpoint.
72-
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
71+
const textAnalyticsClient = new TextAnalyticsClient(LanguageEndpoint, new AzureKeyCredential(languageKey));
7372

7473
// Example method for detecting sentiment and opinions in text.
7574
async function sentimentAnalysisWithOpinionMining(client){
@@ -153,6 +152,8 @@ sentimentAnalysisWithOpinionMining(textAnalyticsClient);
153152

154153
[!INCLUDE [clean up resources](../../../includes/clean-up-resources.md)]
155154

155+
[!INCLUDE [clean up environment variables](../../../includes/clean-up-variables.md)]
156+
156157
> [!div class="nextstepaction"]
157158
> <a href="https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=REST API&Pillar=Language&Product=Entity-linking&Page=quickstart&Section=Clean-up-resources" target="_target">I ran into an issue</a>
158159

0 commit comments

Comments
 (0)