A Python thin-client for h2oGPT.
- Python 3.8+
If you don't have Python 3.8 in your system, you can use Conda.
conda create -n h2ogpt_client_build -y
conda activate h2ogpt_client_build
conda install python=3.8 -y
Install the latest nightly wheel from S3.
pip install https://s3.amazonaws.com/artifacts.h2o.ai/snapshots/ai/h2o/h2ogpt_client/latest-nightly/h2ogpt_client-0.1.0-py3-none-any.whl
Nightly releases can also be found here
If want to build fresh wheel from main branch instead of getting nightly, follow these instructions.
ℹ️ Poetry is used as the build tool.
rm -rf client/.poetry/
make -C client setup
make -C client build
Distribution wheel file can be found in the client/dist
directory. This wheel can be installed in the primary h2oGPT environment or any other environment, e.g.
pip uninstall -y h2ogpt_client
pip install client/dist/h2ogpt_client-*-py3-none-any.whl
Based upon test code and test code test_readme_example
:
def test_readme_example(local_server):
import os
import asyncio
from h2ogpt_client import Client
if local_server:
client = Client("http://0.0.0.0:7860")
else:
h2ogpt_key = os.getenv("H2OGPT_KEY") or os.getenv("H2OGPT_H2OGPT_KEY")
if h2ogpt_key is None:
return
# if you have API key for public instance:
client = Client("https://gpt.h2o.ai", h2ogpt_key=h2ogpt_key)
# Text completion
text_completion = client.text_completion.create()
response = asyncio.run(text_completion.complete("Hello world"))
print("asyncio text completion response: %s" % response)
# Text completion: synchronous
response = text_completion.complete_sync("Hello world")
print("sync text completion response: %s" % response)
# Chat completion
chat_completion = client.chat_completion.create()
reply = asyncio.run(chat_completion.chat("Hey!"))
print("asyncio text completion user: %s gpt: %s" % (reply["user"], reply["gpt"]))
chat_history = chat_completion.chat_history()
print("chat_history: %s" % chat_history)
# Chat completion: synchronous
reply = chat_completion.chat_sync("Hey!")
print("sync chat completion gpt: %s" % reply["gpt"])
test_readme_example(local_server=True)
In an h2oGPT environment with the client installed, can run tests that test client and server.
- Install test dependencies of the Client into the h2oGPT Python environment.
make -C client setup_test
- Run the tests with h2oGPT.
pytest client/tests/
If you already have a running h2oGPT server, then set the H2OGPT_SERVER
environment variable to use it for testing.
make H2OGPT_SERVER="http://0.0.0.0:7860" -C client test