Skip to main content
Version: v1.6.8 🚧

Tutorial 2: 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​

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.

  1. On the Enterprise h2oGPTe navigation menu, click Collections.
  2. Click + New collection.
  3. In the Collection name box, enter:
    tutorial-2a
  4. In the Description box, enter:
    An AI-powered chatbot (model) to enhance website search
  5. Click + Create.
  6. Click + Add documents.
  7. Select Import from URL. Connectors
  8. In the URL to import box, enter:
    https://docs.h2o.ai/wave-apps/h2o-model-validation/
    Import web pages
  9. Click Add.
caution

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.

note

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.

  1. In Enterprise h2oGPTe, click Account Circle.
  2. Select Using the API.
  3. Click + New API Key.
  4. In the Key name box, enter:
    tutorial-2a
  5. In the Restrict to collection list, select tutorial-2a. Add a new API Key
  6. Click Generate new key.
  7. Click Copy.
    caution

    Do not share your API Key with others or expose it within the browser or other client-side code.

  8. Click Close. Copy secret key

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.

  1. Create a Python environment with the Enterprise h2oGPTe client.

    caution

    It's advisable to install the client version that matches the Enterprise h2oGPTe version currently in use.

    note

    To access the Enterprise h2oGPTe Python Client documentation, see h2oGPTe Python Client.

    python -m venv enterprise

    source enterprise/bin/activate

    pip install h2ogpte==1.5.12
  2. Where you created the enterprise Python environment, create a Python file with the following name:

    tutorial-2.py
  3. In the tutorial-2.py file, paste the following:

    tutorial-2a.py
    import 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)
  4. Revise line 5 to indicate the URL where Enterprise h2oGPTe is operational (the first URL with the domain name and without any additional paths).

  5. Modify line 6 the created (copied) Collection-specific API Key to establish communication with the H2O Model Validation documentation website.

  6. The provided Python code has been structured to ask the website (Collection) the following: What is H2O Model Validation? (line 15).

  7. Run the tutorial-2a.py file.

    caution

    Enterprise 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

    Answer UI answer

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:


Feedback