Skip to main content

A minimalist LLM modeling library

Project description

ModeLLM

PyPI version License

"Controlling complexity is the essence of computer programming."

Overview

ModeLLM is here to make your AI workflows dead simple to build and maintain.

Your Pydantic data models become the single source of truth.

Once the data models are well defined, you can create the workflow in a single line of code:

output: YourPydanticModel2 = input_data | YourPydanticModel1 | YourPydanticModel2

More Benefits

  • Prompts as Documentation: Keep prompts and code together by writing prompts in Pydantic docstrings, making them easy to understand for both humans and LLMs
  • Self-Documenting Workflows: Understand the entire pipeline at a glance through clear model definitions and model chains
  • Production-Ready Design: Built on battle-tested libraries like Pydantic and LangChain
  • Rapid Prototyping and Maintenance: Iterate quickly by swapping models and transformations with minimal code changes.

Installation

pip install modellm

ModeLLM requires Python 3.10+. All required dependencies (pydantic, langchain) will be installed automatically.

Currently, ModeLLM supports the following LangChain LLM providers:

  • ChatOpenAI
  • ChatAnthropic

To use them, you will need to add your OPENAI_API_KEY and/or ANTHROPIC_API_KEY to your environment variables.

Quick Start

Here's a minimal example to get you started:

from pydantic import BaseModel
from modellm import add_llm
from langchain_openai import ChatOpenAI

# Set up your LLM
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.7)

@add_llm(llm)
class Recipe(BaseModel):
    """
    A cooking recipe.
    """
    name: str
    ingredients: list[str]
    instructions: list[str]
    cooking_time: str

# Generate a recipe
text = "Fish and chips"
recipe = text | Recipe
print(recipe)

Detailed Usage

ModeLLM supports complex transformation chains and multiple LLM providers:

# Continuing from the previous example

claude_llm = ChatAnthropic(model="claude-3-5-sonnet-20240620", temperature=0.2)

@add_llm(claude_llm) # Add a different LLM to this model
class SimplifiedRecipe(Recipe):
    """Simplified recipe with more basic, everyday ingredients"""
    pass

class HealthyRecipe(Recipe): # OpenAI LLM is inherited from the Recipe
    """Recipe with minimal calories and maximal nutrients.""" 
    pass

# Chain transformations
healthy_simple_recipe: Recipe = recipe | HealthyRecipe | SimplifiedRecipe
print(healthy_simple_recipe)

Contributing

Contributions are welcome! Feel free to submit a pull request!

For major changes, please open an issue first to discuss what you would like to change.

Acknowledgments

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

modellm-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

modellm-0.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file modellm-0.1.2.tar.gz.

File metadata

  • Download URL: modellm-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for modellm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c79ff9ce66b9c9b14bd6ac2334ef30f1ec30fb98dd73f42ecc61b8b24161483c
MD5 0da678b0596fce5836e9e6aa31770350
BLAKE2b-256 780b81a4adfb4f8ca94b8f3dee5d05a2d6f02730ae598c403008c5152c85799c

See more details on using hashes here.

File details

Details for the file modellm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: modellm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for modellm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d67e5861d68798c3fb37728d2462039be0e02eb9958fb4321c2cad1c795f52a
MD5 5b0b862c467845021bf90bdd08046b9b
BLAKE2b-256 5f5ae744cc965e653bbf6b4bd6c9b6d91bfb236db5feb5a3f951de45499d613c

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