gpru


Namegpru JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
SummaryUnofficial Python client library for the OpenAI and Azure OpenAI APIs
upload_time2023-12-07 05:41:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords asyncio azure chatgpt gpt gpt-3 gpt-4 openai pydantic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # GPRU: Unofficial Python Client Library for the OpenAI and Azure OpenAI APIs

**PyPI**
[![PyPI - Version](https://img.shields.io/pypi/v/gpru.svg)](https://pypi.org/project/gpru)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/gpru.svg)](https://pypi.org/project/gpru)
[![License](https://img.shields.io/pypi/l/gpru.svg)](https://github.com/sincekmori/gpru/blob/main/LICENSE)

**CI/CD**
[![test](https://github.com/sincekmori/gpru/actions/workflows/test.yml/badge.svg)](https://github.com/sincekmori/gpru/actions/workflows/test.yml)
[![lint](https://github.com/sincekmori/gpru/actions/workflows/lint.yml/badge.svg)](https://github.com/sincekmori/gpru/actions/workflows/lint.yml)

**Build System**
[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)

**Code**
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)

**Docstrings**
[![docformatter](https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg)](https://github.com/PyCQA/docformatter)
[![numpy](https://img.shields.io/badge/%20style-numpy-459db9.svg)](https://numpydoc.readthedocs.io/en/latest/format.html)

---

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

```console
pip install gpru
```

## Examples

### OpenAI API

**Notes** Before anything else, you must ensure that the [API key](https://platform.openai.com/account/api-keys) is set as an environment variable named `OPENAI_API_KEY`.

Here is an example of [chat completion](https://platform.openai.com/docs/api-reference/chat/create), also known as [ChatGPT](https://chat.openai.com/).

```python
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](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/).

**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. |

```python
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?
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gpru",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "asyncio,azure,chatgpt,gpt,gpt-3,gpt-4,openai,pydantic",
    "author": null,
    "author_email": "Shinsuke Mori <sincekmori@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/78/c1/269515b147a1e24d09b4645d51e135f294b8ae78d266e1599a35dc1f5e17/gpru-0.3.1.tar.gz",
    "platform": null,
    "description": "# GPRU: Unofficial Python Client Library for the OpenAI and Azure OpenAI APIs\n\n**PyPI**\n[![PyPI - Version](https://img.shields.io/pypi/v/gpru.svg)](https://pypi.org/project/gpru)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/gpru.svg)](https://pypi.org/project/gpru)\n[![License](https://img.shields.io/pypi/l/gpru.svg)](https://github.com/sincekmori/gpru/blob/main/LICENSE)\n\n**CI/CD**\n[![test](https://github.com/sincekmori/gpru/actions/workflows/test.yml/badge.svg)](https://github.com/sincekmori/gpru/actions/workflows/test.yml)\n[![lint](https://github.com/sincekmori/gpru/actions/workflows/lint.yml/badge.svg)](https://github.com/sincekmori/gpru/actions/workflows/lint.yml)\n\n**Build System**\n[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)\n\n**Code**\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)\n\n**Docstrings**\n[![docformatter](https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg)](https://github.com/PyCQA/docformatter)\n[![numpy](https://img.shields.io/badge/%20style-numpy-459db9.svg)](https://numpydoc.readthedocs.io/en/latest/format.html)\n\n---\n\nGPRU is an unofficial Python client library for the OpenAI and Azure OpenAI APIs with improved usability through comprehensive annotations.\n\n**WARNING**: GPRU is currently under development and any destructive changes may be made until version `1.0.0`.\n\n## Installation\n\n```console\npip install gpru\n```\n\n## Examples\n\n### OpenAI API\n\n**Notes** Before anything else, you must ensure that the [API key](https://platform.openai.com/account/api-keys) is set as an environment variable named `OPENAI_API_KEY`.\n\nHere is an example of [chat completion](https://platform.openai.com/docs/api-reference/chat/create), also known as [ChatGPT](https://chat.openai.com/).\n\n```python\nimport os\n\nfrom gpru.openai.api import (\n    ChatCompletionModel,\n    ChatCompletionRequest,\n    OpenAiApi,\n    UserMessage,\n)\n\nkey = os.environ[\"OPENAI_API_KEY\"]\napi = OpenAiApi(key)\n\nreq = ChatCompletionRequest(\n    model=ChatCompletionModel.GPT_35_TURBO, messages=[UserMessage(\"Hello!\")]\n)\nchat_completion = api.create_chat_completion(req)\nprint(chat_completion.content)\n# Greetings! How can I assist you today?\n```\n\n### Azure OpenAI API\n\nThe following code replaces the same example with the [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/).\n\n**Notes** Set the following environment variables before executing the program.\n\n| Variable name                    | Value                                                                |\n| -------------------------------- | -------------------------------------------------------------------- |\n| `AZURE_OPENAI_API_ENDPOINT`      | URL in the form of `https://{your-resource-name}.openai.azure.com/`. |\n| `AZURE_OPENAI_API_KEY`           | Secret key.                                                          |\n| `AZURE_OPENAI_API_DEPLOYMENT_ID` | Custom name you chose for your deployment when you deployed a model. |\n\n```python\nimport os\n\nfrom gpru.azure.preview_2023_06_01 import (\n    AzureOpenAiApi,\n    ChatCompletionRequest,\n    UserMessage,\n)\n\nendpoint = os.environ[\"AZURE_OPENAI_API_ENDPOINT\"]\nkey = os.environ[\"AZURE_OPENAI_API_KEY\"]\ndeployment_id = os.environ[\"AZURE_OPENAI_API_DEPLOYMENT_ID\"]\napi = AzureOpenAiApi(endpoint, key)\n\nreq = ChatCompletionRequest(messages=[UserMessage(\"Hello!\")])\nchat_completion = api.create_chat_completion(deployment_id, req)\nprint(chat_completion.content)\n# Greetings! How can I assist you today?\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Unofficial Python client library for the OpenAI and Azure OpenAI APIs",
    "version": "0.3.1",
    "project_urls": {
        "Documentation": "https://github.com/sincekmori/gpru#readme",
        "Issues": "https://github.com/sincekmori/gpru/issues",
        "Source": "https://github.com/sincekmori/gpru"
    },
    "split_keywords": [
        "asyncio",
        "azure",
        "chatgpt",
        "gpt",
        "gpt-3",
        "gpt-4",
        "openai",
        "pydantic"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ab99672d48d1d58afc18e0b21f0519afd430256ec2e8f7924f1228b964a6b7fa",
                "md5": "ad0b91dd4498faf96d50a89219951d0e",
                "sha256": "11a831bc4ab486134c7f320815696e1d0765028f3bb62f9fc739e75c9171c17a"
            },
            "downloads": -1,
            "filename": "gpru-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad0b91dd4498faf96d50a89219951d0e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 83872,
            "upload_time": "2023-12-07T05:41:44",
            "upload_time_iso_8601": "2023-12-07T05:41:44.433151Z",
            "url": "https://files.pythonhosted.org/packages/ab/99/672d48d1d58afc18e0b21f0519afd430256ec2e8f7924f1228b964a6b7fa/gpru-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "78c1269515b147a1e24d09b4645d51e135f294b8ae78d266e1599a35dc1f5e17",
                "md5": "013b3a9be458a4dbe0fbb5fd5cfd62b6",
                "sha256": "26a9f8df75fd37623ecb348d41face7eee7af75dd6393da011c513d722b35d20"
            },
            "downloads": -1,
            "filename": "gpru-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "013b3a9be458a4dbe0fbb5fd5cfd62b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 76945,
            "upload_time": "2023-12-07T05:41:47",
            "upload_time_iso_8601": "2023-12-07T05:41:47.008680Z",
            "url": "https://files.pythonhosted.org/packages/78/c1/269515b147a1e24d09b4645d51e135f294b8ae78d266e1599a35dc1f5e17/gpru-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-07 05:41:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sincekmori",
    "github_project": "gpru#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gpru"
}
        
Elapsed time: 0.19916s