Skip to main content

📦 LLM Batch

A command-line tool for running and managing batch inference jobs with LLM providers (OpenAI and Anthropic).

Installation

uv is a fast Python package installer and resolver.

uv pip install llm-batch

Using pip

pip install llm-batch

Usage

The llm-batch tool offers several commands to create, run, and parse batches of LLM inference requests.

Available Commands

  • create: Create a batch of requests from a CSV or JSON file
  • run: Run a batch of requests through Ollama (requires Ollama installation with the model specified in your config)
  • run-anthropic: Run a batch of Anthropic requests directly. Requires an ANTHROPIC_API_KEY environmental variable.
  • parse: Parse and convert batch results to CSV

Creating a Batch

llm-batch create INPUT_PATH CONFIG_FILE OUTPUT_PATH
  • INPUT_PATH: Path to a CSV or JSON file containing questions
  • CONFIG_FILE: Path to the YAML config file (see configuration section)
  • OUTPUT_PATH: Path to save the output JSONL file

The input CSV file should have at least two columns:

  • question_id: A unique identifier for the question
  • question: The text of the question
  • image_path (optional): Path to an image file for multimodal models

Running a Batch

llm-batch run FILE_PATH [--interval INTEGER] [--output-dir DIRECTORY] [--verbose]
  • FILE_PATH: Path to the JSONL file containing the batch
  • --interval: Number of responses to save at once (default: 100)
  • --output-dir: Directory to save the output (default: current directory)
  • --verbose: Enable verbose logging

This command processes the batch requests through Ollama and saves the responses to a JSONL file.

Important: This command requires:

  1. Ollama to be installed on your system
  2. The model specified in your config to be downloaded in Ollama ollama pull <model_name>

Running Anthropic Batches Directly

llm-batch run-anthropic FILE_PATH
  • FILE_PATH: Path to the JSONL file containing Anthropic requests

This command uses Anthropic's native batch API.

Parsing Results

llm-batch parse INPUT_PATH [OUTPUT_DIR]
  • INPUT_PATH: Path to the JSONL file containing batch responses
  • OUTPUT_DIR: Directory to save the parsed CSV file (default: current directory)

This command parses the batch responses and converts them to a CSV file.

Configuration

The tool uses a YAML configuration file to specify the parameters for creating batch requests. Here's an explanation of the configuration options:

# Format of the batch requests
format: openai  # Options: "openai" or "anthropic"

# Number of responses to generate per question
# n_answers: 5    # Uncomment to set a different value (default: 1)

# Generation parameters
params:
  model: gemma2:2b         # Model to use for inference
  temperature: 0.7         # Controls randomness
  max_tokens: 8196         # Maximum tokens to generate

  # Optional parameters
  # top_p: 0.9              # Nucleus sampling parameter
  # frequency_penalty: 0.0  # Penalize repeated tokens
  # presence_penalty: 0.0   # Penalize tokens already present

# System message to include in the prompt (optional)
# system_message: |
#   You are a helpful AI assistant.

# JSON Schema for structured output (optional)
# json_schema:
#   name: response_model        # Name of the schema
#   schema:                     # JSON schema definition
#     type: object
#     properties:
#       thinking:
#         type: string
#       answer:
#         type: string
#     required:
#       - thinking
#       - answer
#     additionalProperties: false
#   strict: true               # Enforce strict schema 

Important Configuration Notes

  • format: Must be either "openai" or "anthropic" based on which provider you're using
  • params: Contains model parameters like model, temperature, and token limits
  • json_schema: Optional JSON schema for structured responses (useful for parsing)

Environment Variables

The tool requires API keys for the LLM providers you're using:

# For OpenAI
export OPENAI_API_KEY=your_openai_api_key

# For Anthropic
export ANTHROPIC_API_KEY=your_anthropic_api_key

You can also use a .env file in your project directory.

Example Workflow

  1. Prepare a CSV file with questions (questions.csv)
  2. Create a config file (config.yaml)
  3. Create a batch file:
    llm-batch create questions.csv config.yaml batches/my_batch.jsonl
    
  4. Run the batch:
    # Make sure Ollama is installed and the model is downloaded
    ollama pull <model_name>
    
    # Run the batch
    llm-batch run batches/my_batch.jsonl --output-dir results
    
  5. Parse the results:
    llm-batch parse results/batch_*.jsonl results
    

License

See the LICENSE file for details.

Metadata

Release files for llm-batch 0.1.8

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

Source distribution (sdist)

Source distribution for llm-batch 0.1.8
File Size Uploaded Provenance
llm_batch-0.1.8.tar.gz 2.3 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-batch 0.1.8
File Interpreter ABI Platform
llm_batch-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 2.3 MB

Release files / llm_batch-0.1.8.tar.gz

Download URL llm_batch-0.1.8.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
23118f8e426c4cd9d87ff22d7ddaad2ae060c94b85eee46577ae43f4b936becf
BLAKE2b-256 checksum
How to use checksums
d1002459f2342fbfb0e44d3e47670198e02f3015b666ffd12410fd46e65d3945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Release files / llm_batch-0.1.8-py3-none-any.whl

Download URL llm_batch-0.1.8-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4404ff3582175e0eb2e805904941dff51758ade90d7b94d5f249f1531b8ea2a
BLAKE2b-256 checksum
How to use checksums
3aa77f6e2fe8734b8689f0f5a3d236b2a5298bf60199f0b8a903d0e1e6fa0c9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Security for llm-batch 0.1.8

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.8 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