gpru 0.3.1

Creator: bradpython12

Last updated:

Add to Cart

Description:

gpru 0.3.1

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



CI/CD


Build System

Code





Docstrings



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?

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.