Skip to main content

daaf — decision-as-a-function

Write a typed Python function with a docstring. Laya answers it, locally, in any of 100+ languages, in tens of milliseconds.

from enum import Enum, IntEnum
from typing import Literal
from daaf import decide

@decide
def is_scam(message: str) -> bool:
    """Is this message a scam trying to get money or credentials?"""

class Dept(Enum):
    billing = "invoices, payments, refunds"   # the value describes the option to the model
    support = "bugs, outages, login problems"
    sales = "pricing, buying a product"

@decide
def department(message: str) -> Dept:
    """Which department should handle this message?"""

is_scam("Votre colis est bloqué, payez 1,99 € ici")  # True
department("I was billed twice")                     # Dept.billing

The function body is never run: the docstring is the question, the return type is the set of possible answers.

Install

pip install daaf

The first call downloads the Laya model (a few hundred MB) and loads it, which takes a few seconds. Later calls are fast.

Return types

Annotation Result
bool True / False
Literal["a", "b", ...] one of the values (strings, ints…)
Enum subclass one member; string values describe each option, which helps the model
IntEnum subclass an ordered level (Laya's score type); member names are read as the level labels
class Urgency(IntEnum):
    not_urgent = 0
    soon = 1
    blocking = 2

@decide
def urgency(message: str) -> Urgency:
    """How urgent is this message?"""

urgency("Production is down!")  # Urgency.blocking

Arguments

  • One argument: its value is the text Laya reads.
  • Several arguments: Laya reads them as named fields, for example def urgent(subject: str, body: str) -> bool.

Many inputs at once

is_scam.batch(["message 1", "message 2", ...])         # one-argument function
urgent.batch([("subject", "body"), {"subject": "s", "body": "b"}])  # several arguments

Inputs share forward passes, which is much faster than a loop. Results come back in input order. batch_size= caps how many go through the model at once.

Options

@decide(min_confidence=0.8)      # raise daaf.Undecided below 80% instead of guessing
def is_scam(message: str) -> bool:
    """Is this message a scam trying to get money or credentials?"""

@decide(model="multilingual", max_len=8192)  # anything else goes to laya's Router.predict
def is_contract(document: str) -> bool:
    """Is this document a contract?"""

@decide(router=my_router)        # your own Router, or any object with Laya's .predict / .predict_batch
def is_spam(text: str) -> bool:
    """Is this message spam?"""

Undecided carries Laya's raw answer in .answer, so you can hand the case to a person or a larger model. In .batch(...), the first undecided input raises it.

is_scam.question shows the exact question sent to Laya.

Accuracy

daaf adds no intelligence: answers are as good as Laya's zero-shot checkpoints, which can make mistakes, especially on subtle questions. Test on your own examples, and use min_confidence where an error costs something. Clear docstrings and Enum descriptions help.

License

Apache-2.0, like Laya.

Tests

python test_daaf.py   # no model needed, a fake router stands in for Laya

Metadata

Release files for daaf 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for daaf 0.1.0
File Size Uploaded
daaf-0.1.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for daaf 0.1.0
File Interpreter ABI Platform
daaf-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / daaf-0.1.0.tar.gz

Download URL daaf-0.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5e3ccccd4106c35add14171b829dd85e32dcee34bc942886cb565f369c481514
BLAKE2b-256 checksum
How to use checksums
50942081c94adda2b577adbcc0073034083301ded62db4555936883e554da67e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / daaf-0.1.0-py3-none-any.whl

Download URL daaf-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bae980ff02634cf9f1e2e3242f52c9618edc7de275e3aea8c5a71411830fb82
BLAKE2b-256 checksum
How to use checksums
85e63f6d1c3f4fb6727ab956a1c5788266d69455c41a339eb8b075c9703354f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page