Skip to main content

Loads a Langchain LLM by model name as a string.

Project description

pypi testing badge black 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-4o")
result = llm.invoke("Write me a haiku about love")

llm = llmloader.load("claude-3-5-sonnet-20240620")
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")

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-5.2
llmloader "Write me a haiku about love" --model claude-sonnet-4-5-20250929
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

Azure

To use custom models deployed with Azure OpenAI, you need to set the following environment variables:

  • CUSTOM_API_KEY: Your Azure API key.

  • CUSTOM_ENDPOINT: The endpoint URL for your Azure AI service.

--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 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)

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

llmloader-0.1.9.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

llmloader-0.1.9-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file llmloader-0.1.9.tar.gz.

File metadata

  • Download URL: llmloader-0.1.9.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.1 Darwin/24.6.0

File hashes

Hashes for llmloader-0.1.9.tar.gz
Algorithm Hash digest
SHA256 6baa0e00777e9ee8a24664d5af0bc6c9b943e01a41bda3328f2a36cc96417090
MD5 31ee06b0cda90f50985126ade1c6ba4c
BLAKE2b-256 95b335c8d639a7dffcf797d46c23c7ae92b93e22555eb0848fa5811994d8beb7

See more details on using hashes here.

File details

Details for the file llmloader-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: llmloader-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.1 Darwin/24.6.0

File hashes

Hashes for llmloader-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e7671a47a57eae5f6323662376d2fb1ea8bb43972a753ea87bc355e5ea0d4388
MD5 eac81ae320627e5bfcb42675889cc92c
BLAKE2b-256 211d02f2cb30c0521d30248699e078a08404561569c8a625f05c53cdb34b0e04

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