azure-ai-language-conversations-py
microsoft/skills
Azure AI Language Conversations Python SDK を使用して、会話の意図やエンティティを分析し、認証やエラー処理に関するベストプラクティスを適用します。
...すべて拡張しますPython 向け Azure AI Language Conversations
システムプロンプト
あなたは、Azure AI サービスと自然言語処理を専門とする Python 開発のエキスパートです。
あなたの役割は、ユーザーがazure-ai-language-conversationsSDK を使用して会話型言語理解 (CLU) を実装できるよう支援することです。
Azure AI Language Conversations に関するリクエストに回答する際は、以下の点に注意してください:
- 常に
azure-ai-language-conversationsSDK の最新バージョンを使用してください。 DefaultAzureCredentialを使用したConversationAnalysisClientの利用を強調してください。- 会話ペイロードの構成方法を示す、わかりやすいコード例を提供してください。
- 例外を適切に処理してください。
認証とライフサイクル
🔑 以下のすべてのコードサンプルには、次の 2 つのルールが適用されます:
DefaultAzureCredentialを優先してください。これにより、コードの変更なしに、ローカル環境(Azure CLI / VS Code / Developer CLI)およびAzure環境(マネージドID、ワークロードID)の両方で動作します。接続文字列やアカウント/APIキーの使用は避けてください。これらはEntraの監査およびローテーションの対象外となります。
- ローカル開発:
DefaultAzureCredentialはそのまま使用できます。- 本番環境:
AZURE_TOKEN_CREDENTIALS=prod(またはAZURE_TOKEN_CREDENTIALS=)を設定し、資格情報チェーンを本番環境に適した資格情報に制限してください。- すべてのクライアントをコンテキストマネージャーでラップし、HTTPトランスポート、ソケット、トークンキャッシュが確定的に解放されるようにします:
- 同期:
(...) as client: - 非同期:
`async with` および(...) as client: `async with DefaultAzureCredential() as credential:` (azure.identity.aioから)スニペットではこの設定を省略する場合もありますが、本番環境のコードでは常に両方のルールに従う必要があります。
ConversationAnalysisClient は、DefaultAzureCredential などのTokenCredentialを受け付けます。トークン資格情報を使用してください。コードを変更することなく、ローカル(Azure CLI / VS Code / Developer CLI)および Azure 内(マネージド ID、ワークロード ID)で動作します。
レガシー: API キー(既存のキーベースのデプロイメント)
新しいコードではDefaultAzureCredential を使用してください。AzureKeyCredentialを使用するのは、Entra ID へまだ移行されていない既存のキーベースのデプロイメントがある場合のみです。たとえば、Entra の展開がまだ完了していない規制対象環境などが該当します。
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.language.conversations import ConversationAnalysisClient
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
key = os.environ["AZURE_CONVERSATIONS_KEY"]
with ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) as client:
# analyze_conversation ペイロードについては、以下の「基本的な会話分析」を参照してください
...
ベストプラクティス
- 同期(sync)か非同期(async)のいずれかを選択し、一貫性を保ってください。同じ呼び出しパス内で、
azure.ai.language.conversationsの同期クライアントとazure.ai.language.conversations.aioの非同期クライアントを混在させないでください。モジュールごとに 1 つのモードを選択してください。 - クライアントおよび非同期の認証情報には、常にコンテキストマネージャーを使用してください。すべてのクライアント
を、ConversationAnalysisClient(...) as client:(同期)またはasync with ConversationAnalysisClient(...) as client:(非同期)でラップしてください。 非同期の場合、azure.identity.aioのDefaultAzureCredentialを使用する際は、credential: とともに非同期モードも使用し、トークンとトランスポートがクリーンアップされるようにしてください。 - ローカル開発環境と Azure 間でポータブルな認証を行うには、
`DefaultAzureCredential`を使用してください(API キーは使用しないでください。API キーは Entra の監査およびローテーションをバイパスしてしまいます)。 - エンドポイント、プロジェクト名、デプロイ名には環境変数を使用してください。
conversationItemペイロード内のparticipantIdとidを明確にマッピングしてください。
例
基本的な会話分析
import os
from azure.identity import DefaultAzureCredential
from azure.ai.language.conversations import ConversationAnalysisClient
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
project_name = os.environ["AZURE_CONVERSATIONS_PROJECT"]
deployment_name = os.environ["AZURE_CONVERSATIONS_DEPLOYMENT"]
# DefaultAzureCredential を使用すれば、コードを変更することなく、ローカルおよび Azure 環境で動作します。
credential = DefaultAzureCredential()
with ConversationAnalysisClient(endpoint, credential) as client:
query = "明日の会議について、キャロルにメールを送ってください"
result = client.analyze_conversation(
task={
"kind": "Conversation",
"analysisInput": {
"conversationItem": {
"participantId": "1",
"id": "1",
"modality": "text",
"language": "en",
"text": query
},
"isLoggingEnabled": False
},
"parameters": {
"projectName": project_name,
"deploymentName": deployment_name,
"verbose": True
}
}
)
print(f"トップインテント: {result['result']['prediction']['topIntent']}")
---
name: azure-ai-language-conversations-py
description: Analyze conversation intent and entities using the Azure AI Language Conversations Python SDK with best practices for authentication and error handling.
license: MIT
---
# Azure AI Language Conversations for Python
## System Prompt
You are an expert Python developer specializing in Azure AI Services and Natural Language Processing.
Your task is to help users implement Conversational Language Understanding (CLU) using the `azure-ai-language-conversations` SDK.
When responding to requests about Azure AI Language Conversations:
1. Always use the latest version of the `azure-ai-language-conversations` SDK.
2. Emphasize the use of `ConversationAnalysisClient` with `DefaultAzureCredential`.
3. Provide clear code examples demonstrating how to structure the conversation payload.
4. Handle exceptions properly.
## Authentication & Lifecycle
> **🔑 Two rules apply to every code sample below:**
>
> 1. **Prefer `DefaultAzureCredential`.** It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
> - Local dev: `DefaultAzureCredential` works as-is.
> - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials.
> 2. **Wrap every client in a context manager** so HTTP transports, sockets, and token caches are released deterministically:
> - Sync: `with <Client>(...) as client:`
> - Async: `async with <Client>(...) as client:` **and** `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`)
>
> Snippets may abbreviate this setup, but production code should always follow both rules.
`ConversationAnalysisClient` accepts a `TokenCredential` such as `DefaultAzureCredential`. Use the token credential — it works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change.
### Legacy: API Key (existing keyed deployments)
New code should use `DefaultAzureCredential`. Use `AzureKeyCredential` only if you have an existing keyed deployment that hasn't been migrated to Entra ID yet — for example, regulated environments still completing their Entra rollout.
```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.language.conversations import ConversationAnalysisClient
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
key = os.environ["AZURE_CONVERSATIONS_KEY"]
with ConversationAnalysisClient(endpoint, AzureKeyCredential(key)) as client:
# See "Basic Conversation Analysis" below for the analyze_conversation payload
...
```
## Best Practices
- **Pick sync OR async and stay consistent.** Do not mix `azure.ai.language.conversations` sync clients with `azure.ai.language.conversations.aio` async clients in the same call path. Choose one mode per module.
- **Always use context managers for clients and async credentials.** Wrap every client in `with ConversationAnalysisClient(...) as client:` (sync) or `async with ConversationAnalysisClient(...) as client:` (async). For async `DefaultAzureCredential` from `azure.identity.aio`, also use `async with credential:` so tokens and transports are cleaned up.
- **Use `DefaultAzureCredential`** for portable auth across local dev and Azure (avoid API keys; they bypass Entra audit and rotation).
- Use environment variables for the endpoint, project name, and deployment name.
- Clearly map the `participantId` and `id` in the `conversationItem` payload.
## Examples
### Basic Conversation Analysis
```python
import os
from azure.identity import DefaultAzureCredential
from azure.ai.language.conversations import ConversationAnalysisClient
endpoint = os.environ["AZURE_CONVERSATIONS_ENDPOINT"]
project_name = os.environ["AZURE_CONVERSATIONS_PROJECT"]
deployment_name = os.environ["AZURE_CONVERSATIONS_DEPLOYMENT"]
# DefaultAzureCredential works locally and in Azure with no code change.
credential = DefaultAzureCredential()
with ConversationAnalysisClient(endpoint, credential) as client:
query = "Send an email to Carol about the tomorrow's meeting"
result = client.analyze_conversation(
task={
"kind": "Conversation",
"analysisInput": {
"conversationItem": {
"participantId": "1",
"id": "1",
"modality": "text",
"language": "en",
"text": query
},
"isLoggingEnabled": False
},
"parameters": {
"projectName": project_name,
"deploymentName": deployment_name,
"verbose": True
}
}
)
print(f"Top intent: {result['result']['prediction']['topIntent']}") すべてのファイル
0件のファイルazure-ai-language-conversations-pyをインストール
スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。
ZIPをダウンロードリポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/azure-ai-language-conversations-py # Copy SKILL.md to your .claude/skills/ directory
コピー





家
