Skip to main content

OpenAI Request Runner

Pypi CI License: MIT Status

Twitter

A lightweight Python package designed to facilitate parallel processing of OpenAI API requests. This implementation is inspired by the OpenAI cookbook example but offers advanced customization capabilities and integration with OpenAI Functions (leaning on the great openai_function_call library). It ensures efficient and organized interactions with the OpenAI models. Features

  • Parallel Processing: Handle multiple OpenAI API requests concurrently.
  • Rate Limiting: Adheres to rate limits set by the OpenAI API.
  • Advanced Customization: Allows for detailed input preprocessing and API response postprocessing.
  • OpenAI Functions: Seamlessly integrates with OpenAI Functions for added capabilities.
  • Error Handling: Efficiently manage and log errors, including rate limit errors.
  • Extendable: Easily integrate with custom schemas and other extensions.

Installation

Using pip (wip)

pip install openai_request_runner

Git

pip install git@https://github.com/jphme/openai_request_runner

Using poetry

For local development and testing:

poetry install

Usage

Minimal example:

from openai_request_runner import run_openai_requests

example_input = [{"id": 0, "prompt": "What is 1+1?"}]
results = run_openai_requests(
        example_input, system_prompt="Translate input to French"
    )

#in a notebook env you need nest_asyncio, see below

print(results[0]["content"])
# "Qu'est-ce que 1+1 ?"

See examples/classify_languages.py and examples/translate.py for detailed examples of how to use the package for advanced usecases.

The package allows for extensive customization. You can set your desired preprocessing function, postprocessing function, and other parameters to suit your specific needs.

Refer to the inline documentation and docstrings in the code for detailed information on each function and its parameters.

Run inside a notbook

If you want to run openai_request_runner inside a notebook, use nest_asyncio like this:

import nest_asyncio
nest_asyncio.apply()

Run Tests

poetry run pytest tests/

Contributing

Contributions are welcome! Please open an issue if you encounter any problems or would like to suggest enhancements. Pull requests are also appreciated.

License

MIT

Metadata

Release files for openai_request_runner 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai_request_runner 0.1.0
File Size Uploaded
openai_request_runner-0.1.0.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai_request_runner 0.1.0
File Interpreter ABI Platform
openai_request_runner-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / openai_request_runner-0.1.0.tar.gz

Download URL openai_request_runner-0.1.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
27258acead8a67b97df0edcdfe9d44569319ac1e4f9d52212f0ee84c6d64daa0
BLAKE2b-256 checksum
How to use checksums
82e25e7c318f3bb2971988fff5c36bf0e53de1649a5f925af4929303c2d9e883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1016-azure

Release files / openai_request_runner-0.1.0-py3-none-any.whl

Download URL openai_request_runner-0.1.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9dc9315d74c3d8eb037a7cdb3d7711b7b9327e698d58337d6b070309bbfb75a0
BLAKE2b-256 checksum
How to use checksums
f7da2121693b5a5743ba3144b0c126e4b5657a51fdc93daf96c959c754e1a51d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.13 Linux/6.2.0-1016-azure

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page