Using AI nodes
Implementing AI-based automation.
Table of contents:
- Using AI Speech-to-Text group nodes
- Using AI nodes to assist with writing a blog article
- Using AI for ASR and text summarization
- Using AI to analyze the sentiment of a text
- Using AI to Draft Responses to User Emails
Using AI Speech-to-Text group nodes
As an example of using nodes of the AI Speech-To-Text group, let's create a scenario where an audio file will be passed for processing. The outcome of the scenario will be a text generated from the content of the audio file.
Several nodes must be added for the scenario to work successfully:

- (1) A Trigger on Webhook node to whose URL is sent a POST request containing a file;
- (2) A NVIDIA Canary-1B (Free Preview) node to process the file content. The file content can be an output parameter of the Trigger on Webhook node. To make the node return a response immediately without waiting for the results of file processing, the Async parameter should be checked.

- (3) A NVIDIA Canary-1B - Check result (Free Preview) node to get the result of file processing. The ID can be obtained from the NVIDIA Canary-1B (Free Preview) node parameters. File processing takes some time, so the output parameters of the node will not show the result, but the initial status will be displayed;

- (4) Wait node, to set the wait time, e.g. 30 seconds;

- (5) A Node NVIDIA Canary-1B - Check result (Free Preview) to retrieve the result of file processing. After waiting for a while, the processing status will already be complete and the node will have a response in its output parameters;

- (6) A Webhook response node, to send the result of the scenario execution.

The output of the scenario is text:

Using AI nodes to assist with writing a blog article
As an example of using AI nodes, let's create a scenario, during the execution of which we will analyze the proposed short text and form a blog article according to the given rules.
For convenience of using such a scenario we can create a table AirTable with columns:
- Summary - for the user to enter the idea and brief content of the article;
- Detailed content - for filling in the result of the scenario execution;
- Date - to record the date of text generation.
To generate the text of the article we will use the node mistral-7b-instruct-v0.1-awq With History (preview) from the group AI: Text Generation.
Several nodes must be added for the scenario to work successfully:

- (1) A New Records node to run a scenario when a new row is added to the LNBlog table. One of the output parameters of the node is the Summary attribute of the added row containing the article idea. Authorization is required for correct operation of the node;

- (2) Node mistral-7b-instruct-v0.1-awq With History (preview) to generate the article text. In the Dialogue History field you need to add instructions in JSON format that will be used by AI when generating the article text. The User Prompt field should be filled with the value of the Summary attribute of the Summary row of the LNBlog table, which is provided by the New Records node;
[{
"role": "system",
"content": "Determine the topic of the article. Carefully analyze the query that will serve as the basis for the article. Identify key features and benefits that should be emphasized. Create text that allows Latenode users to better understand why they should be interested in this feature. The article should be structured into sections. An attention-grabbing headline and opening paragraph that will interest the reader and encourage them to read further is essential. The query provided should be the starting point for more extended paragraphs. The article should contain use cases and interesting facts, as well as opportunities to automate business processes. The article should have a bottom line, you need to highlight the main benefits of using the platform and give readers a clear idea of its value. After creating the text, you should check it for grammatical errors, logical consistency and clarity of presentation."
}]

- (3) Update record node to update the Detailed content attribute of a row in the LNBlog table with the value generated in the mistral-7b-instruct-v0.1-awq With History (preview) node. The current time and date value can be entered as the date of text generation using the
now
operator. Authorization is required for correct operation of the node;

- (4) Webhook response node to generate a response to the scenario execution.
The result of the scenario execution is the "Ok" response of the Webhook response node and the AI generated text of the article in the LNBlog table:


Using AI for ASR and text summarization
As an example of using AI nodes, let's create a scenario that will:
- process the provided audio file;
- generate the full text content of the file;
- generate a brief text content of the file;
- send a notification e-mail to the user with the brief text content of the text file.
To process the audio file and generate the text we will use the nodes whisper (preview) from the group AI: Automatic Speech Recognition and bart-large-cnn (preview) from the group AI: Summarization.
Several nodes must be added for the scenario to work successfully:

- (1) Trigger on Webhook node to whose URL a POST request containing a file is sent;
- (2) whisper (preview) node to process the audio file. The content of the file is the output parameter of the Trigger on Webhook node;

- (3) Create New Document from Text node for writing the text resulting from audio file processing to Google disk. The name of the file can be anything, such as the current date and time. The text of the file is one of the output parameters of the whisper (preview) node. Authorization is required for correct operation of the node;

- (4) The bart-large-cnn (preview) node to process the text received in the whisper (preview) node and generate its summary. The maximum length of the node's response can be adjusted in the Max Length (Integer) field;

- (5) Send Email node for sending an email to a specified mail address with a summary text generated in bart-large-cnn (preview) node. Authorization is required for the node to work correctly;

The outputs of the scenario are:
- a file with text generated from the provided audio file;

- a letter summarizing the content of the audio file.

Using AI to analyze the sentiment of a text
As an example of using AI nodes to classify text, let's create a script whose execution will:
- analyze a message sent to a Telegram chat room;
- process the result of text classification and determine its "mood";
- send a notification email to the user with the content of the message, if the text is classified as negative;
- send a standard response to Telegram chat if the text is classified as positive.
For text processing we will use the node distilbert-sst-2-int8 (preview) from the group AI: Text Classification.
Several nodes and links with filters must be added for the script to work successfully:

- (1) New Message Updates node to run a script when a new message is sent to Telegram chat. In order for the node to work correctly, it is necessary to perform authorization and make sure that the bot is allowed to work with messages;

- (2) Node distilbert-sst-2-int8 (preview) to process message text. The text is the output parameter of the New Message Updates node;

- (3) A JavaScript node to process the distilbert-sst-2-int8 (preview) node data and return a response with the code below. The code categorizes a message as negative if the
NEGATIVE
is greater than 0.3. This number can be replaced if necessary:
export default async function run({execution_id, input, data, store}) { // Get the JSON string with classification results from the previous node and parse it into an array const classificationResults = JSON.parse(data["{{2.`result`.`result`}}"]); // Variable to store the sum of negative scores let negativeScoreSum = 0; // Iterate through the classification results and sum up the negative scores classificationResults.forEach(classification => { if (classification.label === 'NEGATIVE') { negativeScoreSum += classification.score; } }); // Determine the overall result based on the sum of negative scores const overallResult = negativeScoreSum > 0.3 ? "negative" : "positive"; // Return the result return { result: overallResult }; }

- (4) Send a Text Message or Reply node to send a standard message "Thank you for your review, it is very important to us!" if the text is classified as positive. The output of the New Message Updates node can be used as the chat identifier;

- (5) Link negative before the Send a Text Message or Reply node with the filter condition
{{$3.result != "negative"}}
set so that the script proceeds to execute the Send a Text Message or Reply node if the text is classified as positive;

- (6) Send Email node for sending an email to a specified mail address with the text of a Telegram message and mentioning the negative coloring of the message. Authorization is required for the node to work correctly;

- (7) Link positive before the Send Email node with the filtering condition
{{$3.result = "negative"}}
set so that the script proceeds to execute the Send Email node if the text is classified as negative;

The outcome of the script execution is one of two actions:
- sending a standard message to Telegram;

- a letter with a customized notice.

Using AI to Draft Responses to User Emails
As an example of using AI nodes, let's create a scenario that triggers upon receiving a new Gmail message. The result will be a draft reply email with text generated by AI. During the scenario execution, we'll use AI to classify the text to determine if it contains a question. Based on the classification results, the instructions for drafting the reply will differ.
Since any AI model requires instructions that may vary, we'll define several variables in the scenario:
- Response format
- Response length
- Role of the responder
We'll use the AI Anthropic Claude 3 node from the AI ChatGPT Alternatives group to generate the text.
To successfully execute the scenario, we'll need to add several nodes and conditions in the routes:

- (1) New Email node to trigger the scenario upon receiving a new email and to obtain its information. The output data will include the email content. Authorization is required to use this node.

- (2) SetVariables node to create the necessary text variables:
Length of the response - Length
Role of the responding user - Role
Format of the response - Format

- (3) interrogative route to branch the scenario if the email is interrogative in nature. To configure this route, set the condition
{{askAI("\rIf the text \"" + $1.data.decodedContent + "\" contains the character \"?\" or is interrogative in nature return true, otherwise false") = "True"}}

- (4) AI Anthropic Claude 3 interrogative node to generate a response to the interrogative email based on the given instructions. Configure this node by filling in the Model and User Prompt fields. The User Prompt field can be filled using the variables created in the SetVariables node, for example:
Generate a reply letter to the question {{$1.data.decodedContent}}
. In your reply, indicate that the question has been accepted and an answer will be generated soon. Recipient of the response {{$1.data.from}}
. Role of the responder {{_.Role}}
. Format of the response is {{_.Format}}
, and size of the response is {{_.Length}}
.

- (5) Create Draft Reply interrogative node to create a Gmail draft with the text generated by the AI Anthropic Claude 3 interrogative node. To configure this node, authorize access and select the parameters from the previous nodes.

- (6) narrative route to branch the scenario if the email is not interrogative, i.e., the interrogative route condition is not met. To configure this route, set the condition:
{{askAI("\rIf the text \"" + $1.data.decodedContent + "\" contains the character \"?\" or is interrogative in nature return true, otherwise false") != "True"}}

- (7) AI Anthropic Claude 3 narrative node to generate a response to the non-interrogative email based on the given instructions. Configure this node by filling in the Model and User Prompt fields. The User Prompt field can be filled using the variables created in the SetVariables node, for example:
Generate a draft response to a letter with the text {{$1.data.decodedContent}}
. Recipient of the response {{$1.data.from}}
. Role of the responder {{_.Role}}
. Format of the response is {{_.Format}}
, and size of the response is {{_.Length}}
.

- (8) Create Draft Reply narrative node to create a Gmail draft with the text generated by the AI Anthropic Claude 3 narrative node. To configure this node, authorize access and select the parameters from the previous nodes.

The result of the scenario execution is a draft reply email with content generated by AI.
Example 1
Incoming Email:

Generated Draft:

Example 2
Incoming Email:

Generated Draft:

Example 3
Incoming Email:

Generated Draft:

Example 4
Incoming Email:

Generated Draft:
