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.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

uopenai-0.2.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uopenai-0.2.2.tar.gz
  • Upload date:
  • Size: 4.6 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.2.tar.gz
Algorithm Hash digest
SHA256 612c7a3c991b853588c0d471d1c2945c819a3cacb367dfbf253067ba2855eb01
MD5 d36cb778615535ad645a520d2c7d96d3
BLAKE2b-256 eb109fb7066a554904f72ce500b38e2c473e6dffe4f0efa79fa1e152e3f1cceb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uopenai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 67488f917b7f77e5e8f6f3c6da0eab8273541bdedab329d8b2b603711c0d6b77
MD5 48e34374b594e7665946b3e9eeea33d4
BLAKE2b-256 a9c0eefb380cc0eff77f801d052080c9237f837d4c0840565f0f3746e6771e17

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