Skip to main content

Model Library for vals.ai

Project description

Model Library

Open-source model library for interacting with a variety of LLM providers. Originally developed for internal use at vals.ai benchmarks. This tool is designed to be a general-purpose solution for any project requiring a unified interface for multiple model providers.

pip install model-library

Note: This library is undergoing rapid development. Expect breaking changes.

Features

Providers

  • AI21 Labs
  • Alibaba
  • Amazon Bedrock
  • Anthropic
  • Azure OpenAI
  • Cohere
  • DeepSeek
  • Fireworks
  • Google Gemini
  • Mistral
  • Perplexity
  • Together AI
  • OpenAI
  • X AI
  • ZhipuAI (zai)

Run python -m scripts.browse_models to browse the model registry.

Supported Input

  • Images
  • Files
  • Tools (with full history)
  • Batch
  • Reasoning
  • Custom Parameters

Usage

Here is a basic example of how to query a model:

import asyncio
from model_library.registry_utils import get_registry_model

async def main():
    # Load a model from the registry
    model = get_registry_model("openai/gemini-2.5-flash")

    # Query the model with a simple text input
    response = await model.query("What is QSBS? Explain your thinking in detail and make it concise.")

    # Logger automatically logs the response

if __name__ == "__main__":
    asyncio.run(main())

The model registry holds model attributes, ex. reasoning, file support, tool support, max tokens. You may also use models not included in the registry.

model = get_raw_model("openai/gpt-3.5-turbo", config=LLMConfig(max_tokens=1000))

Environment Setup

The model library will use:

  • Environment varibles for API keys

    • OPENAI_API_KEY
    • ANTHROPIC_API_KEY
    • GOOGLE_API_KEY
    • ...
  • Variables set through model_library.settings

from model_library import model_library_settings

model_library_settings.set(MY_KEY="my-key")

System Prompt

python -m examples.basics
await model.query(
    [TextInput(text="Hello, how are you?")],
    system_prompt="You are a pirate, answer in the speaking style of a pirate. Keeps responses under 10 words",
)

Image/File Input

Supports base64, url, and file id (file upload)

python -m examples.images
red_image_content = b"..."

await model.query(
    [
        TextInput(text="What color is the image?"),
        FileWithBase64(
            type="image",
            name="red_image.png",
            mime="png",
            base64=base64.b64encode(red_image_content).decode("utf-8"),
        ),
    ]
)

Tool Calls

python -m examples.tool_calls
tools = [
    ToolDefinition(
        name="get_weather",
        body=ToolBody(
            name="get_weather",
            description="Get current temperature in a given location",
            properties={
                "location": {
                    "type": "string",
                    "description": "City and country e.g. Bogotá, Colombia",
                },
            },
            required=["location"],
        ),
    )
]

output1 = await model.query(
    [TextInput(text="What is the weather in SF right now?")],
    tools=tools,
)

output2 = await model.query(
    [
        # assume one tool call was made
        ToolResult(tool_call=output1.tool_calls[0], result="25C"),
        TextInput(
            text="Also, includes some weird emojies in your answer (at least 8 of them)"
        ),
    ],
    history=output1.history,
    tools=tools,

Full examples

You can run make examples (default models) or make example <model> to run all examples.

python -m examples.basics

python -m examples.images

python -m examples.files

python -m examples.tool_calls

python -m examples.embeddings

python -m examples.advanced.batch

python -m examples.advanced.custom_retrier

python -m examples.advanced.stress

python -m examples.advanced.deep_research

Architecture

Designed to abstract different LLM providers:

  • LLM Base Class: An abstract base class that defines a common interface for all models
  • Model Registry: A central registry that loads model configurations from YAML files
  • Provider-Specific Implementations: Concrete classes for each provider (e.g., OpenAI, Google, Anthropic) that inherit from the LLM base class
  • Data Models: A set of pydantic models for representing various input and output types, such as TextInput, FileWithBase64, ToolDefinition, and ToolResult. This ensures code is model agnostic, and easy to maintain.
  • Retry Logic: A set of retry strategies for handling errors and rate limiting

Contributing

Setup

We use uv for dependency management. A Makefile is provided to help with development.

To install dependencies, run:

make install

Makefile commands

make install          Install dependencies"
make test             Run unit tests"
make test-integration Run integration tests (requires API keys)"
make test-all         Run all tests (unit + integration)"
make style            Lint & Format"
make style-check      Check style"
make typecheck        Typecheck"
make config           Generate all_models.json"
make run-models       Run all models"
make examples         Run all examples"
make examples <model> Run all examples with specified model"
make browse-models    Browse all models"

Testing

Unit Tests

Unit tests do not require API keys

make test-unit

Integration Tests

Make sure you have API keys configured

make test-integration

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

model_library-0.1.0.tar.gz (227.9 kB view details)

Uploaded Source

Built Distribution

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

model_library-0.1.0-py3-none-any.whl (117.7 kB view details)

Uploaded Python 3

File details

Details for the file model_library-0.1.0.tar.gz.

File metadata

  • Download URL: model_library-0.1.0.tar.gz
  • Upload date:
  • Size: 227.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for model_library-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6c8d277f18843fcb158ac4cf45d813fb598b49adc2ae5d5a437eb11a7cf8a64d
MD5 c953eb2149b9c4d594106266ed1857ff
BLAKE2b-256 9d0844951801b95243a3d54775eba7ea53ff5e7cc3b609dfccdf0aa082dbace2

See more details on using hashes here.

Provenance

The following attestation bundles were made for model_library-0.1.0.tar.gz:

Publisher: publish.yml on vals-ai/model-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file model_library-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: model_library-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 117.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for model_library-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 511f830e4b5468c5c1e9b21d6de02d202491ed6168c40c40ae93e9d56bb58df5
MD5 40768829a588d1bbdbf67ae68097e9e7
BLAKE2b-256 5a6de3229fc69743c22a5b2758851cbfccf8734da5fe3613af3d6c2000f34ab4

See more details on using hashes here.

Provenance

The following attestation bundles were made for model_library-0.1.0-py3-none-any.whl:

Publisher: publish.yml on vals-ai/model-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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