OpenAI Batcher
OpenAI Batcher is a Python package designed to process batches of user prompts using OpenAI's API. It allows for efficient batch processing and monitoring of jobs.
Installation
you can install the package directly using pip:
pip install openai-batcher
Alternatively, You can clone the repository and install the dependencies:
git clone https://github.com/srinathmkce/openai-batcher
cd openai_batcher
pdm install
Usage
Set your openai key
export OPENAI_API_KEY=<SET-YOUR-OPENAI-KEY-HERE>
Here's an example of how to use the process_batch function from the package:
from openai_batcher.batch import process_batch
from datasets import load_dataset
# Load dataset
dataset = load_dataset("stanfordnlp/imdb")
train_df = dataset["train"].to_pandas()
# Define system prompt
system_prompt = """
your task is to analyze the sentiment of the review and classify it as Positive or Negative. DO not add any explanation.
JSON:{"sentiment": String // Positive or Negative}
"""
# Process batch
process_batch(
system_prompt=system_prompt,
batch_user_prompts=train_df["text"],
start_index=0,
end_index=25,
batch_size=5
)
Development
To develop this package inside a development container, use the provided devcontainer.json and Dockerfile.
Using Dev Container Open the project in Visual Studio Code.Install the Remote - Containers extension.Reopen the project in the container. Building the Docker Image To build the Docker image manually, run:
docker build -t openai-batcher .
Next Steps
Your contribuitions are welcome. Following features are yet to be added
- Checkpointing
- Auto-Batching
- Improved Polling meachnism
- Test Cases
Metadata
Release files for openai-batcher 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openai_batcher-0.1.0.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openai_batcher-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / openai_batcher-0.1.0.tar.gz
| Download URL | openai_batcher-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
858ee7442cc29c043be71b8e8c924c66dab42aff1d90c05241aac8f0456a58de
|
|
BLAKE2b-256 checksum How to use checksums |
604696dd86acfc3d312e26cf5e2e1781dca307566b5281081ec9a0622dc886b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.18.1 CPython/3.11.9 Linux/5.10.102.1-microsoft-standard-WSL2
|
Release files / openai_batcher-0.1.0-py3-none-any.whl
| Download URL | openai_batcher-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afd45ec4767a6aef00017b3818e7096d5806776e43397defe1695d5d3a7902cb
|
|
BLAKE2b-256 checksum How to use checksums |
2c320dbe73143164dded387ee9ec096d956244521445b930eacf5b99e9d9788b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.18.1 CPython/3.11.9 Linux/5.10.102.1-microsoft-standard-WSL2
|