Skip to main content

Unofficial Python client library for the OpenAI and Azure OpenAI APIs

Project description

GPRU: Unofficial Python Client Library for the OpenAI and Azure OpenAI APIs

PyPI PyPI - Version PyPI - Python Version License

CI/CD test lint

Build System Hatch project

Code pre-commit Code style: black Imports: isort Checked with mypy Ruff

Docstrings docformatter numpy


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 ChatCompletionRequest, OpenAiApi, UserMessage

api_key = os.environ["OPENAI_API_KEY"]
api = OpenAiApi(api_key)

req = ChatCompletionRequest(model="gpt-3.5-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.stable_2023_05_15 import (
    AzureOpenAiApi,
    ChatCompletionRequest,
    UserMessage,
)

endpoint = os.environ["AZURE_OPENAI_API_ENDPOINT"]
api_key = os.environ["AZURE_OPENAI_API_KEY"]
deployment_id = os.environ["AZURE_OPENAI_API_DEPLOYMENT_ID"]
api = AzureOpenAiApi(endpoint, api_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?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpru-0.0.1.tar.gz (63.0 kB view details)

Uploaded Source

Built Distribution

gpru-0.0.1-py3-none-any.whl (69.6 kB view details)

Uploaded Python 3

File details

Details for the file gpru-0.0.1.tar.gz.

File metadata

  • Download URL: gpru-0.0.1.tar.gz
  • Upload date:
  • Size: 63.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.0

File hashes

Hashes for gpru-0.0.1.tar.gz
Algorithm Hash digest
SHA256 96be767f24de79ea7f58631b1eb344c08c853ba20cee29782f822e343c43eaa1
MD5 965147c5bad6e2c93ed543d0a645946e
BLAKE2b-256 5d701d543ab6ba9e441612fd8cbef16c45315bc54e53f2397a30307c5dc68a74

See more details on using hashes here.

File details

Details for the file gpru-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: gpru-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 69.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.0

File hashes

Hashes for gpru-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd66a6949e00409a6eb2955b58df45071d7369a80ab865a510048503b9f9adc5
MD5 c3071c6e7924d24d9b0ca9667bbc436e
BLAKE2b-256 a4fbaccc6d5b5b34bcfbc0e0bdeeb679fc3893ed32dee636e19e3409fa4e5e5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page