This is a step-by-step guide to create a conversational assistant with internet search using Flows in Globant Enterprise AI.
This Flow manages two assistants: a Chat Assistant that answers questions using internet search results, and another Chat Assistant that rephrases follow-up questions (based on the conversation history) as standalone questions. In addition, it includes a Search API component.
To get started, first, make sure you have access to the Globant Enterprise AI Backoffice and are familiar with the interface for creating Flows.
In this step, two Chat Assistants are created. They are called 'Response from Search' and 'Follow-up Rephrase'.
This Chat Assistant generates answers for the end user based solely on the results of an internet search, without using prior knowledge or inventing information. It takes the provided search results and uses them to answer the end user's question in the best possible way. If necessary, the answer can include rich text in HTML format, but Markdown should not be used to format the answer.
LLM Settings:
AI Provider: Google VertexAI
Model: gemini-1.5-pro
Temperature: 0.10
Max Output Tokens: 8192
Prompt:
INSTRUCTIONS
------------
Your task is to generate a response for the user based on the results of an internet search.
DO NOT USE PRIOR KNOWLEDGE AND DO NOT MAKE UP INFORMATION USE THE SEARCH RESULTS.
Given the following results from an internet search and NOT PRIOR KNOWLEDGE answer the user question the best you can.
SEARCH RESULTS
--------------
{searchResults}
RESPONSE FORMAT
---------------
For the response you can generate RICH TEXT USING HTML if it is needed.
DO NOT USE MARKDOWN TO FORMAT YOUR RESPONSE.
FOR RICH TEXT DO NOT USE MARKDOWN USE HTML INSTEAD.
This Chat Assistant rephrases a follow-up question based on the conversation history, ensuring it becomes a standalone question if needed. If the follow-up question already works as a standalone question, it simply repeats the question without any changes.
LLM Settings:
AI Provider: Google VertexAI
Model: gemini-1.5-pro
Temperature: 0.10
Max Output Tokens: 8192
Prompt:
Given the conversation history and not prior knowledge, and a follow-up question, rephrase the follow-up question to be a standalone question IF IT IS NEEDED. If the question works as a standalone question, just repeat the question.
RESPONSE ONLY WITH THE STANDALONE QUESTION AND NOTHING MORE; DO NOT INCLUDE ANY OTHER TEXT.
Follow the steps described in How to create a Flow to create the Flow called 'Search Assistant' with the following structure:

To add the API component, go to the Interactions section and, below INTEGRATIONS in the Flow menu, drag the component between the Assistants nodes.

Go to Google Search API documentation and click on Get API key button.

In the pop-up window that opens, select or create a project from the Select or create project menu.

Select the Yes option to agree that the use of the services and related APIs is subject to compliance with the applicable Terms of Service. Then click on NEXT to continue with the setup process.
In the next window, click on the SHOW KEY button to reveal the API Key. Copy this API key, as it will be required to configure the API node in your flow.

Go to Programmable Search Engine and click on the Add button.

In the pop-up window that opens, fill in the necessary fields to create the search engine:

- Name of your search engine: In the "Search engine name" field, enter a name for the search engine, such as Search Assistant.
- What to search for: Select the "Search the entire web" option to have the engine search the entire web. If you prefer to search only specific sites, you can select the "Search specific sites or pages" option and add the necessary URLs.
- Search settings: If you wish, you can adjust additional settings such as image search or SafeSearch filter.
- Captcha: Select the "I am not a robot" checkbox.
- Create: At the end of the window, click on the Create button to finalize the creation of the search engine.
In the window that appears, you must click on the Customize button.

This will take you to the Overview section of the search engine you have just created. In this section, you should find and copy the Search engine ID, which is a unique value associated with your search engine. This ID is required to configure the API node in your flow.

With the Search engine ID and API key, you can now configure the API node. First, you must click on the Edit button that appears when you position the mouse over the API node.

Once you have clicked on Edit, the State Configuration menu will be displayed on the left side.

Within this menu, in the URL section, you must configure the URL with the following value:
https://www.googleapis.com/customsearch/v1?key=<API key>&cx=<Search engine ID>&q=<query>
Be sure to replace <API key> and <Search engine ID> with the previously obtained values.
In the API node, go to the Parameters section and click on + Add new to add a new parameter. Then, configure the parameter with the following details:
- Parameter name: q.
- Value: lastResponse (the value obtained from the previous response).
Next, in the State Configuration section, you must make sure to mark q as Query params.

In the Responses section, make sure to map the items property to the searchResults variable. If searchResults is not available, you can click on Add new variable to create it.

After you have configured the API node, go to the Assistant node, which is located just below the API node in your flow. In this node, find the Variable section and change the input variable to searchResults.

Finally, save the changes and test the flow. You can use the test window or the Playground to make sure everything works correctly, verifying that the Assistant responds properly using the search results.