Skip to main content

llmloader

pypi testing badge black badge coverage badge

Loads a Langchain LLM by model name as a string.

Installation

pip install llmloader

Or install from GitHub directly:

pip install git+https://github.com/rbturnbull/llmloader.git

Usage

Load the LLM with the llmloader.load function. e.g.

import llmloader

llm = llmloader.load("gpt-6-luna")
result = llm.invoke("Write me a haiku about love")

llm = llmloader.load("claude-sonnet-5")
result = llm.invoke("Write me a haiku about love")

llm = llmloader.load("grok-4-latest")
result = llm.invoke("Write me a haiku about love")

llm = llmloader.load("mistral-small-latest")
result = llm.invoke("Write me a haiku about love")

llm = llmloader.load("meta-llama/Llama-3.3-70B-Instruct")
result = llm.invoke("Write me a haiku about love")

To pass an image, it needs to be base64 encoded, and reformatted with LLMWrapper.

import base64
from langchain_core.messages import HumanMessage
from llmloader.wrappers import LLMWrapper

with open("path/to/image.png", "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode("utf-8")

formatted_image = LLMWrapper.format(llm, "image", {
    "data": encoded_string,
    "mime_type": "image/png"
})

message = HumanMessage(content=[{"type": "text", "text": "Here is an image for you:"}, formatted_image])

result = llm.invoke(message)

Get the token usage

from llmloader.wrappers import LLMWrapper

result = llm.invoke(message)

count = LLMWrapper.get_token_count(result, record="optional_path/to/record.yaml")

CLI

You can test out prompts and models on the command line. Make sure you have your API keys set in your environment or add the key with the --api-key flag.

llmloader "Write me a haiku about love" --model gpt-5-mini
llmloader "Write me a haiku about love" --model gpt-6-luna
llmloader "Write me a haiku about love" --model claude-sonnet-5
llmloader "Write me a haiku about love" --model grok-4-latest
llmloader "Write me a haiku about love" --model mistral-small-latest
llmloader "Write me a haiku about love" --model gemini-3-pro-preview
# Using OpenRouter
llmloader "Write me a haiku about love" --model openai/gpt-5-mini
# Local deployment models
llmloader "Write me a haiku about love" --model meta-llama/Meta-Llama-3-8B-Instruct
llmloader "Write me a haiku about love" --model meta-llama/Llama-3.3-70B-Instruct
llmloader --help

Environment Variables

You can pass an API key for the model provider using the command line flag --api-key, kwarg api_key=..., or by setting the appropriate environment variable as described below.

Model Provider

Environment Variable

OpenAI

OPENAI_API_KEY

Anthropic

ANTHROPIC_API_KEY

Mistral

MISTRAL_API_KEY

XAI

XAI_API_KEY

OpenRouter

OPENROUTER_API_KEY

Google

GOOGLE_API_KEY

OpenRouter

Model names containing a / (e.g. openai/gpt-5-mini) are loaded through OpenRouter. Set OPENROUTER_API_KEY or pass --api-key. No endpoint is needed.

Azure and Custom Endpoints

To use custom models deployed with Azure OpenAI or another OpenAI-compatible service, you need to set the following environment variables:

  • CUSTOM_API_KEY: Your Azure or custom service API key. This takes precedence over OPENROUTER_API_KEY.

  • CUSTOM_ENDPOINT: The endpoint URL for your Azure AI or custom service. OPENROUTER_API_KEY is never sent to a custom endpoint.

Alternatively, you can pass the endpoint URL directly using the --endpoint flag.

--model should match the deployment name in your Azure AI resource.

Note:

  • If llmloader detects the OPENAI_API_KEY environment variable, it will use the OpenAI API by default if a valid model name is provided and CUSTOM_ENDPOINT is not set.

  • If both CUSTOM_API_KEY and CUSTOM_ENDPOINT are set, llmloader will use the Azure or OpenRouter service.

  • CUSTOM_ENDPOINT should be the URL ending with /models, e.g. https://your-resource-name.openai.azure.com/models

Testing

Endpoint Manual Testing

test_manual.py contains tests for models that require API keys. You can run these tests manually after setting the appropriate environment variables.

Once the environment variables are set, you can run the tests with:

pytest -m manual

To specify a particular test, use:

pytest -m manual tests/test_manual.py::test_name

Credit

  • Robert Turnbull (Melbourne Data Analytics Platform, University of Melbourne)

  • James Quang (Melbourne Data Analytics Platform, University of Melbourne)

Metadata

Release files for llmloader 0.1.10

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

Source distribution (sdist)

Source distribution for llmloader 0.1.10
File Size Uploaded
llmloader-0.1.10.tar.gz 9.9 kB Details

Built distribution (wheel)

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

Total release size: 23.8 kB

Release files / llmloader-0.1.10.tar.gz

Download URL llmloader-0.1.10.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2ff6f4f0913bf04a200d5100b0f0aa43b752204ab8d4925ecf2ac0f0ca11d690
BLAKE2b-256 checksum
How to use checksums
8267cbd4a9d0a22d36b1f229e9b3c2ed468ee892ebdf99af6d5e1cfe9b064548
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.1 Darwin/25.6.0

Release files / llmloader-0.1.10-py3-none-any.whl

Download URL llmloader-0.1.10-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6eeeb2ea1c2c431b058e705eb11068ac6d3be4f2a3fec57255c35c0e30e8fcb
BLAKE2b-256 checksum
How to use checksums
c2fc9c1c88adde75fc33e9f301b3c732b89bafa980fb0233b38d0bc12f775ed9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.1 Darwin/25.6.0

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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