Skip to content

OpenAI With Evaluation Of Intents

Category: Cognitive

Description: This extension module allows the evaluation of the cognitive module's intents for decision-making within the flow designed in Lynn, complementing OpenAI's responses.

Functionality: The extension module can be applied to various functions to complement the actions or intents defined in the behavior of the OpenAI chat. Its main action is to evaluate and enrich OpenAI's responses. Some possibilities include querying a web service after OpenAI's conversational response, integrating with other systems to obtain additional data, and adjusting the interaction based on detected intents.

Prerequisites

  1. Create an OpenAI account:

    • If you don’t have an account, go to the OpenAI website and sign up. If you already have an account, just log in.
  2. Access the Dashboard:

    • Once logged in, go to your OpenAI dashboard.
    • In the dashboard, look for the "API" or "API Keys" section. This may vary depending on user interface updates, but it’s generally found in the main menu or in a submenu related to account management or settings.
  3. Generate a new API Key:

    • Click the button to generate a new API Key. It may be labeled "Create API Key," "Generate New Key," "New API Key," or something similar.
    • Follow the on-screen instructions to name and generate the key. You may be asked to verify your account or accept certain terms of use.

Note: Once generated, the API Key will be displayed on the screen. Copy it and store it in a safe place, as this key is necessary to authenticate your requests to the OpenAI API. Keep in mind that, for security reasons, you might not be able to see the full key again after leaving the generation screen. If you lose it, you will need to generate a new one.

  1. Have a cognitive engine

Implementation

Random dialog type action to continue the conversation: A list-type field that displays dialogs created in the tenant. These will be used to display user-defined random questions.

Expression that defines the training corpus: A field where an expression defining the behavior for the OpenAI chat must be entered. It accepts the Human/AI format.

Note 📑: It is important to frame simpler corpora in backticks (`).

Model: A string-type expression where the model to be used for text validation must be indicated. There are models with different levels of capabilities:

MODEL DESCRIPTION
gpt-3.5-turbo-instruct Capabilities similar to GPT-3 era models. Compatible with legacy completion endpoints, but not with chat completions.
text-embedding-ada-002 The most capable second-generation embedding model, replacing 16 first-generation models.
text-moderation-007 The most capable moderation model across all categories.

Note 📑: Check the available models HERE.

Temperature: A float-type field that controls the creativity of the model's responses. A high value (like 0.9) generates more creative responses, while a low value (like 0) produces more precise and defined responses.

Top_P: Controls the diversity of the model's responses. A high value (close to 1) allows greater diversity by considering more possible options. A low value (close to 0) limits the options to the most probable ones, resulting in more coherent and less creative responses.

Max_Tokens: Determines the maximum length of the model's response, measured in tokens. A high value allows longer and more detailed responses, while a low value restricts the length to shorter and more concise responses.

If the maximum number of failed attempts is reached, the action flow will be interrupted and the error description will be passed to the selected intent with the name 'OpenAi_Error': A dropdown list where the name of the intent for error handling must be selected.

Intent monitoring threshold: A list-type field that allows selecting the percentage of coincidence at which the intent to be monitored defined in the Intent Monitoring List field will be executed.

Requires confirmation: A field that allows indicating whether client confirmation is required. Its values can be:

  • Yes: Indicates when the menu should be displayed and client confirmation of the intent in the intent monitoring list is required.
  • No: If automatic execution of the intent defined in the intent monitoring list is required.

Intent Monitoring List: Fields where the key corresponding to the value to be assigned to the intent must be indicated.

Implementation Example

Field Value
Name: OpenAi_EvaluationOfIntents
Random dialog type action to continue the conversation: 'What is your query?'
Expression that defines the training corpus:

Question: How does our company handle sensitive customer data?

Answer: Our company strictly complies with all privacy and data protection regulations. We use secure systems for storing and handling confidential customer information.

Question: What is our approach to dealing with customers in default?

Answer: Our approach is based on empathy and understanding of each customer’s circumstances. We seek to establish open and transparent communication to find solutions that fit their possibilities.

Question: How do we ensure ethical compliance in our collection practices?

Answer: Our company adheres to strict ethical standards in all our interactions with customers. We do not tolerate abusive or coercive collection practices, and we are committed to treating all customers with respect and dignity.

Note: The expression must be inserted between backticks (`)

MODEL: 'gpt-3.5-turbo-instruct'
TEMPERATURE: 0.8
TOP_P : 0
MAX_TOKENS: 150
Authorization: AXX2XkXmXXXXX
If the maximum number of failed attempts is reached, the action flow will be interrupted and the error description will be passed to the selected intent with the name: 'OpenAi_Error': Error_Handler
Intent monitoring threshold: 95
Requires confirmation: No
Intent Monitoring List.: Key ForwardToExecutive / Value 'Can I transfer you to an executive for the request of your designer checkbook, do you agree?'

Example 1

In this case, the extension module is used to interact only with OpenAI to deliver a response to the user.

Input:

Client: How do we ensure ethical compliance in our collection practices?

Output:

OpenAI <--

Our company adheres to strict ethical standards in all our interactions with customers. We do not tolerate abusive or coercive collection practices, and we are committed to treating all customers with respect and dignity

Example 2

In the following case, this extension module is used as a complement to OpenAI's response to the intent “Checkbook,” offering transfer to an executive with the Dialog Flow cognitive engine.

To achieve this process, in the Requires confirmation field, we must select the "Yes" option and complete the required fields in section 2 of the extension module. For this example, we will configure an entity that will contain the confirmation response and the value of Confirmation Value.

Input:

Client: I want to know if the checkbook is charged

Output:

Lynn/OpenAI: Acme Bank does not charge you for the checkbook; but there are charges for designer checkbooks.

Lynn/Extension Module: Can I transfer you to an executive for the request of your designer checkbook, do you agree? Yes/No

Input:

Client: Yes

Output:

Lynn: Transferring to an executive...