AI service

AI Service

AI Service is an utility found in Aura Bot common library in charge of managing calls to external AI services.

Introduction

AI ​​Service allows you to manage calls to external AI services through generative APIs. The service is responsible for abstracting the details of the API calls and providing a simple interface for recognizing intents using different recognizers.

Creating an instance of the service

To create an instance of the service, you need to provide a AiRecognizerServiceConfiguration object with the following parameters:

Parameter Type Description Mandatory
AURA_GATEWAY_API_ENDPOINT string URL of the Aura Gateway API yes
AURA_AUTHORIZATION_HEADER string Authorization header yes
AURA_GATEWAY_API_ISSUER_URL string Issuer URL for token info yes

Example of use:

import { AuraBotCommon } from '@telefonica/aura-bot-utilities';

const aiService = new AuraBotCommon.AiRecognizerService({
    AURA_AUTHORIZATION_HEADER: process.env.AURA_AUTHORIZATION_HEADER!,
    AURA_GATEWAY_API_ENDPOINT: process.env.AURA_GATEWAY_API_ENDPOINT!,
    AURA_GATEWAY_API_ISSUER_URL: process.env.AURA_GATEWAY_API_ISSUER_URL!
});

Recognizing intents. The recognize method

The recognize method allows you to recognize intents from a TurnContext using a specific intent configuration. The method takes the following parameters:

Parameter Type Description Mandatory
context TurnContext Turn context yes
intentConfiguration AuraConfigurationApiClient.AtriaIntentConfiguration Intent configuration yes

Example of use:

const intentConfiguration = AiRecognizerService.getConfigurationByRecognizer(
    context, AiRecognizerService.TRIAGE_RECOGNIZER
);

const intent = await aiService.recognize(context, intentConfiguration);

This method uses the generative API to send the message and receive the response. It also manages the session ID by storing it in the TurnContext for future requests.

Recognizing intents using triage. The recognizeUsingTriage method

The recognizeUsingTriage method allows you to recognize intents from a TurnContext using the triage recognizer. The method takes the following parameter:

Parameter Type Description Mandatory
context TurnContext Turn context yes

Example of use:

const intent = await aiService.recognizeUsingTriage(context);

Getting configurations

The AI Service provides two static methods to retrieve intent configurations from the TurnContext:

  • getConfigurationByRecognizer: Retrieves the configuration for a specific recognizer by its name.
  • getConfigurationByDialog: Retrieves the configuration for a specific dialog by its intent name.