Skip to main content

Large Language Model Batch Operations

Project description

LLMbo - Large Language model batch operations

AWS Bedrock offers powerful capabilities for running batch inference jobs with large language models. However, orchestrating these jobs, managing inputs and outputs, and ensuring consistent result structures can be arduous. LLMbo aims to solve these problems by providing an intuitive, Pythonic interface for Bedrock batch operations.

Additionally, it provides a method of using batch inference for structured responses, taking inspiration from the likes of instructor, mirascope and pydanticai. You provide a model output as a pydantic model and llmbo creates takes care of the rest.

See the AWS documentation for models that support batch inference.

Currently the library has full support (including StructuredBatchInference) for Anthropic and Mistral models. Other models may be supported through the default adapter, or you can write and register your own.

Prerequisites

  • A .env file with an entry for AWS_PROFILE=. This profile should have sufficient permissions to create and schedule a batch inference job. See the AWS instructions
  • A service role with the required permissions to execute the job.,
  • A s3 bucket to store the input and outputs for the job. S3 buckets must exists in the same region as you execute the job. This is a limitation of AWS batch inference rather that the package.
    • Inputs will be written to f{s3_bucket}/input/{job_name}.jsonl
    • Outputs will be written to f{s3_bucket}/output/{job_id}/{job_name}.jsonl.out and f{s3_bucket}/output/{job_id}/manifest.json.out

Install

pip install llmbo-bedrock

Getting started

Here's a quick example of how to use LLMbo:

BatchInferer

from llmbo import BatchInferer, ModelInput

bi = BatchInferer(
    model_name="anthropic.claude-v2",
    bucket_name="my-inference-bucket",
    region="us-east-1",
    job_name="example-batch-job",
    role_arn="arn:aws:iam::123456789012:role/BedrockBatchRole"
)

# Prepare your inputs using the ModelInput class, you also need to include an id 
# input Dict[job_id: ModelInput ]

inputs = {
    f"{i:03}": ModelInput(
        messages=[{"role": "user", "content": f"Question {i}"}]
    ) for i in range(100)
}


# Run the batch job, this prepares, uploads, creates the job, monitors the progress 
# and downloads the results
results = bi.auto(inputs)

StructuredInferer

For structured inference, simply define a Pydantic model and use StructuredBatchInferer:

from pydantic import BaseModel
from llmbo import StructuredBatchInferer

class ResponseSchema(BaseModel):
    answer: str
    confidence: float

sbi = StructuredBatchInferer(
    output_model=ResponseSchema,
    model_name="anthropic.claude-v2",
    # ... other parameters
)

# The results will be validated against ResponseSchema
structured_results = sbi.auto(inputs)

For more detailed examples see the followingin llmbo.py:

  • examples/batch_inference_example.py: for an example of free text response
  • examples/structured_batch_inference_example.py: for an example of structured response ala instructor

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

llmbo_bedrock-0.2.3.tar.gz (106.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llmbo_bedrock-0.2.3-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file llmbo_bedrock-0.2.3.tar.gz.

File metadata

  • Download URL: llmbo_bedrock-0.2.3.tar.gz
  • Upload date:
  • Size: 106.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llmbo_bedrock-0.2.3.tar.gz
Algorithm Hash digest
SHA256 44c76dc3f57b711129e70007ddfd15b66a7c6d07039230480ecbb7440d717f2c
MD5 816b7757a2577f27048f7d666cf1b1dd
BLAKE2b-256 abecd08cad60a57d92edd8da2f01e97f8228486e4a1954e42d7d429cfa1b221f

See more details on using hashes here.

File details

Details for the file llmbo_bedrock-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: llmbo_bedrock-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llmbo_bedrock-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c736c39c4fc4e268590045aa4efdf66f9d303d9b2cda3af1f1d191e58851c19a
MD5 eefaa9b8af66f87c1962a4385bdead56
BLAKE2b-256 cc0b3e7b015315b27eb6d93ad9d97dbcfedc773080dfcee4c58c5e905e4f23c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page