Tutorial 2A: Build an AI-powered chatbot (model) to enhance a website's search capabilities
Overview​
This tutorial with Enterprise h2oGPTe and Python builds an AI-powered chatbot to replace the function of a website's search bar, which, in turn, builds something better to enable users to obtain better answers to their questions about the website. In this tutorial, we will create an AI-powered chatbot to enhance the search capabilities of the H2O Model Validation documentation website.
Objectives​
- Understand how to crawl a website and convert its pages into documents using Enterprise h2oGPTe.
- Learn how to create a Collection-specific API Key in Enterprise h2oGPTe and use it to chat with a Collection.
- Understand how to use Python and the Enterprise h2oGPTe client to Chat with a website and retrieve information from it.
- Learn how to create an AI-powered chatbot to enhance the search capabilities of a website.
Prerequisites​
- (Optional) Review the Enterprise h2oGPTe workflow
- Complete Tutorial 1A: A quick introduction to Enterprise h2oGPTe
- Basic understanding of Python
Step 1: Crawl website​
Enterprise h2oGPTe enables you to crawl a website, which converts the specified website pages into Documents that can be associated with a Collection that you can Chat with. For this tutorial, we will crawl the H2O Model Validation documentation website.
- On the Enterprise h2oGPTe navigation menu, click Collections.
- Click + New collection.
- In the Collection name box, enter:
tutorial-2a
- In the Description box, enter:
An AI-powered chatbot (model) to enhance website search
- Click + Create.
- Click + Add documents.
- Select Import from URL.
- In the URL to import box, enter:
https://docs.h2o.ai/wave-apps/h2o-model-validation/
- Click Add.
The website's size determines the time it takes Enterprise h2oGPTe to crawl a website. Enterprise h2oGPTe processes ten pages per second. You can modify this rate at startup; contact your administrator for more details.
Continue to step 2 until the crawling Job reaches 100% completion.
Step 2: Create a Collection-specific API Key​
To access the Collection containing the content of the crawled website externally, you can create a Collection-specific API Key that enables you to Chat with the Collection. For this tutorial, a Collection-specific API key with Python will enable the creation of a chatbot to enhance the search capabilities of the H2O Model Validation documentation website. Let's create a Collection-specific API key.
Collection-specific API keys do not allow other API calls, such as creation, deletion, or access to other Collections or Chats. On the other hand, you can create Global API Keys to externally create, delete, or interact with any of your past, current, and future Collections, Documents, Chats, and settings. To learn more, see Types of API Keys.
- In Enterprise h2oGPTe, click Account Circle.
- Select Using the API.
- Click + New API Key.
- In the Key name box, enter:
tutorial-2a
- In the Restrict to collection list, select tutorial-2a.
- Click Generate new key.
- Click caution
Do not share your API Key with others or expose it within the browser or other client-side code.
Copy. - Click Close.
Step 3: Chat with the H2O Model Validation website​
Let's Chat with the H2O Model Validation documentation website using Python and the created Collection-specific API Key.
Create a Python environment with the Enterprise h2oGPTe client.
cautionIt's advisable to install the client version that matches the Enterprise h2oGPTe version currently in use.
noteTo access the Enterprise h2oGPTe Python Client documentation, see h2oGPTe Python Client.
python -m venv enterprise
source enterprise/bin/activate
pip install h2ogpte==1.5.17Where you created the enterprise Python environment, create a Python file with the following name:
tutorial-2.py
In the tutorial-2.py file, paste the following:
tutorial-2a.pyimport os
from h2ogpte import H2OGPTE
client = H2OGPTE(
address='https://',
api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
)
# Automatically connects to the Collection connected to the Collection-specific API key
chat_session_id = client.create_chat_session_on_default_collection()
# Query the Collection
with client.connect(chat_session_id) as session:
reply = session.query(
'What is H2O Model Validation?',
timeout=60,
)
print(reply.content)
Revise line 5 to indicate the URL where Enterprise h2oGPTe is operational (the first URL with the domain name and without any additional paths).
Modify line 6 the created (copied) Collection-specific API Key to establish communication with the H2O Model Validation documentation website.
The provided Python code has been structured to ask the website (Collection) the following: What is H2O Model Validation? (line 15).
Run the tutorial-2a.py file.
cautionEnterprise h2oGPTe saves and displays the asked question(s) in the Enterprise h2oGPTe UI (in this case, in the tutorial-2a Collection).
python3 tutorial-2a.py
Summary​
In this tutorial, we learned how to build an AI-powered chatbot using Enterprise h2oGPTe and Python to enhance website search capabilities. The objectives of this tutorial included crawling a website, creating a Collection-specific API key, and chatting with the website using Python. By completing this tutorial, we gained the ability to develop an AI-powered chatbot to replace the function of a website's search bar, enabling users to obtain better answers to their questions about the website.
Next​
After completing this tutorial, you can learn how to import and interact with audio or images in a Collection. To learn more, see:
- Submit and view feedback for this page
- Send feedback about Enterprise h2oGPTe to cloud-feedback@h2o.ai