Chatbot with Google Search Assistance
This guide covers how to build a chat callable that refines user questions with Google Searches to obtain a response from a LLM that references data from websites.
Last updated
This guide covers how to build a chat callable that refines user questions with Google Searches to obtain a response from a LLM that references data from websites.
Last updated
Navigate to the Callable Builder tab in the top right of the navigation bar and go ahead and press Create Callable. Name your callable "llm-with-google-assist" and give the following description:
Answer questions with high factual accuracy by searching online and compiling responses based on content downloaded from websites (with references).
Select Private and choose the Barebone template callable before pressing Create.
Once inside the Callable Builder, you should see two blocks: INPUT, OUTPUT. Since we are creating a Chatbot let's switch the input type in the INPUT block to ChatDataset.
Message objects contain the entire conversation history as an array with the last message in the array from the user. In order to send a google search query, we first need to extract the relevant context of the conversation to enhance the user’s question and receive correct search results.
To do this, click the plus and create two code blocks: one to extract the question and the second to extract the conversation history.
Once we extract the question and history with the respected code blocks, we can refine our question with a language model so that it will include the context of the history inside a Model Block.
For the model configuration, we want a temperature of 0.1 for a more conservative change and so that our original question is not altered dramatically.
After refining our question, we want to create a google search query using the result from the REFINED_QUESTION block that will provide links to relevant websites.
Our google search query provides us with a few of the most relevant links related to our query. In order to extract the information from these links, we must utilize a Map Reduce block and call a web crawler block on each link to retrieve the details from the google search results.
In order to extract the relevant links and web crawl over them, we want to simplify our GOOGLE_SEARCH object into a result object with a field for the title and link before starting our Map Reduce block. This can be done with another Code block.
Now with a list of relevant links formatted correctly, we can start a Map Reduce loop to collect a summary of each link.
This loop begins by calling upon a Web Page Crawler Block with each link to retrieve the HTML body of the page.
Then, another code block is called upon with the web crawler data to format into content blocks with only the first 2000 bytes of the HTML body.
Once the data is collected, a language model block can help us summarize the raw data from the HTML body into a single paragraph for which we can use in our final prompt.
The last block in the loop is a code block that nicely formats the link summaries into an object for us to reference in our final prompt.
Lastly, we need to combine the data from all relevant links together along with the original question into a single prompt before sending to our language model. This can be done with a code block that loops through each FORMAT_SUMMARY object to extract the summary of the links and append it into a single string with the original question.
Once this is finished, the last step is to run the final prompt in a language model prompt and extract the results.
Congratulations, you have created a chatbot that uses google search to find relevant information about the question. Create some test cases and deploy your callable to start using it in any application.