Skip to main content
Version: v1.6.8 🚧

Tutorial 1: Chat with a website

Overview​

This tutorial demonstrates how to use the h2oGPTe Python Client Library to interact with a website. We will use H2O Label Genie's documentation website for this tutorial.

Prerequisites​

  • A global API key: Sign up/in at Enterprise h2oGPTe and create a global API key.

Code​

from h2ogpte import H2OGPTE

# Step 1: Set up client
# Instantiate an h2oGPTe client by providing:
# - address (address): Specifies the URL where Enterprise h2oGPTe is hosted. The address should be where the API key was created.
# - global API key (api_key): Provides full system-wide access to all collections, documents, chats, and settings within the h2oGPTe service, allowing for secure communication and interaction with all aspects of your work.
client = H2OGPTE(
address="https://h2ogpte.genai.h2o.ai",
api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
)

# Step 2: Create a Collection
collection_id = client.create_collection(
name="Chat with website",
description="Chat with the H2O Label Genie documentation website",
)

# Step 3: Crawl website
website = client.ingest_website(
collection_id=collection_id,
url="https://docs.h2o.ai/wave-apps/h2o-label-genie/"
)

# Step 4: Initiate a chat session
chat_session_id = client.create_chat_session(collection_id=collection_id)

with client.connect(chat_session_id) as session:

# Step 5: Chat with the website
reply = session.query("What is H2O Label Genie?")

print(
f"Content: {reply.content}\n" # Response to the sent query
f"Created at: {reply.created_at}\n"
f"Error: {reply.error}\n"
f"ID: {reply.id}\n"
f"Model computed fields: {reply.model_computed_fields}\n"
f"Model config: {reply.model_config}\n"
f"Model fields: {reply.model_fields}\n"
f"Reply to: {reply.reply_to}\n"
f"Type list: {reply.type_list}\n"
f"Votes: {reply.votes}"
)
Content: According to the provided context, H2O Label Genie is an application developed by H2O.ai that automates the process of labeling data. It is designed to assist users in annotating datasets and creating annotation tasks for various purposes, such as zero-shot learning models and clustering tasks. H2O Label Genie aims to streamline the labeling process and improve efficiency in data exploration and analysis.
Created at: 2024-10-30 20:49:32.294197
Error: None
ID: e76a8cc4-fa52-4901-ab55-1a5b67e47713
Model computed fields: {}
Model config: {}
Model fields: {'id': FieldInfo(annotation=str, required=True), 'content': FieldInfo(annotation=str, required=True), 'reply_to': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'votes': FieldInfo(annotation=int, required=True), 'created_at': FieldInfo(annotation=datetime, required=True), 'type_list': FieldInfo(annotation=Union[List[str], NoneType], required=False, default=None), 'error': FieldInfo(annotation=Union[str, NoneType], required=False, default=None)}
Reply to: 7e7107af-4dc3-4fd6-947a-d3715e7c9531
Type list: []
Votes: 0

Feedback