# h2oGPTe Python Client
## Install
```bash
pip install h2ogpte
```
## Usage
```python
from h2ogpte import H2OGPTE
client = H2OGPTE(
address='https://h2ogpte.genai.h2o.ai',
api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
)
# Create a new collection
collection_id = client.create_collection(
name='Contracts',
description='Paper clip supply contracts',
)
# Create documents
# Note: Done for demonstration purposes only (not usually needed)
with open('dunder_mifflin.txt', 'w') as f:
f.write('There were 55 paper clips shipped, 22 to Scranton and 33 to Filmer.')
with open('initech.txt', 'w') as f:
f.write('David Brent did not sign any contract with Initech.')
# Upload documents
# Many file types are supported: text/image/audio documents and archives
with open('dunder_mifflin.txt', 'rb') as f:
dunder_mifflin = client.upload('Dunder Mifflin.txt', f)
with open('initech.txt', 'rb') as f:
initech = client.upload('IniTech.txt', f)
# Ingest documents (Creates previews, chunks and embeddings)
client.ingest_uploads(collection_id, [dunder_mifflin, initech])
# Create a chat session
chat_session_id = client.create_chat_session(collection_id)
# Query the collection
with client.connect(chat_session_id) as session:
reply = session.query(
'How many paper clips were shipped to Scranton?',
timeout=60,
)
print(reply.content)
reply = session.query(
'Did David Brent co-sign the contract with Initech?',
timeout=60,
)
print(reply.content)
# Summarize each document
documents = client.list_documents_in_collection(collection_id, offset=0, limit=99)
for doc in documents:
summary = client.summarize_document(
document_id=doc.id,
timeout=60,
)
print(summary.content)
# Chat with LLM without a collection
chat_session_id = client.create_chat_session()
with client.connect(chat_session_id) as session:
reply = session.query(
'Why is drinking water good for you?',
timeout=60,
)
print(reply.content)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "h2ogpte",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "information-retrieval, LLM, large-language-models, question-answering, search, semantic-search, analytical-search, lexical-search, document-search, natural-language-querying",
"author": null,
"author_email": "\"H2O.ai, Inc.\" <support@h2o.ai>",
"download_url": null,
"platform": null,
"description": "# h2oGPTe Python Client\n\n## Install\n\n```bash\npip install h2ogpte\n```\n\n## Usage\n\n```python\nfrom h2ogpte import H2OGPTE\n\nclient = H2OGPTE(\n address='https://h2ogpte.genai.h2o.ai',\n api_key='sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',\n)\n\n# Create a new collection\ncollection_id = client.create_collection(\n name='Contracts',\n description='Paper clip supply contracts',\n)\n\n# Create documents\n# Note: Done for demonstration purposes only (not usually needed)\nwith open('dunder_mifflin.txt', 'w') as f:\n f.write('There were 55 paper clips shipped, 22 to Scranton and 33 to Filmer.')\n\nwith open('initech.txt', 'w') as f:\n f.write('David Brent did not sign any contract with Initech.')\n\n# Upload documents\n# Many file types are supported: text/image/audio documents and archives\nwith open('dunder_mifflin.txt', 'rb') as f:\n dunder_mifflin = client.upload('Dunder Mifflin.txt', f)\n\nwith open('initech.txt', 'rb') as f:\n initech = client.upload('IniTech.txt', f)\n\n# Ingest documents (Creates previews, chunks and embeddings)\nclient.ingest_uploads(collection_id, [dunder_mifflin, initech])\n\n# Create a chat session\nchat_session_id = client.create_chat_session(collection_id)\n\n# Query the collection\nwith client.connect(chat_session_id) as session:\n reply = session.query(\n 'How many paper clips were shipped to Scranton?',\n timeout=60,\n )\n print(reply.content)\n\n reply = session.query(\n 'Did David Brent co-sign the contract with Initech?',\n timeout=60,\n )\n print(reply.content)\n\n# Summarize each document\ndocuments = client.list_documents_in_collection(collection_id, offset=0, limit=99)\nfor doc in documents:\n summary = client.summarize_document(\n document_id=doc.id,\n timeout=60,\n )\n print(summary.content)\n\n# Chat with LLM without a collection\nchat_session_id = client.create_chat_session()\n\nwith client.connect(chat_session_id) as session:\n reply = session.query(\n 'Why is drinking water good for you?',\n timeout=60,\n )\n print(reply.content)\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Client library for Enterprise h2oGPTe",
"version": "1.4.13",
"project_urls": {
"Documentation": "https://h2oai.github.io/h2ogpte/",
"Issues": "https://github.com/h2oai/h2ogpte/issues",
"Source": "https://github.com/h2oai/h2ogpte"
},
"split_keywords": [
"information-retrieval",
" llm",
" large-language-models",
" question-answering",
" search",
" semantic-search",
" analytical-search",
" lexical-search",
" document-search",
" natural-language-querying"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fe0570a759f61ac5a6a3d7f611854cc220d8d5d8094249843892fb5a5db64524",
"md5": "130d1c0f97419ddb3052ef03528738b9",
"sha256": "a353361a401b20faafdd34c32a78242b1bea2693488d11a4fa582de40fbcac74"
},
"downloads": -1,
"filename": "h2ogpte-1.4.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "130d1c0f97419ddb3052ef03528738b9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 45516,
"upload_time": "2024-05-02T06:13:44",
"upload_time_iso_8601": "2024-05-02T06:13:44.678196Z",
"url": "https://files.pythonhosted.org/packages/fe/05/70a759f61ac5a6a3d7f611854cc220d8d5d8094249843892fb5a5db64524/h2ogpte-1.4.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-02 06:13:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "h2oai",
"github_project": "h2ogpte",
"github_not_found": true,
"lcname": "h2ogpte"
}