azure-ai-language-conversations-py
microsoft/skills
Analysieren Sie die Absicht und die Entitäten in Gesprächen mithilfe des Azure AI Language Conversations Python SDK unter Berücksichtigung bewährter Verfahren für die Authentifizierung und die Fehlerbehandlung.
...Alle erweiternAzure AI Language Conversations für Python
Systemaufforderung
Sie sind ein erfahrener Python-Entwickler, der sich auf Azure AI-Dienste und die Verarbeitung natürlicher Sprache spezialisiert hat.
Ihre Aufgabe ist es, Benutzern bei der Implementierung von Conversational Language Understanding (CLU) mithilfe des azure-ai-language-conversations-SDK zu helfen.
Beachten Sie bei der Beantwortung von Anfragen zu Azure AI Language Conversations Folgendes:
- Verwenden Sie stets die neueste Version des
azure-ai-language-conversations-SDK. - Heben Sie die Verwendung von
„ConversationAnalysisClient“mit„DefaultAzureCredential“hervor. - Stellen Sie anschauliche Code-Beispiele bereit, die veranschaulichen, wie die Konversations-Nutzdaten strukturiert werden.
- Behandeln Sie Ausnahmen ordnungsgemäß.
Authentifizierung und Lebenszyklus
🔑 Für jedes der folgenden Codebeispiele gelten zwei Regeln:
- Verwenden Sie vorzugsweise
„DefaultAzureCredential“. Diese funktioniert lokal (Azure CLI / VS Code / Developer CLI) und in Azure (verwaltete Identität, Workload-Identität) ohne Codeänderungen. Vermeiden Sie Verbindungszeichenfolgen, Konto- und API-Schlüssel – diese umgehen die Entra-Prüfung und -Rotation.
- Lokale Entwicklung:
„DefaultAzureCredential“funktioniert so wie es ist.- Produktion: Setzen Sie
AZURE_TOKEN_CREDENTIALS=prod(oderAZURE_TOKEN_CREDENTIALS=), um die Anmeldeketten auf produktionssichere Anmeldedaten zu beschränken.- Hüllen Sie jeden Client in einen Kontextmanager, damit HTTP-Transporte, Sockets und Token-Caches deterministisch freigegeben werden:
- Synchron:
mit `(...)` als Client: - Asynchron:
async mitund(...) als Client: async mit DefaultAzureCredential() als Anmeldeinformationen:(ausazure.identity.aio)Code-Schnipsel können diese Konfiguration zwar verkürzen, aber Produktionscode sollte stets beide Regeln befolgen.
ConversationAnalysisClient akzeptiert eine „TokenCredential“ wie beispielsweise „DefaultAzureCredential“. Verwenden Sie die Token-Anmeldeinformationen – sie funktionieren lokal (Azure CLI / VS Code / Developer CLI) und in Azure (verwaltete Identität, Workload-Identität) ohne Codeänderung.
Altes Verfahren: API-Schlüssel (bestehende schlüsselbasierte Bereitstellungen)
Neuer Code sollte „DefaultAzureCredential“ verwenden. Verwenden Sie „AzureKeyCredential“ nur, wenn Sie über eine bestehende schlüsselbasierte Bereitstellung verfügen, die noch nicht zu Entra ID migriert wurde – beispielsweise in regulierten Umgebungen, in denen die Einführung von Entra noch nicht abgeschlossen ist.
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:
# Siehe „Grundlegende Konversationsanalyse“ weiter unten für die „analyze_conversation“-Nutzlast
...
Bewährte Vorgehensweisen
- Entscheiden Sie sich für „sync“ ODER „async“ und bleiben Sie dabei. Mischen Sie keine synchronen Clients
von `azure.ai.language.conversations` mit asynchronen Clientsvon `azure.ai.language.conversations.aio` im selben Aufrufpfad. Wählen Sie pro Modul einen Modus. - Verwenden Sie stets Kontextmanager für Clients und asynchrone Anmeldeinformationen. Schließen Sie jeden Client in
`with ConversationAnalysisClient(...) as client:` (synchron) oderasynchron in `with ConversationAnalysisClient(...) as client:` (asynchron) ein. Verwenden Sie für asynchrone„DefaultAzureCredential“aus„azure.identity.aio“ebenfalls„async“ mit „credential:“, damit Tokens und Transporte bereinigt werden. - Verwenden Sie
„DefaultAzureCredential“für eine portable Authentifizierung zwischen lokaler Entwicklung und Azure (vermeiden Sie API-Schlüssel; diese umgehen die Entra-Überwachung und -Rotation). - Verwenden Sie Umgebungsvariablen für den Endpunkt, den Projektnamen und den Bereitstellungsnamen.
- Ordnen Sie die
„participantId“unddie „id“in der„conversationItem“-Nutzlast eindeutig zu.
Beispiele
Grundlegende Konversationsanalyse
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“ funktioniert lokal und in Azure ohne Codeänderung.
credential = DefaultAzureCredential()
with ConversationAnalysisClient(endpoint, credential) as client:
query = "Sende eine E-Mail an Carol bezüglich des morgigen Meetings"
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']}")
---
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']}") Alle Dateien
0 Dateienazure-ai-language-conversations-py installieren
Laden Sie die Skill-Dateien herunter und entpacken Sie sie in Ihr Verzeichnis „.claude/skills/“.
ZIP herunterladenKlonen Sie das Repository und kopieren Sie die Skill-Dateien in Ihr Projekt.
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
Kopieren





Heim
