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
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
key = os.environ["OPENAI_API_KEY"]
api = OpenAiApi(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"]
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?
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
Built Distribution
File details
Details for the file gpru-0.0.3.tar.gz
.
File metadata
- Download URL: gpru-0.0.3.tar.gz
- Upload date:
- Size: 63.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8badc95aa7eb016c3b4fc1d017702bb4a4de7c055e871cf34cc400d954a45e5d |
|
MD5 | 913f48a8593e68f029e81bcc42cb8fd6 |
|
BLAKE2b-256 | 46ca616d5726c0b6eb39e51fc7cb587ee66c0e885b3fd61815404cab89a1a7aa |
File details
Details for the file gpru-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: gpru-0.0.3-py3-none-any.whl
- Upload date:
- Size: 70.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d98e0cd7457be77312380945769a5e64bb2fcfc42c67948e15ba798e740d7cdd |
|
MD5 | 78dcc120d87b0ce16e80d780ed6d9221 |
|
BLAKE2b-256 | 408c6e06d315b65f616df37fdfdedb5c6ff00f05e67ad5ef946770548fdcced9 |