aid-runtime-python 0.1.90__tar.gz → 0.1.92__tar.gz
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_python-0.1.90 → aid_runtime_python-0.1.92}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/__init__.py +1 -1
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/ir.py +5 -4
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/__init__.py +2 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/metrics.py +90 -1
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/SOURCES.txt +1 -0
- aid_runtime_python-0.1.92/tests/test_evals_decision.py +150 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/README.md +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/setup.cfg +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/chat_model.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/deep_agents.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/loop.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/__init__.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/tests/test_vertex_provider.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aid-runtime-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.92
|
|
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
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "aid-runtime-python"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.92"
|
|
8
8
|
description = "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."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -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
|
|
@@ -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",
|
|
@@ -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())
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aid-runtime-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.92
|
|
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
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""A ``score`` decision measured as an eval metric.
|
|
2
|
+
|
|
3
|
+
Two things are pinned here beyond the arithmetic: the metric asks reproducibly, so a
|
|
4
|
+
vendor temperature change cannot move a recorded score, and a vendor failure raises
|
|
5
|
+
instead of scoring. A ``0.0`` would look like a regression the candidate caused.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from aid_runtime.agents.ir import DecisionDefinition
|
|
15
|
+
from aid_runtime.decisions import DecisionAnswer, DecisionQuestion, DecisionResponse
|
|
16
|
+
from aid_runtime.errors import ConfigurationError, EvalError
|
|
17
|
+
from aid_runtime.evals import DecisionScore, EvalCase
|
|
18
|
+
|
|
19
|
+
DEFINITION = DecisionDefinition(
|
|
20
|
+
id="helpfulness",
|
|
21
|
+
model="jev-1.14.0",
|
|
22
|
+
instructions="How helpful is this answer",
|
|
23
|
+
criteria=("unusable", "partial", "complete"),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FakeAsker:
|
|
28
|
+
"""A ``DecisionAsker`` returning one scripted answer, and recording the call."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, answer: DecisionAnswer | None, *, key: str = "helpfulness") -> None:
|
|
31
|
+
self._answer = answer
|
|
32
|
+
self._key = key
|
|
33
|
+
self.calls: list[dict[str, Any]] = []
|
|
34
|
+
|
|
35
|
+
async def decide(
|
|
36
|
+
self,
|
|
37
|
+
*,
|
|
38
|
+
model: str,
|
|
39
|
+
state: Any,
|
|
40
|
+
questions: Any,
|
|
41
|
+
reproducible: bool = False,
|
|
42
|
+
) -> DecisionResponse:
|
|
43
|
+
self.calls.append(
|
|
44
|
+
{
|
|
45
|
+
"model": model,
|
|
46
|
+
"state": state,
|
|
47
|
+
"questions": dict(questions),
|
|
48
|
+
"reproducible": reproducible,
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
answers = {} if self._answer is None else {self._key: self._answer}
|
|
52
|
+
return DecisionResponse(model=model, answers=answers)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def metric_for(answer: DecisionAnswer | None, **kwargs: Any) -> tuple[DecisionScore, FakeAsker]:
|
|
56
|
+
asker = FakeAsker(answer)
|
|
57
|
+
return DecisionScore(DEFINITION, client_factory=lambda: asker, **kwargs), asker
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
CASE = EvalCase(id="a", input="Q", expected="A")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def scored(level: float) -> DecisionAnswer:
|
|
64
|
+
return DecisionAnswer(type="score", score=level)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def test_a_score_metric_is_not_deterministic() -> None:
|
|
68
|
+
metric, _ = metric_for(scored(3))
|
|
69
|
+
|
|
70
|
+
assert metric.name == "decision"
|
|
71
|
+
assert metric.deterministic is False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.mark.parametrize(("level", "expected"), [(1, 0.0), (2, 0.5), (3, 1.0)])
|
|
75
|
+
async def test_the_ordered_criteria_position_maps_onto_the_unit_interval(
|
|
76
|
+
level: int, expected: float
|
|
77
|
+
) -> None:
|
|
78
|
+
metric, _ = metric_for(scored(level))
|
|
79
|
+
|
|
80
|
+
assert (await metric.score(CASE, "answer")).score == expected
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def test_the_detail_names_the_level_and_the_number_of_levels() -> None:
|
|
84
|
+
metric, _ = metric_for(scored(2))
|
|
85
|
+
|
|
86
|
+
assert (await metric.score(CASE, "answer")).detail == "level 2 of 3"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
async def test_the_threshold_marks_a_single_answer_as_passing() -> None:
|
|
90
|
+
at_half, _ = metric_for(scored(2))
|
|
91
|
+
at_bottom, _ = metric_for(scored(1))
|
|
92
|
+
|
|
93
|
+
assert (await at_half.score(CASE, "answer")).passed is True
|
|
94
|
+
assert (await at_bottom.score(CASE, "answer")).passed is False
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
async def test_the_metric_asks_the_decision_it_was_built_from() -> None:
|
|
98
|
+
metric, asker = metric_for(scored(3))
|
|
99
|
+
|
|
100
|
+
await metric.score(CASE, "the prediction")
|
|
101
|
+
|
|
102
|
+
assert asker.calls == [
|
|
103
|
+
{
|
|
104
|
+
"model": "jev-1.14.0",
|
|
105
|
+
"state": "the prediction",
|
|
106
|
+
"questions": {
|
|
107
|
+
"helpfulness": DecisionQuestion(
|
|
108
|
+
type="score",
|
|
109
|
+
instructions="How helpful is this answer",
|
|
110
|
+
criteria=("unusable", "partial", "complete"),
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
# A recorded score has to mean the same thing when the eval runs again.
|
|
114
|
+
"reproducible": True,
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async def test_a_missing_answer_raises_rather_than_scoring_zero() -> None:
|
|
120
|
+
metric, _ = metric_for(None)
|
|
121
|
+
|
|
122
|
+
with pytest.raises(EvalError, match="returned no score"):
|
|
123
|
+
await metric.score(CASE, "answer")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def test_an_answer_without_a_score_raises() -> None:
|
|
127
|
+
metric, _ = metric_for(DecisionAnswer(type="score"))
|
|
128
|
+
|
|
129
|
+
with pytest.raises(EvalError, match="returned no score"):
|
|
130
|
+
await metric.score(CASE, "answer")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@pytest.mark.parametrize("level", [0, 4])
|
|
134
|
+
async def test_a_level_outside_the_declared_range_raises(level: int) -> None:
|
|
135
|
+
metric, _ = metric_for(scored(level))
|
|
136
|
+
|
|
137
|
+
with pytest.raises(EvalError, match=r"outside the declared 1\.\.3 range"):
|
|
138
|
+
await metric.score(CASE, "answer")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_a_decision_with_fewer_than_two_levels_cannot_be_scored() -> None:
|
|
142
|
+
single = DecisionDefinition(
|
|
143
|
+
id="helpfulness",
|
|
144
|
+
model="jev-1.14.0",
|
|
145
|
+
instructions="How helpful is this answer",
|
|
146
|
+
criteria=("complete",),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
with pytest.raises(ConfigurationError, match="at least two ordered levels"):
|
|
150
|
+
DecisionScore(single)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/chat_model.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/deep_agents.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/agents/guardrails.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/__init__.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/anthropic.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/providers/bedrock.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/__init__.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/chunking.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/citations.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/connectors.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/embedding.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/metrics.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/pgvector.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime/retrieval/retriever.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.90 → aid_runtime_python-0.1.92}/src/aid_runtime_python.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|