Skip to content

Chat Open AI

Category: Cognitive

Description: This extension module allows advanced integration with OpenAI's APIs, adding the ability to incorporate conversational features based on a base corpus.

Functionality: It is oriented towards managing chats based on OpenAI, where messages are processed emulating the behavior of a cognitive engine, but without the need to define an IEC model for each intent. In its most basic form, it allows a free chat based on the context of a corpus or previous context.

Prerequisites

  1. Create an account on OpenAI:

    • If you do not have an account, go to the OpenAI website and sign up. If you already have an account, simply 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 is generally found in the main menu or a sub-menu 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 as "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 save it in a safe place, as this key is necessary to authenticate your requests to the OpenAI API. Be aware that, for security reasons, you may not be able to see the complete key again after leaving the generation screen. If you lose it, you will need to generate a new one.

Implementation

Expression that defines the training corpus: Field where you must enter an expression that defines the behavior for the OpenAI chat, it supports the Human/AI format.

Note ๐Ÿ“‘: It is important that simpler corpora are framed in backticks (`).

Chat Input: Mandatory field that stores an entity that defines the input to be analyzed. For most chat implementation cases, its value should be set to the entity: CURRENT_EVALUATION. Remember that this entity will be empty for sessions that do not depend on a client message (Example: opening a web chat does not require an initial message like other channels such as WhatsApp).

Chat Entity: Mandatory field that stores a string-type entity that supports the corpus aggregation transaction, define an entity for this action to work.

Model: String-type expression where the model to be used for text validation should 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 and not with chat completions.
text-embedding-ada-002 The most capable second-generation integration model, replacing 16 first-generation models.
text-moderation-007 The most capable moderation model across all categories.

Note ๐Ÿ“‘: Check available models HERE.

Temperature: 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 for 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 response generated by the model, measured in tokens. A high value allows for longer and more detailed responses, while a low value restricts the length to shorter and more concise responses.

Stop: Defines a text string that will stop the response process of the OpenAI engine.

Authorization: To use OpenAI APIs, you need an API Key. This key acts as an identifier and authenticator for your requests. You can obtain your API Key in the OpenAI dashboard and use it in your code to access the service's functions.

Entity where the evaluation result will be deposited: Dropdown list field that allows you to select the entity where the OpenAI evaluation result will be saved.

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': Dropdown list where the name of the intent for error handling must be selected.

Implementation Example

Field Value
Name: PruebaChatOpenAi
Expression that defines the training corpus: -- Example expression:

Human: Hello, good morning.

AI: Hello, how can I help you?

Human: I want to know if there is a fee for the checkbook.

AI: Acme Bank does not charge for the checkbook; however, there are charges for designed checkbooks.

Human: I want my checkbook.

AI: When you open your account, we provide a checkbook and a booklet, which contains a form that you need to present to request your next booklet. If you do not have the form, you can request it at the nearest branch.

Human: What should I do if I need cash and don't have checks or cards with me?

AI: Go to the service desk at any Acme Bank branch and request emergency cash. You can request it as withdrawals from your Checking Account or Credit Line, or as an advance from your Credit Card.

Note: The expression should be enclosed in backticks (`)

CHAT INPUT: CURRENT_EVALUATION
CHAT ENTITY: entityTest
MODEL: 'gpt-3.5-turbo-instruct'
TEMPERATURE: 0.8
TOP_Pย : 0
MAX_TOKENS: 150
STOP: '[" Human:", " AI:"]'
Authorization: AXX2XkXmXXXXX
Entity where the evaluation result will be deposited: entityTest
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

Input:

Client writes: what about the checkbook?

CURRENT_EVALUATION <-- โ€˜what about the checkbook?โ€™

Output:

OPENAI <--

The checkbook is a set of pre-printed checks that are provided when opening a checking account. These checks contain the basic account details, such as the account holder's name, account number, and bank name. The checkbook is a useful tool for making payments and transferring funds. Acme Bank does not charge for the checkbook, but there are charges for designed checkbooks.

OPENAI_INPUT <-- Corpus + new processed Human/AI.