Skip to main content

Minimalistic library to call OpenAI API, with httpx and type-hinting

Project description

uOpenAI

uOpenAI is a lightweight, asynchronous Python library designed to interact with the OpenAI API. Leveraging the power of httpx for async HTTP requests and pydantic for data validation and settings management, it aims to provide a seamless and efficient way to access OpenAI's capabilities in modern async Python applications.

Features

  • Fully Asynchronous: Built from the ground up for asyncio compatibility.
  • Type-Hinted: Ensures robust code through comprehensive type annotations.
  • Simple and Intuitive: A straightforward API to access OpenAI's features with minimal boilerplate.

Installation

To install uOpenAI, run:

pip install uopenai

Quick Start

Here's a quick example to get you started:

import asyncio
from uopenai import OpenAI, Message

async def main():
    api = OpenAI("your-api-key")
    # Complete a prompt with options
    res = await api.complete([Message("system", "You are a chat bot"), Message("user", "What’s on your mind?")], max_tokens=50)
    print(res.choices[0].message.content)

    # easy version

    res = await api.easy_complete("What’s on your mind?", "You are a chat bot")

    res = await api.easy_complete("What’s on your mind?",
                    "You are a JSON answering machine, give the answer in JSON only.", json=True)

if __name__ == "__main__":
    asyncio.run(main())

Replace "your-api-key" with your actual OpenAI API key.

Requirements

  • Python 3.7+
  • OpenAI API key
  • httpx
  • pydantic

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

uOpenAI is released under the The Unlicense. See the LICENSE file for more details.

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

uopenai-0.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

uopenai-0.2.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file uopenai-0.2.1.tar.gz.

File metadata

  • Download URL: uopenai-0.2.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.2

File hashes

Hashes for uopenai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1ca73088b030c552c1dc401fc17280a0dbebae436e9e4548efd2d524d616ef00
MD5 6568dbaafbb728c1640ce4e50adcd91b
BLAKE2b-256 78182bb743ee7f2c861b84c074dd6581ff3fc40456314c50bb19826b6f08cc41

See more details on using hashes here.

File details

Details for the file uopenai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: uopenai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.2

File hashes

Hashes for uopenai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d7eeb0d78eab543fdcfa46e8bdbc15e173d5032decee75ea9b4b91be3a7094b
MD5 aab14d7a88e9ab840d21cf9223110f06
BLAKE2b-256 5816dbf516a31b20e906696419434b8b2c657c70aa2d86f16ed8b4b82fd67272

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