使用 Azure 标识库进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
使用 azure-identity 进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
使用 Azure 标识库进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
使用 azure-identity 进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
使用 Azure 标识库进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
using Azure.AI.TextAnalytics;
using Azure.Identity;
string endpoint = Environment.GetEnvironmentVariable("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_AISERVICES_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
TextAnalyticsClient languageServiceClient = new(
new Uri(endpoint),
credential);
使用 azure-identity 进行身份验证,并从服务连接器添加的环境变量中获取 Azure AI 服务终结点。 使用下面的代码时,请对要使用的身份验证类型的代码片段的一部分取消评论。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential credential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_AISERVICES_CLIENTID"))
// .clientSecret(System.getenv("AZURE_AISERVICES_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_AISERVICES_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_AISERVICES_COGNITIVESERVICES_ENDPOINT");
TextAnalyticsClient languageClient = new TextAnalyticsClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();