azure-sdk-for-js/sdk/cognitivelanguage/ai-language-conversations/README.md

5.9 KiB

Azure ConversationAnalysis client library for JavaScript

This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure ConversationAnalysis client.

The language service conversations API is a suite of natural language processing (NLP) skills that can be used to analyze structured conversations (textual or spoken). The synchronous API in this suite accepts a request and mediates among multiple language projects, such as LUIS Generally Available, Question Answering, Conversational Language Understanding, and then calls the best candidate service to handle the request. At last, it returns a response with the candidate service's response as a payload.

In some cases, this API needs to forward requests and responses between the caller and an upstream service. The asynchronous APIs in this suite enable tasks like Conversation Summarization and Conversational PII detection.

Key links:

Getting started

Currently supported environments

See our support policy for more details.

Prerequisites

If you use the Azure CLI, replace <your-resource-group-name> and <your-resource-name> with your own unique names:

az cognitiveservices account create --kind ConversationalLanguageUnderstanding --resource-group <your-resource-group-name> --name <your-resource-name> --sku <your-sku-name> --location <your-location>

Install the @azure/ai-language-conversations package

Install the Azure ConversationAnalysis client library for JavaScript with npm:

npm install @azure/ai-language-conversations

Create and authenticate a ConversationAnalysisClient

To create a client object to access the Language API, you will need the endpoint of your Language resource and a credential. The Conversation Analysis client can use an API key credential to authenticate.

You can find the endpoint for your Language resource either in the Azure Portal or by using the Azure CLI snippet below:

az cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query "properties.endpoint"

Using an API Key

Use the Azure Portal to browse to your Language resource and retrieve an API key, or use the Azure CLI snippet below:

Note: Sometimes the API key is referred to as a "subscription key" or "subscription API key."

az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>

Once you have an API key and endpoint, you can use the AzureKeyCredential class to authenticate the client as follows:

const { AzureKeyCredential } = require("@azure/core-auth");
const { ConversationAnalysisClient } = require("@azure/ai-language-conversations");

const client = new ConversationAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));

JavaScript Bundle

To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our bundling documentation.

Key concepts

ConversationAnalysisClient

ConversationAnalysisClient is the primary interface for developers using the Azure ConversationAnalysis client library. Explore the methods on this client object to understand the different features of the Azure ConversationAnalysis service that you can access.

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

const { setLogLevel } = require("@azure/logger");
setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

Impressions