Skip to main content
Version: v1.1.7

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

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. In 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. In the Choose method list, select Import web pages.
  8. In the URL to import web pages from box, enter https://docs.h2o.ai/wave-apps/h2o-model-validation/Import web pages
  9. Click Add.

Job

note

The time it takes to crawl a website depends on its size, as Enterprise h2oGPTe crawls ten pages per second. You can change this at startup and not in the UI.

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 be able to 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 the Enterprise h2oGPTe navigation menu, click APIs.
  2. Click + New API Key.
  3. In the Key name (Optional) box, enter tutorial-2a.
  4. In the Collection (Optional) list, select tutorial-2a. Add a new API Key
  5. Click Generate new key.
  6. Click Copy.
    caution

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

  7. Click Confirm. Copy secret key

Step 3: Chat with 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

    We recommend installing the same version of the client as the utilized Enterprise h2oGPTe version.

    python -m venv enterprise

    source enterprise/bin/activate

    pip install h2ogpte==1.3.6
  2. Modify line 6 of the provided Python file with the copied/created Collection-specific API Key to establish communication with the documentation website. In particular, the file has been structured to ask the website (Collection) the following: What is H2O Model Validation? (line 15).

    tutorial-2a.py
    import os
    from h2ogpte import H2OGPTE

    client = H2OGPTE(
    address='https://playground.h2ogpte.h2o.ai',
    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)
    note

    The provided Python file was constructed using the code provided on the APIs page.

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

    caution

    Enterprise h2oGPTe saves and displays the asked question(s) in the Enterprise h2oGPTe UI.

    python3 tutorial-2a.py

    Response (answer): H2O Model Validation is an application that lets you assess the robustness and stability of trained H2O Driverless AI (DAI) models. It provides various validation tests to analyze the robustness and stability of a model or dataset, helping to avoid model degradation by revealing weaknesses and vulnerabilities in the datasets. It also centralizes and visualizes how DAI models and their datasets are validated for production.

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.


Feedback