GPRU: Unofficial Python Client Library for the OpenAI and Azure OpenAI APIs
GPRU is an unofficial Python client library for the OpenAI and Azure OpenAI APIs with improved usability through comprehensive annotations.
WARNING: GPRU is currently under development and any destructive changes may be made until version 1.0.0.
Installation
pip install gpru
Examples
OpenAI API
Notes Before anything else, you must ensure that the API key is set as an environment variable named OPENAI_API_KEY.
Here is an example of chat completion, also known as ChatGPT.
import os
from gpru.openai.api import (
ChatCompletionModel,
ChatCompletionRequest,
OpenAiApi,
UserMessage,
)
key = os.environ["OPENAI_API_KEY"]
api = OpenAiApi(key)
req = ChatCompletionRequest(
model=ChatCompletionModel.GPT_35_TURBO, messages=[UserMessage("Hello!")]
)
chat_completion = api.create_chat_completion(req)
print(chat_completion.content)
# Greetings! How can I assist you today?
Azure OpenAI API
The following code replaces the same example with the Azure OpenAI API.
Notes Set the following environment variables before executing the program.
| Variable name | Value |
|---|---|
AZURE_OPENAI_API_ENDPOINT |
URL in the form of https://{your-resource-name}.openai.azure.com/. |
AZURE_OPENAI_API_KEY |
Secret key. |
AZURE_OPENAI_API_DEPLOYMENT_ID |
Custom name you chose for your deployment when you deployed a model. |
import os
from gpru.azure.preview_2023_06_01 import (
AzureOpenAiApi,
ChatCompletionRequest,
UserMessage,
)
endpoint = os.environ["AZURE_OPENAI_API_ENDPOINT"]
key = os.environ["AZURE_OPENAI_API_KEY"]
deployment_id = os.environ["AZURE_OPENAI_API_DEPLOYMENT_ID"]
api = AzureOpenAiApi(endpoint, key)
req = ChatCompletionRequest(messages=[UserMessage("Hello!")])
chat_completion = api.create_chat_completion(deployment_id, req)
print(chat_completion.content)
# Greetings! How can I assist you today?
Metadata
Release files for gpru 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gpru-0.3.1.tar.gz | 76.9 kB | Without provenance | Details for gpru-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gpru-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for gpru-0.3.1-py3-none-any.whl |
Total release size: 160.8 kB
Release files / gpru-0.3.1.tar.gz
| Download URL | gpru-0.3.1.tar.gz |
|---|---|
| Size | 76.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26a9f8df75fd37623ecb348d41face7eee7af75dd6393da011c513d722b35d20
|
|
BLAKE2b-256 checksum How to use checksums |
78c1269515b147a1e24d09b4645d51e135f294b8ae78d266e1599a35dc1f5e17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.25.1
|
Release files / gpru-0.3.1-py3-none-any.whl
| Download URL | gpru-0.3.1-py3-none-any.whl |
|---|---|
| Size | 83.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11a831bc4ab486134c7f320815696e1d0765028f3bb62f9fc739e75c9171c17a
|
|
BLAKE2b-256 checksum How to use checksums |
ab99672d48d1d58afc18e0b21f0519afd430256ec2e8f7924f1228b964a6b7fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.25.1
|
Security for gpru 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.