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
ℹ️ Poetry is used as the build tool.
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 install client/dist/h2ogpt_client-*-py3-none-any.whl
from h2ogpt_client import Client
client = Client("http://0.0.0.0:7860")
# Text completion
text_completion = client.text_completion.create()
response = await text_completion.complete("Hello world")
# Text completion: synchronous
response = text_completion.complete_sync("Hello world")
# Chat completion
chat_completion = client.chat_completion.create()
reply = await chat_completion.chat("Hey!")
print(reply["user"]) # prints user prompt, i.e. "Hey!"
print(reply["gpt"]) # prints reply from h2oGPT
chat_history = chat_completion.chat_history()
# Chat completion: synchronous
reply = chat_completion.chat_sync("Hey!")
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