Skip to main content

lightweight library for building Trigger-Action programs with llm

Project description

LLM Trigger-Action Programs

llm-tap is a lightweight and extensible library for building Trigger-Action programs with Large Language Models (LLMs).

Quickstart

Let's take an example to generate a workflow based on the following user query:

"When the electricity price is below $0.4/ kWh and my Tesla is plugged, turn on charging."

OpenAI

import os
from llm_tap import llm
from llm_tap.models import Workflow

system_prompt = """You are an automation assistant.

- Design a workflow to answer user's query for an automation.
- Be sure to consider all branches when evaluating conditionals.
- Ensure safe defaults.

"""
prompt = "When the electricity price is below $0.4/ kWh and my Tesla is plugged, turn on charging."

with llm.HTTP(
    base_url="https://api.openai.com/v1/chat/completions",
    api_key=os.getenv('OPENAI_API_KEY'),
    model="gpt-4.1-nano",
) as parser:
    workflow = parser.parse(data_class=Workflow, prompt=prompt, system_prompt=system_prompt)
    print(workflow)

When called, this displays:

Workflow(
    name="Electricity Price and Tesla Charging Workflow",
    description="Automates Tesla charging based on electricity prices.",
    triggers=[Trigger(description="Electricity price updates")],
    nodes=[
        Node(
            name="Check Electricity Price and Tesla Plug Status",
            condition_sets=[
                ConditionSet(
                    conditions=[
                        Condition(
                            description="Electricity price is below $0.4/kWh"
                        )
                    ],
                    operator="AND",
                ),
                ConditionSet(
                    conditions=[Condition(description="Tesla is plugged in")],
                    operator="AND",
                ),
            ],
            branches=[
                Branch(
                    conditions_value=True,
                    actions=[Action(description="Turn on Tesla charging")],
                ),
                Branch(
                    conditions_value=False,
                    actions=[Action(description="Do nothing")],
                ),
            ],
        )
    ],
)

GGUF Open weights models with llama.cpp

import os
from llm_tap import llm
from llm_tap.models import Workflow

system_prompt = """You are an automation assistant.

- Design a workflow to answer user's query for an automation.
- Be sure to consider all branches when evaluating conditionals.
- Ensure safe defaults.

"""
prompt = "When the electricity price is below $0.4/ kWh and my Tesla is plugged, turn on charging."


#: model should be the path to a GGUF model
model="~/.cache/py-llm-core/models/qwen2.5-1.5b"
# model="~/.cache/py-llm-core/models/llama-3.2-3b"
# model="~/.cache/py-llm-core/models/llama-3.1-8b"
# model="~/.cache/py-llm-core/models/qwen3-4b"
# model="~/.cache/py-llm-core/models/mistral-7b"

with llm.LLamaCPP(model=model) as parser:
    workflow = parser.parse(data_class=Workflow, prompt=prompt)
    print(workflow)

When called, this displays:

Workflow(
    name="Turn on charging",
    description="Turn on charging when the electricity price is below $0.4/ kWh and my Tesla is plugged.",
    triggers=[
        Trigger(
            description="Electricity price is below $0.4/ kWh and my Tesla is plugged."
        )
    ],
    nodes=[
        Node(
            name="Turn on charging",
            condition_sets=[
                ConditionSet(
                    conditions=[
                        Condition(
                            description="Electricity price is below $0.4/ kWh"
                        ),
                        Condition(description="My Tesla is plugged"),
                    ],
                    operator="AND",
                )
            ],
            branches=[
                Branch(
                    conditions_value=True,
                    actions=[Action(description="Turn on charging")],
                )
            ],
        )
    ],
)

Documentation - Tutorial

Currently work in progress here:

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

llm_tap-0.0.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

llm_tap-0.0.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file llm_tap-0.0.2.tar.gz.

File metadata

  • Download URL: llm_tap-0.0.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for llm_tap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 709a6efbd68001c22f8bf24da6504899b69965142e70ac07773fe8d364a96889
MD5 802844a6283506fdc31bac33a0fa3404
BLAKE2b-256 5765b71776ac0ae708283f0ecbb5638b40e2c8689d5ed1f706ca20571822b5d2

See more details on using hashes here.

File details

Details for the file llm_tap-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: llm_tap-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for llm_tap-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e1f5f7393c56c65ce02388793a4fcb52740a6103846e2ceb36a32e9c07aa1a48
MD5 51ccfc16deaa1ffac7946b05ead66d7b
BLAKE2b-256 7ccdf4dd70a0fb56b951bc19e974612f5d09137a0b89193a15c3a9123eba9e26

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