aid-runtime-python 0.1.90__py3-none-any.whl → 0.1.91__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aid_runtime/__init__.py +1 -1
- aid_runtime/agents/ir.py +5 -4
- aid_runtime/evals/__init__.py +2 -0
- aid_runtime/evals/metrics.py +90 -1
- {aid_runtime_python-0.1.90.dist-info → aid_runtime_python-0.1.91.dist-info}/METADATA +1 -1
- {aid_runtime_python-0.1.90.dist-info → aid_runtime_python-0.1.91.dist-info}/RECORD +8 -8
- {aid_runtime_python-0.1.90.dist-info → aid_runtime_python-0.1.91.dist-info}/WHEEL +0 -0
- {aid_runtime_python-0.1.90.dist-info → aid_runtime_python-0.1.91.dist-info}/top_level.txt +0 -0
aid_runtime/__init__.py
CHANGED
aid_runtime/agents/ir.py
CHANGED
|
@@ -86,11 +86,12 @@ class ToolSpec:
|
|
|
86
86
|
|
|
87
87
|
@dataclass(frozen=True, slots=True)
|
|
88
88
|
class DecisionDefinition:
|
|
89
|
-
"""A
|
|
89
|
+
"""A decision resolved from the IR's ``decisions`` collection.
|
|
90
90
|
|
|
91
|
-
Only the fields
|
|
92
|
-
question, and the labels
|
|
93
|
-
|
|
91
|
+
Only the fields a runtime needs are here: the model that answers, the
|
|
92
|
+
question, and the ordered labels or levels. A guardrail uses a ``choice``
|
|
93
|
+
decision's labels through an ``on_decision`` map; an eval's ``DecisionScore``
|
|
94
|
+
uses a ``score`` decision's criteria, where the position is the score.
|
|
94
95
|
"""
|
|
95
96
|
|
|
96
97
|
id: str
|
aid_runtime/evals/__init__.py
CHANGED
|
@@ -17,6 +17,7 @@ from aid_runtime.evals.gate import (
|
|
|
17
17
|
)
|
|
18
18
|
from aid_runtime.evals.metrics import (
|
|
19
19
|
AssertMetric,
|
|
20
|
+
DecisionScore,
|
|
20
21
|
ExactMatch,
|
|
21
22
|
JsonSchemaValid,
|
|
22
23
|
JudgeVerdict,
|
|
@@ -44,6 +45,7 @@ __all__ = [
|
|
|
44
45
|
"CaseOutcome",
|
|
45
46
|
"Dataset",
|
|
46
47
|
"DatasetRun",
|
|
48
|
+
"DecisionScore",
|
|
47
49
|
"EvalBaseline",
|
|
48
50
|
"EvalCase",
|
|
49
51
|
"EvalRun",
|
aid_runtime/evals/metrics.py
CHANGED
|
@@ -15,13 +15,17 @@ from typing import Any, Protocol, runtime_checkable
|
|
|
15
15
|
|
|
16
16
|
from pydantic import BaseModel, ConfigDict, Field
|
|
17
17
|
|
|
18
|
-
from aid_runtime.
|
|
18
|
+
from aid_runtime.agents.guardrails import DecisionAsker
|
|
19
|
+
from aid_runtime.agents.ir import DecisionDefinition
|
|
20
|
+
from aid_runtime.decisions import DecisionClient, DecisionQuestion, DecisionResponse
|
|
21
|
+
from aid_runtime.errors import ConfigurationError, EvalError
|
|
19
22
|
from aid_runtime.evals.dataset import EvalCase
|
|
20
23
|
from aid_runtime.evals.predicate import evaluate_predicate
|
|
21
24
|
from aid_runtime.structured import run_structured
|
|
22
25
|
|
|
23
26
|
__all__ = [
|
|
24
27
|
"AssertMetric",
|
|
28
|
+
"DecisionScore",
|
|
25
29
|
"ExactMatch",
|
|
26
30
|
"JsonSchemaValid",
|
|
27
31
|
"JudgeVerdict",
|
|
@@ -273,6 +277,91 @@ class LlmJudge:
|
|
|
273
277
|
)
|
|
274
278
|
|
|
275
279
|
|
|
280
|
+
class DecisionScore:
|
|
281
|
+
"""Scores a prediction with a TypeSafe AI Jev ``score`` decision.
|
|
282
|
+
|
|
283
|
+
``deterministic`` is ``False``: the answer comes from a model, so the gate
|
|
284
|
+
refuses to threshold on it and ``gate.ci`` may not declare it. What makes a
|
|
285
|
+
``score`` decision the right rubric here is that its ``criteria`` are
|
|
286
|
+
ordered: the position the model returns *is* the score, so this metric maps
|
|
287
|
+
that position onto ``[0, 1]`` instead of inventing an order for labels.
|
|
288
|
+
|
|
289
|
+
A call that fails, or an answer outside the declared range, raises rather
|
|
290
|
+
than scoring. A ``0.0`` would read as a regression the candidate caused and
|
|
291
|
+
a ``1.0`` would silently pass; neither is what "the vendor did not answer"
|
|
292
|
+
means.
|
|
293
|
+
|
|
294
|
+
``threshold`` marks a single answer as passing, which is useful when the
|
|
295
|
+
metric is read directly. It is not a gate: ``BaselineGate`` refuses a
|
|
296
|
+
``Threshold`` on any non-deterministic metric, so a spec has no way to floor
|
|
297
|
+
this score and the generated eval never asks for one.
|
|
298
|
+
"""
|
|
299
|
+
|
|
300
|
+
def __init__(
|
|
301
|
+
self,
|
|
302
|
+
decision: DecisionDefinition,
|
|
303
|
+
*,
|
|
304
|
+
threshold: float = 0.5,
|
|
305
|
+
name: str = "decision",
|
|
306
|
+
client_factory: Callable[[], DecisionAsker] | None = None,
|
|
307
|
+
) -> None:
|
|
308
|
+
if len(decision.criteria) < 2:
|
|
309
|
+
raise ConfigurationError(
|
|
310
|
+
f"decision {decision.id!r} declares {len(decision.criteria)} criteria, "
|
|
311
|
+
"but scoring needs at least two ordered levels"
|
|
312
|
+
)
|
|
313
|
+
self._decision = decision
|
|
314
|
+
self._threshold = threshold
|
|
315
|
+
self._name = name
|
|
316
|
+
self._client_factory = client_factory
|
|
317
|
+
self._client: DecisionAsker | None = None
|
|
318
|
+
|
|
319
|
+
@property
|
|
320
|
+
def name(self) -> str:
|
|
321
|
+
return self._name
|
|
322
|
+
|
|
323
|
+
@property
|
|
324
|
+
def deterministic(self) -> bool:
|
|
325
|
+
return False
|
|
326
|
+
|
|
327
|
+
async def score(self, case: EvalCase, prediction: str) -> MetricResult:
|
|
328
|
+
response = await self._ask(prediction)
|
|
329
|
+
answer = response.answers.get(self._decision.id)
|
|
330
|
+
if answer is None or answer.score is None:
|
|
331
|
+
raise EvalError(
|
|
332
|
+
f"decision {self._decision.id!r} returned no score for its own question"
|
|
333
|
+
)
|
|
334
|
+
levels = len(self._decision.criteria)
|
|
335
|
+
normalized = (answer.score - 1.0) / (levels - 1)
|
|
336
|
+
if not 0.0 <= normalized <= 1.0:
|
|
337
|
+
raise EvalError(
|
|
338
|
+
f"decision {self._decision.id!r} answered {answer.score:g}, "
|
|
339
|
+
f"which is outside the declared 1..{levels} range"
|
|
340
|
+
)
|
|
341
|
+
return MetricResult(
|
|
342
|
+
metric=self.name,
|
|
343
|
+
score=normalized,
|
|
344
|
+
passed=normalized >= self._threshold,
|
|
345
|
+
detail=f"level {answer.score:g} of {levels}",
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
async def _ask(self, prediction: str) -> DecisionResponse:
|
|
349
|
+
if self._client is None:
|
|
350
|
+
self._client = (self._client_factory or DecisionClient)()
|
|
351
|
+
return await self._client.decide(
|
|
352
|
+
model=self._decision.model,
|
|
353
|
+
state=prediction,
|
|
354
|
+
questions={
|
|
355
|
+
self._decision.id: DecisionQuestion(
|
|
356
|
+
type="score",
|
|
357
|
+
instructions=self._decision.instructions,
|
|
358
|
+
criteria=self._decision.criteria,
|
|
359
|
+
)
|
|
360
|
+
},
|
|
361
|
+
reproducible=True,
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
|
|
276
365
|
def default_metrics() -> tuple[Metric, ...]:
|
|
277
366
|
"""The deterministic gate metrics: everything that needs no model call."""
|
|
278
367
|
return (ExactMatch(), NormalizedContains(), JsonSchemaValid())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aid-runtime-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.91
|
|
4
4
|
Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
|
|
5
5
|
Author: The AID Framework authors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
aid_runtime/__init__.py,sha256=
|
|
1
|
+
aid_runtime/__init__.py,sha256=O3QiwSITK-KaobuENTMu01TPAoqsxlSa2e6wAyrKSXo,12397
|
|
2
2
|
aid_runtime/cache.py,sha256=jhw_EBd9dfWEUzYeibOvIkVBqqiLUjqF5WKEPz9GkhE,6836
|
|
3
3
|
aid_runtime/concurrency.py,sha256=z0tFQHw35ttFLKfazGBjCMPOLQOnUotE_OPpvR1piH4,2829
|
|
4
4
|
aid_runtime/control.py,sha256=u4U97QFdYSSjOPY3D6f1-GZhkGhygEdR-apdgw_jJok,13797
|
|
@@ -20,15 +20,15 @@ aid_runtime/agents/chat_model.py,sha256=fZdCmSpoECuBVGZE1s8NmT2erT33RhDuLh3yJM6k
|
|
|
20
20
|
aid_runtime/agents/deep_agents.py,sha256=ZM6ZSc92arCvtsYGsIGdF-NryqN_tvXtRqbdlHaGpeE,26948
|
|
21
21
|
aid_runtime/agents/engine.py,sha256=RQUV49u7MLDmirnFv8YsRGdIutzUGsGaLA6Y2JT5wj0,4129
|
|
22
22
|
aid_runtime/agents/guardrails.py,sha256=XwllB-33HE65FJumCMx--LGDVNfWjLrrupQHfUbCAG8,26624
|
|
23
|
-
aid_runtime/agents/ir.py,sha256=
|
|
23
|
+
aid_runtime/agents/ir.py,sha256=GzIbaMFsq64M0eC8tB2xB6pKrXtJdT4Z1LtuM4wKEEE,25145
|
|
24
24
|
aid_runtime/agents/loop.py,sha256=T-QnC9BQ9K3RyZfHdAuzWiwMXBpQjDLGdHrLgf2fnFM,52608
|
|
25
25
|
aid_runtime/agents/memory.py,sha256=6_D6k2bzAiR2euNvzr6HB28wsUUq-R-WTQc12gkB8ao,9156
|
|
26
26
|
aid_runtime/agents/policy.py,sha256=ael0EW_hWfLu95rbqFMrR4WyqAPtgiSNvNw97xnthdw,6122
|
|
27
27
|
aid_runtime/agents/state.py,sha256=4itT7BWv2JKSeWpRrDyxLguOOVnz9gGH_qgRdCbWCaw,6086
|
|
28
|
-
aid_runtime/evals/__init__.py,sha256=
|
|
28
|
+
aid_runtime/evals/__init__.py,sha256=Xxoz6OImHs9-BfaRQo7O4tu9J8zAIDXiotqIM-xnj1Q,1419
|
|
29
29
|
aid_runtime/evals/dataset.py,sha256=waG4tYSJsgsZ9DLxkhUvF_X-aQB8w2OexYxc7Wwdiyg,2494
|
|
30
30
|
aid_runtime/evals/gate.py,sha256=_nLWXvcuHwq8nE3HpiONg_wBkrzZyGrGT49ZNeKMyTY,15524
|
|
31
|
-
aid_runtime/evals/metrics.py,sha256=
|
|
31
|
+
aid_runtime/evals/metrics.py,sha256=il9lzJa-hir59pw9Muyg9MhDuozUqAQaO1Tb75CxBKc,14185
|
|
32
32
|
aid_runtime/evals/predicate.py,sha256=JaeN1LJFpliI4JHYdFPtXfjH5_Aad-2-U3ZC6_hManE,8726
|
|
33
33
|
aid_runtime/evals/runner.py,sha256=Lkl-kAVxegPO40pCBUcprRBKvfL6bjYzVf__xe6Z-Mc,7951
|
|
34
34
|
aid_runtime/providers/__init__.py,sha256=5PA3A5IRabcxYS0r75Byol2RHcC4ZZ3gi-boJV0sjWQ,1516
|
|
@@ -51,7 +51,7 @@ aid_runtime/retrieval/rerank.py,sha256=L4ICBi9YHDzhnKVtImKh5Wzre1HDzS8at-AKDkXBJ
|
|
|
51
51
|
aid_runtime/retrieval/retriever.py,sha256=hVLP0xOLKioYsa-aS1akyJl5p-WbpVjm8OfCw26m4CE,13941
|
|
52
52
|
aid_runtime/retrieval/stores.py,sha256=VEi68AaMHcQjdAbWOHflp3jCl1_1db71rIzZjTouLlo,5857
|
|
53
53
|
aid_runtime/retrieval/types.py,sha256=8vKP21rmE9LglnB5gtv0dLBIkXzaPqdG3-GS98K0gpc,13498
|
|
54
|
-
aid_runtime_python-0.1.
|
|
55
|
-
aid_runtime_python-0.1.
|
|
56
|
-
aid_runtime_python-0.1.
|
|
57
|
-
aid_runtime_python-0.1.
|
|
54
|
+
aid_runtime_python-0.1.91.dist-info/METADATA,sha256=ws7MDn3A1208lV17JfL_sFmuFIHVb4eHRa9tC40B2uM,17005
|
|
55
|
+
aid_runtime_python-0.1.91.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
56
|
+
aid_runtime_python-0.1.91.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
|
|
57
|
+
aid_runtime_python-0.1.91.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|