A minimalist LLM modeling library
Project description
ModeLLM
"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.9+. 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
- Built on top of Pydantic and LangChain
- Inspired by the Eric S. Raymond's Art of Unix Programming
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modellm-0.1.1.tar.gz.
File metadata
- Download URL: modellm-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
094e3ff6010c8e011192a59826f9b31e286fa0c83e654d325548fd46ae368d50
|
|
| MD5 |
b72fbe9de40e4e6ae330eaa3f0c01ebc
|
|
| BLAKE2b-256 |
aadd3e47ce35f77bf30acbec2e8a3466b28442accfd74a642cd0341d85cbd5e3
|
File details
Details for the file modellm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: modellm-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9368ef8cc20647add16c351080137e35b1a42d50663b1ba02da6dbd8aeeff680
|
|
| MD5 |
112bd4d9e746bcb150fcd298587fa0ca
|
|
| BLAKE2b-256 |
021671f86a17ca76ee5b92b61f25776c85fa9324ebd83d5a1172e9e5474262d4
|