Skip to content

Commit 8f92636

Browse files
committed
cognitive sample
1 parent 1dd71a5 commit 8f92636

File tree

5 files changed

+277
-27
lines changed

5 files changed

+277
-27
lines changed

articles/service-connector/how-to-integrate-cognitive-services.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
2-
title: Integrate Azure AI services multi-service account with Service Connector
3-
description: In this document, learn how to integrate Azure AI services multi-service account into your application with Service Connector
2+
title: Integrate Azure Multi-service Cognitive Services with Service Connector
3+
description: In this document, learn how to integrate Azure Multi-service Cognitive Services into your application with Service Connector
44
author: wchigit
55
ms.author: wchi
66
ms.service: service-connector
77
ms.topic: how-to
88
ms.date: 06/14/2024
99
---
1010

11-
# Integrate Azure AI services multi-service account with Service Connector
11+
# Integrate Azure Multi-service Cognitive Services with Service Connector
1212

13-
This page shows supported authentication methods and clients, and shows sample code you can use to connect Azure AI services multi-service account to other cloud services using Service Connector. You might still be able to connect to Azure AI services multi-service account using other methods. This page also shows default environment variable names and values you get when you create the service connection.
13+
This page shows supported authentication methods and clients, and shows sample code you can use to connect Azure Multi-service Cognitive Services to other cloud services using Service Connector. You might still be able to connect to Azure Multi-service Cognitive Services using other methods. This page also shows default environment variable names and values you get when you create the service connection.
1414

1515
## Supported compute services
1616

17-
Service Connector can be used to connect the following compute services to Azure AI services multi-service account:
17+
Service Connector can be used to connect the following compute services to Azure Multi-service Cognitive Services:
1818

1919
- Azure App Service
2020
- Azure Functions
@@ -23,7 +23,7 @@ Service Connector can be used to connect the following compute services to Azure
2323

2424
## Supported authentication types and client types
2525

26-
The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to Azure AI services multi-service account using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported.
26+
The table below shows which combinations of authentication methods and clients are supported for connecting your compute service to Azure Multi-service Cognitive Services using Service Connector. A “Yes” indicates that the combination is supported, while a “No” indicates that it is not supported.
2727

2828

2929
| Client type | System-assigned managed identity | User-assigned managed identity | Secret/connection string | Service principal |
@@ -34,11 +34,11 @@ The table below shows which combinations of authentication methods and clients a
3434
| Python | Yes | Yes | Yes | Yes |
3535
| None | Yes | Yes | Yes | Yes |
3636

37-
This table indicates that all combinations of client types and authentication methods in the table are supported. All client types can use any of the authentication methods to connect to Azure AI services multi-service account using Service Connector.
37+
This table indicates that all combinations of client types and authentication methods in the table are supported. All client types can use any of the authentication methods to connect to Azure Multi-service Cognitive Services using Service Connector.
3838

3939
## Default environment variable names or application properties and sample code
4040

41-
Use the connection details below to connect compute services to Azure AI services multi-service account. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article.
41+
Use the connection details below to connect compute services to Azure Multi-service Cognitive Services. For more information about naming conventions, check the [Service Connector internals](concept-service-connector-internals.md#configuration-naming-convention) article.
4242

4343
### System-assigned managed identity
4444

@@ -47,46 +47,45 @@ Use the connection details below to connect compute services to Azure AI service
4747
| AZURE_COGNITIVESERVICES_ENDPOINT | Azure Cognitive Services token provider service | `https://<cognitive-service-name>.cognitiveservices.azure.com/` |
4848

4949
#### Sample code
50-
Refer to the steps and code below to connect to Azure AI services multi-service account using a system-assigned managed identity.
50+
Refer to the steps and code below to connect to Azure Multi-service Cognitive Services using a system-assigned managed identity.
5151
[!INCLUDE [code sample for app config](./includes/code-cognitive-me-id.md)]
5252

5353
### User-assigned managed identity
5454

5555
| Default environment variable name | Description | Sample value |
5656
| --------------------------------- | -------------------------- | ----------------------------------------------- |
5757
| AZURE_COGNITIVESERVICES_ENDPOINT | Azure Cognitive Services token provider service | `https://<cognitive-service-name>.cognitiveservices.azure.com/` |
58-
| AZURE_AISERVICES_CLIENTID | Your client ID | `<client-ID>` |
58+
| AZURE_COGNITIVESERVICES_CLIENTID | Your client ID | `<client-ID>` |
5959

6060
#### Sample code
61-
Refer to the steps and code below to connect to Azure AI services multi-service account using a user-assigned managed identity.
62-
[!INCLUDE [code sample for Azure AI services multi-service account](./includes/code-cognitive-me-id.md)]
61+
Refer to the steps and code below to connect to Azure Multi-service Cognitive Services using a user-assigned managed identity.
62+
[!INCLUDE [code sample for Azure Multi-service Cognitive Services](./includes/code-cognitive-me-id.md)]
6363

6464
### Connection string
6565

6666
> [!div class="mx-tdBreakAll"]
6767
> | Default environment variable name | Description | Sample value |
6868
> | --------------------------------- | ------------| ------------ |
6969
> | AZURE_COGNITIVESERVICES_ENDPOINT | Azure Cognitive Services token provider service | `https://<cognitive-service-name>.cognitiveservices.azure.com/` |
70-
> | AZURE_AISERVICES_KEY | Azure AI services multi-service account API key | `<api-key>` |
70+
> | AZURE_COGNITIVESERVICES_KEY | Azure Multi-service Cognitive Services API key | `<api-key>` |
7171
7272
#### Sample Code
73-
Refer to the steps and code below to connect to Azure AI services multi-service account using a connection string.
74-
[!INCLUDE [code sample for Azure AI services multi-service account](./includes/code-cognitive-secret.md)]
73+
Refer to the steps and code below to connect to Azure Multi-service Cognitive Services using a connection string.
74+
[!INCLUDE [code sample for Azure Multi-service Cognitive Services](./includes/code-cognitive-secret.md)]
7575

7676

7777
### Service principal
7878

7979
| Default environment variable name | Description | Sample value |
8080
| ----------------------------------- | -------------------------- | ---------------------------------------------- |
81-
| AZURE_AISERVICES_OPENAI_BASE | Azure OpenAI endpoint | `https://<cognitive-service-name>.openai.azure.com/` |
82-
| AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT | Azure Cognitive Services token provider service | `https://<cognitive-service-name>.cognitiveservices.azure.com/` |
83-
| AZURE_AISERVICES_CLIENTID | Your client ID | `<client-ID>` |
84-
| AZURE_AISERVICES_CLIENTSECRET | Your client secret | `<client-secret>` |
85-
| AZURE_AISERVICES_TENANTID | Your tenant ID | `<tenant-ID>` |
81+
| AZURE_COGNITIVESERVICES_ENDPOINT | Azure Cognitive Services token provider service | `https://<cognitive-service-name>.cognitiveservices.azure.com/` |
82+
| AZURE_COGNITIVESERVICES_CLIENTID | Your client ID | `<client-ID>` |
83+
| AZURE_COGNITIVESERVICES_CLIENTSECRET | Your client secret | `<client-secret>` |
84+
| AZURE_COGNITIVESERVICES_TENANTID | Your tenant ID | `<tenant-ID>` |
8685

8786
#### Sample code
88-
Refer to the steps and code below to connect to Azure AI services multi-service account using a service principaL.
89-
[!INCLUDE [code sample for Azure AI services multi-service account](./includes/code-cognitive-me-id.md)]
87+
Refer to the steps and code below to connect to Azure Multi-service Cognitive Services using a service principaL.
88+
[!INCLUDE [code sample for Azure Multi-service Cognitive Services](./includes/code-cognitive-me-id.md)]
9089

9190
## Next steps
9291

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
author: wchigit
3+
ms.service: service-connector
4+
ms.topic: include
5+
ms.date: 10/20/2023
6+
ms.author: wchi
7+
---
8+
9+
You can use the Azure client library to access various cognitive APIs that Azure Multi-service Cognitive Services support. We use the language service as an example in this sample. Refer to [Authenticate requests to Azure AI services](https://learn.microsoft.com/en-us/azure/ai-services/authentication#authenticate-with-azure-active-directory) to call the cognitive APIs directly.
10+
11+
### [.NET](#tab/dotnet)
12+
13+
1. Install the following dependencies. We use `Azure.AI.TextAnalytics` as an example.
14+
```bash
15+
dotnet add package Azure.AI.TextAnalytics
16+
dotnet add package Azure.Identity
17+
```
18+
1. Authenticate using Azure Identity library and get the Azure Multi-service Cognitive Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
19+
20+
```csharp
21+
using Azure.AI.TextAnalytics;
22+
using Azure.Identity;
23+
24+
string endpoint = Environment.GetEnvironmentVariable("AZURE_COGNITIVESERVICES_ENDPOINT");
25+
26+
// Uncomment the following lines according to the authentication type.
27+
// system-assigned managed identity
28+
// var credential = new DefaultAzureCredential();
29+
30+
// user-assigned managed identity
31+
// var credential = new DefaultAzureCredential(
32+
// new DefaultAzureCredentialOptions
33+
// {
34+
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_COGNITIVESERVICES_CLIENTID");
35+
// });
36+
37+
// service principal
38+
// var tenantId = Environment.GetEnvironmentVariable("AZURE_COGNITIVESERVICES_TENANTID");
39+
// var clientId = Environment.GetEnvironmentVariable("AZURE_COGNITIVESERVICES_CLIENTID");
40+
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_COGNITIVESERVICES_CLIENTSECRET");
41+
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
42+
43+
TextAnalyticsClient languageServiceClient = new(
44+
new Uri(endpoint),
45+
credential);
46+
```
47+
48+
### [Java](#tab/java)
49+
50+
1. Add the following dependencies in your *pom.xml* file. We use `azure-ai-textanalytics` as an example.
51+
```xml
52+
<dependency>
53+
<groupId>com.azure</groupId>
54+
<artifactId>azure-ai-textanalytics</artifactId>
55+
<version>5.1.12</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.azure</groupId>
59+
<artifactId>azure-identity</artifactId>
60+
<version>1.11.4</version>
61+
</dependency>
62+
```
63+
1. Authenticate using `azure-identity` and get the Azure Multi-service Cognitive Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
64+
65+
```java
66+
// Uncomment the following lines according to the authentication type.
67+
// for system-managed identity
68+
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
69+
70+
// for user-assigned managed identity
71+
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
72+
// .managedIdentityClientId(System.getenv("AZURE_COGNITIVESERVICES_CLIENTID"))
73+
// .build();
74+
75+
// for service principal
76+
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
77+
// .clientId(System.getenv("AZURE_COGNITIVESERVICES_CLIENTID"))
78+
// .clientSecret(System.getenv("AZURE_COGNITIVESERVICES_CLIENTSECRET"))
79+
// .tenantId(System.getenv("AZURE_COGNITIVESERVICES_TENANTID"))
80+
// .build();
81+
82+
String endpoint = System.getenv("AZURE_COGNITIVESERVICES_ENDPOINT");
83+
84+
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
85+
.credential(credential)
86+
.endpoint(endpoint)
87+
.buildClient();
88+
```
89+
90+
### [Python](#tab/python)
91+
92+
1. Install the following dependencies. We use `azure-ai-textanalytics` as an example.
93+
```bash
94+
pip install azure-ai-textanalytics==5.1.0
95+
pip install azure-identity
96+
```
97+
1. Authenticate using `azure-identity` and get the Azure Multi-service Cognitive Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
98+
```python
99+
import os
100+
from azure.ai.textanalytics import TextAnalyticsClient
101+
from azure.identity import ManagedIdentityCredential, ClientSecretCredential
102+
103+
# Uncomment the following lines according to the authentication type.
104+
# system-assigned managed identity
105+
# cred = ManagedIdentityCredential()
106+
107+
# user-assigned managed identity
108+
# managed_identity_client_id = os.getenv('AZURE_COGNITIVESERVICES_CLIENTID')
109+
# cred = ManagedIdentityCredential(client_id=managed_identity_client_id)
110+
111+
# service principal
112+
# tenant_id = os.getenv('AZURE_COGNITIVESERVICES_TENANTID')
113+
# client_id = os.getenv('AZURE_COGNITIVESERVICES_CLIENTID')
114+
# client_secret = os.getenv('AZURE_COGNITIVESERVICES_CLIENTSECRET')
115+
# cred = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
116+
endpoint = os.getenv('AZURE_COGNITIVESERVICES_ENDPOINT')
117+
118+
language_service_client = TextAnalyticsClient(
119+
endpoint=endpoint,
120+
credential=cred)
121+
```
122+
123+
### [NodeJS](#tab/nodejs)
124+
125+
1. Install the following dependencies. We use `ai-text-analytics` as an example.
126+
```bash
127+
npm install @azure/[email protected]
128+
npm install @azure/identity
129+
```
130+
1. Authenticate using `@azure/identity` and get the Azure Multi-service Cognitive Services endpoint from the environment variables added by Service Connector. When using the code below, uncomment the part of the code snippet for the authentication type you want to use.
131+
132+
```javascript
133+
import { DefaultAzureCredential,ClientSecretCredential } from "@azure/identity";
134+
const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
135+
136+
// Uncomment the following lines according to the authentication type.
137+
// for system-assigned managed identity
138+
// const credential = new DefaultAzureCredential();
139+
140+
// for user-assigned managed identity
141+
// const clientId = process.env.AZURE_COGNITIVESERVICES_CLIENTID;
142+
// const credential = new DefaultAzureCredential({
143+
// managedIdentityClientId: clientId
144+
// });
145+
146+
// for service principal
147+
// const tenantId = process.env.AZURE_COGNITIVESERVICES_TENANTID;
148+
// const clientId = process.env.AZURE_COGNITIVESERVICES_CLIENTID;
149+
// const clientSecret = process.env.AZURE_COGNITIVESERVICES_CLIENTSECRET;
150+
// const credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
151+
152+
const endpoint = process.env.AZURE_COGNITIVESERVICES_ENDPOINT;
153+
const languageClient = new TextAnalyticsClient(endpoint, credential);
154+
```
155+
156+
### [Other](#tab/none)
157+
For other languages, you can use the connection information that Service Connector sets to the environment variables to connect to Azure Multi-service Cognitive Services. For environment variable details, see [Integrate Azure Multi-service Cognitive Services with Service Connector](../how-to-integrate-cognitive-services.md).

0 commit comments

Comments
 (0)