Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
124 lines (114 loc) · 4.03 KB
/
Copy path__init__.py
File metadata and controls
124 lines (114 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Laya: Fast, non-autoregressive System 1 decision engine with calibrated probabilities."""
from .email import clean_email_body, email_state
from .hooks import AsyncHook, BaseHook, Hook, PredictContext, PredictHook
from .lang import analyse as detect_language
from .lang import detect_script, is_english
from .presets import (
email_questions,
guard_questions,
moderation_questions,
router_questions,
triage_questions,
)
from .router import DEFAULT_MODELS, RouteDecision, Router
from .structured import DecisionResult, decide, decide_batch
__version__ = "0.3.23"
# Routing, language detection and email cleaning are pure Python. The torch-backed names are
# resolved lazily so that `import laya` -- and therefore `from laya import Router` or
# `from laya.lang import detect_script` -- does not pay torch's import time and memory.
_LAZY_ATTRS = {
# stdlib-only module, but keep it lazy so `import laya` does not pull in hashlib
"PINNED_REVISIONS": (".revisions", "PINNED_REVISIONS"),
"Agent": (".agent", "Agent"),
"RLAgent": (".agent", "RLAgent"),
"load": (".agent", "load"),
"fit_temperatures": (".calibrate", "fit_temperatures"),
"fit_one_temperature": (".calibrate", "fit_one_temperature"),
"fit_temperature_map": (".calibrate", "fit_temperature_map"),
"proper_reward": (".common", "proper_reward"),
"td_lambda_targets": (".common", "td_lambda_targets"),
"ece_score": (".common", "ece_score"),
"answer_confidence": (".common", "answer_confidence"),
"confidence_from_probs": (".common", "confidence_from_probs"),
"check_min_confidence": (".confidence", "check_min_confidence"),
"flag_low_confidence": (".confidence", "flag_low_confidence"),
"apply_confidence_gate": (".confidence", "apply_confidence_gate"),
"GATE_STATES": (".confidence", "GATE_STATES"),
"render_options": (".common", "render_options"),
"QTYPES": (".common", "QTYPES"),
"QTYPE_NAMES": (".common", "QTYPE_NAMES"),
"shortlist_choice": (".shortlist", "shortlist_choice"),
"predict_shortlist": (".shortlist", "predict_shortlist"),
"embed_fn_from_agent": (".shortlist", "embed_fn_from_agent"),
"cached_embed_fn": (".shortlist", "cached_embed_fn"),
"LayaRouter": (".integrations", "LayaRouter"),
"LayaGuardrail": (".integrations", "LayaGuardrail"),
"LayaGuardrailError": (".integrations", "LayaGuardrailError"),
"LayaTriage": (".integrations", "LayaTriage"),
"LayaEvaluator": (".integrations", "LayaEvaluator"),
"LayaDecision": (".integrations", "LayaDecision"),
}
def __getattr__(name):
try:
module_name, attr = _LAZY_ATTRS[name]
except KeyError:
raise AttributeError("module %r has no attribute %r" % (__name__, name)) from None
import importlib
value = getattr(importlib.import_module(module_name, __name__), attr)
globals()[name] = value # cache: __getattr__ runs at most once per name
return value
def __dir__():
return sorted(list(globals()) + list(_LAZY_ATTRS))
__all__ = [
"Agent",
"RLAgent",
"load",
"fit_temperatures",
"fit_one_temperature",
"fit_temperature_map",
"RouteDecision",
"DEFAULT_MODELS",
"shortlist_choice",
"predict_shortlist",
"embed_fn_from_agent",
"cached_embed_fn",
"detect_language",
"detect_script",
"is_english",
"clean_email_body",
"email_questions",
"email_state",
"guard_questions",
"moderation_questions",
"router_questions",
"triage_questions",
"proper_reward",
"td_lambda_targets",
"ece_score",
"answer_confidence",
"confidence_from_probs",
"check_min_confidence",
"flag_low_confidence",
"apply_confidence_gate",
"GATE_STATES",
"render_options",
"QTYPES",
"QTYPE_NAMES",
"LayaRouter",
"LayaGuardrail",
"LayaGuardrailError",
"LayaTriage",
"LayaEvaluator",
"LayaDecision",
"PredictContext",
"PredictHook",
"Hook",
"BaseHook",
"AsyncHook",
"decide",
"decide_batch",
"DecisionResult",
"PINNED_REVISIONS",
"__version__",
]