Skip to main content

RLHF-Utils

PyPI version Python Versions License: MIT

A streamlined Python toolkit for building and working with Large Language Models (LLMs), designed for researchers and engineers.

🚀 Installation

pip install rlhf-utils

✨ Features

  • Online Server Module: Efficient utilities for LLM API integrations
    • ⚡ Parallel OpenAI API calls with multithreading
    • 📊 Built-in progress tracking for batch requests
    • 🛡️ Error handling and retry logic
    • 🔄 Complete API response access

🔍 Usage Examples

Parallel OpenAI API Calls

Process multiple prompts simultaneously with optimal resource utilization:

from rlhf_utils.online_server import multithread_openai_chat_completions_call
from openai import OpenAI

# Initialize OpenAI client
client = OpenAI(api_key="your-api-key")

# Define messages for multiple API calls
messages = [
    [{"role": "user", "content": "Explain quantum computing"}],
    [{"role": "user", "content": "Write a short poem about AI"}],
    [{"role": "user", "content": "Summarize the history of the internet"}]
]

# Make parallel API calls (returns complete response objects)
responses = multithread_openai_chat_completions_call(
    client=client,
    messages=messages,
    model_name="gpt-3.5-turbo",
    max_workers=3
)

# Access response data
for i, response in enumerate(responses):
    if response is None:
        print(f"Request {i} failed")
        continue
        
    # Get the generated content
    content = response.choices[0].message.content
    print(f"Response {i+1}:\n{content}\n")
    
    # Access metadata like token usage
    print(f"Total tokens: {response.usage.total_tokens}")

Working with Response Objects

The function returns complete OpenAI ChatCompletion objects with all API response data:

# Access different parts of the response
response = responses[0]  # First response

# Message content
content = response.choices[0].message.content

# Token usage
completion_tokens = response.usage.completion_tokens
prompt_tokens = response.usage.prompt_tokens
total_tokens = response.usage.total_tokens

# Model information
model = response.model

# Other metadata
finish_reason = response.choices[0].finish_reason

Performance Benchmarking

The parallel implementation offers significant speedups:

  • Processing 10 prompts sequentially: ~20 seconds
  • With multithread_openai_chat_completions_call: ~3 seconds

🛠️ For Developers

Clone the repository to contribute:

git clone https://github.com/yourusername/rlhf-utils.git
cd rlhf-utils
pip install -e .

Run tests:

python -m unittest discover tests

📝 License

MIT

Metadata

Release files for rlhf-utils 0.1.1

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

Source distribution (sdist)

Source distribution for rlhf-utils 0.1.1
File Size Uploaded Provenance
rlhf_utils-0.1.1.tar.gz 7.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rlhf-utils 0.1.1
File Interpreter ABI Platform
rlhf_utils-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / rlhf_utils-0.1.1.tar.gz

Download URL rlhf_utils-0.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bfe0c3738a39f0080148b1e338be0e4a3b858a13bc33274f9dd73c72f1accf9c
BLAKE2b-256 checksum
How to use checksums
a7741720c298ba399b4beb09d52d133391bb27b06497e76147b5d61c6ac81566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / rlhf_utils-0.1.1-py3-none-any.whl

Download URL rlhf_utils-0.1.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00f3e028435a864f96d8853824340c834fd8bc6561fb0ea52e837584db6ae6b1
BLAKE2b-256 checksum
How to use checksums
05e3b1473f976ce3736f9722ebb1cd5d0cd9b3204072291865b2d4f8352089e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for rlhf-utils 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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