使用 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();