オプション
家 Skill データサイエンスと機械学習 azure-ai-language-conversations-py

azure-ai-language-conversations-py

microsoft/skills microsoft/skills

Azure AI Language Conversations Python SDK を使用して、会話の意図やエンティティを分析し、認証やエラー処理に関するベストプラクティスを適用します。

...すべて拡張します
3
更新された時間 2026年9月18日

Python 向け Azure AI Language Conversations

システムプロンプト

あなたは、Azure AI サービスと自然言語処理を専門とする Python 開発のエキスパートです。 あなたの役割は、ユーザーがazure-ai-language-conversationsSDK を使用して会話型言語理解 (CLU) を実装できるよう支援することです。

Azure AI Language Conversations に関するリクエストに回答する際は、以下の点に注意してください:

  1. 常にazure-ai-language-conversationsSDK の最新バージョンを使用してください。
  2. DefaultAzureCredential を使用したConversationAnalysisClientの利用を強調してください。
  3. 会話ペイロードの構成方法を示す、わかりやすいコード例を提供してください。
  4. 例外を適切に処理してください。

認証とライフサイクル

🔑 以下のすべてのコードサンプルには、次の 2 つのルールが適用されます:

  1. DefaultAzureCredentialを優先してください。これにより、コードの変更なしに、ローカル環境(Azure CLI / VS Code / Developer CLI)およびAzure環境(マネージドID、ワークロードID)の両方で動作します。接続文字列やアカウント/APIキーの使用は避けてください。これらはEntraの監査およびローテーションの対象外となります。
    • ローカル開発:DefaultAzureCredentialはそのまま使用できます。
    • 本番環境:AZURE_TOKEN_CREDENTIALS=prod(またはAZURE_TOKEN_CREDENTIALS= )を設定し、資格情報チェーンを本番環境に適した資格情報に制限してください。
  2. すべてのクライアントをコンテキストマネージャーでラップし、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.aioDefaultAzureCredentialを使用する際は、credential: とともに非同期モードも使用し、トークンとトランスポートがクリーンアップされるようにしてください。
  • ローカル開発環境と Azure 間でポータブルな認証を行うには、 `DefaultAzureCredential`を使用してください(API キーは使用しないでください。API キーは Entra の監査およびローテーションをバイパスしてしまいます)。
  • エンドポイント、プロジェクト名、デプロイ名には環境変数を使用してください。
  • conversationItemペイロード内のparticipantIdidを明確にマッピングしてください。

基本的な会話分析

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']}")
GitHubで見る
---
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

コピー コピー
クイックセットアップ: スキルフォルダを .claude/skills/ にコピーしてください。 Claude が自動的にそのスキルを検出して使用します。
リポジトリ microsoft/skills

関連スキル

web-search
更新された時間 2026年6月29日
webapp-testing
更新された時間 2026年6月29日
lark-base
更新された時間 2026年7月5日
agentmail
更新された時間 2026年6月29日
OR