Skip to main content

Flexible LLM model initialization from YAML configuration.

Project description

Langfabric

Langfabric is a flexible Python framework for managing, instantiating, and caching Large Language Model (LLM) instances from YAML configuration files.
It supports OpenAI, Azure OpenAI, Groq, Ollama, AzureML, and other providers, making LLM orchestration and deployment easy, reproducible, and robust.


Features

  • Declarative YAML model configs (with secret support via seyaml)
  • Multiple provider support: OpenAI, Azure OpenAI, Groq, Ollama, AzureML, and more
  • Thread-safe model caching
  • Runtime overrides: temperature, max tokens, etc.
  • Parallel/preloaded model initialization
  • Automatic LangChain model rebuild

Installation

pip install langfabric

Or clone the repo and install locally:

git clone https://github.com/grakn/langfabric.git
cd langfabric
pip install -e .

Example: Model Configuration YAML

# models.yaml
- name: gpt4o
  provider: azure_openai
  model: gpt-4o
  deployment_name: gpt-4o-deployment
  api_key: !env AZURE_OPENAI_API_KEY
  endpoint: https://your-endpoint.openai.azure.com
  api_version: 2024-06-01-preview
  max_tokens: 4096
  temperature: 0.1
- name: ollama
  provider: ollama
  model: llama3
  max_tokens: 4096

Usage

1. Load model configs

from langfabric.loader import load_model_configs

model_configs = load_model_configs("./models.yaml")

2. Build and cache models

from langfabric.manager import ModelManager

manager = ModelManager(model_configs)
model = manager.load("gpt4o")  # Get Azure OpenAI GPT-4o model

3. Optional preload all models in parallel (multi-threaded)

manager.preload_all()  # Warms up cache in threads for all configs

4. Use runtime parameter overrides

custom_model = manager.load(
    "gpt4o",
    temperature=0.5,
    max_tokens=2048,
    json_response=True,
    streaming=False,
)

5. Get total amount loaded models

manager.active()

Advanced

Load model configs with secrets

from langfabric.loader import load_model_configs

secrets = {"api_key": "sk-..."}
model_configs = load_model_configs("./models/model.yaml", secrets)

Use !secrets pre-processor to point on secret names

# models.yaml
- name: gpt4o
  provider: azure_openai
  model: gpt-4o
  deployment_name: gpt-4o-deployment
  api_key: !secret api_key
  endpoint: https://your-endpoint.openai.azure.com
  api_version: 2024-06-01-preview
  max_tokens: 4096
  temperature: 0.1
- name: ollama
  provider: ollama
  model: llama3
  max_tokens: 4096

Load multiple model config files with secrets

from langfabric.loader import load_model_configs

secrets = {"api_key": "sk-..."}
model_configs = load_model_configs(["./models/models1.yaml", "./models/models2.yaml"], secrets)

Load multiple model config files from directories

from langfabric.loader import load_model_configs

secrets = {"api_key": "sk-..."}
model_configs = load_model_configs(["./models1/", "./models2/], secrets)

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

langfabric-0.1.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

langfabric-0.1.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file langfabric-0.1.5.tar.gz.

File metadata

  • Download URL: langfabric-0.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1015-azure

File hashes

Hashes for langfabric-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a20e7210d96c11c66b5499d00ff024f222cf056a19491b6f1f0ae4e98b012b50
MD5 2ddfd047f4d953dde394a847597601d5
BLAKE2b-256 eea5f1df12e1f02a30674a49ef6096570caf9e1b4b78af5e982bd8663c809e74

See more details on using hashes here.

File details

Details for the file langfabric-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: langfabric-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1015-azure

File hashes

Hashes for langfabric-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a42a7d30fe3a9dc64dc232924b5c9214f56c1c3847aed72227a612fb9fa39b38
MD5 9e8b8926f8a9ae534830945a2cb36281
BLAKE2b-256 e3291aab136e5722ea8ce89f583d6e412829f46e7266cf450b457339fae22459

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