seldon-runtime 0.1.1.dev2__py3-none-any.whl → 0.1.1.dev4__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.
- seldon_runtime/__init__.py +1 -1
- seldon_runtime/artifact.py +76 -22
- seldon_runtime/components.py +112 -1
- seldon_runtime/conditional.py +2 -0
- seldon_runtime/contracts.py +72 -1
- seldon_runtime/executor.py +27 -13
- seldon_runtime/native_adapter.py +160 -0
- seldon_runtime/program_validation.py +2 -0
- seldon_runtime/semantic.py +140 -0
- seldon_runtime/span_review.py +339 -0
- seldon_runtime/system_one.py +180 -0
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/METADATA +88 -28
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/RECORD +18 -15
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/WHEEL +0 -0
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/licenses/LICENSE +0 -0
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/licenses/NOTICE +0 -0
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/licenses/THIRD_PARTY_NOTICES.md +0 -0
- {seldon_runtime-0.1.1.dev2.dist-info → seldon_runtime-0.1.1.dev4.dist-info}/top_level.txt +0 -0
seldon_runtime/__init__.py
CHANGED
seldon_runtime/artifact.py
CHANGED
|
@@ -16,18 +16,20 @@ from dataclasses import dataclass
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
from typing import Any, Literal, Protocol
|
|
18
18
|
|
|
19
|
-
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
19
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator
|
|
20
20
|
|
|
21
21
|
from .contracts import FunctionSpec, Plan, digest
|
|
22
22
|
from .executor import Execution, execute
|
|
23
|
+
from .native_adapter import native_request, validate_native_config, validate_native_model
|
|
24
|
+
from .native_schema import NATIVE_CONTRACT_ERRORS
|
|
23
25
|
from .output_budget import resolve
|
|
24
26
|
from .program_validation import validate_program
|
|
25
27
|
from .provider_error import ProviderError
|
|
26
28
|
|
|
27
29
|
MAX_ARTIFACT_BYTES = 2 * 1024 * 1024
|
|
28
|
-
RUNTIME_VERSION = "0.1.1.
|
|
30
|
+
RUNTIME_VERSION = "0.1.1.dev4"
|
|
29
31
|
_SHA256 = r"^[0-9a-f]{64}$"
|
|
30
|
-
Capability = Literal["chat", "structured_output", "tools"]
|
|
32
|
+
Capability = Literal["chat", "structured_output", "tools", "choice", "extract"]
|
|
31
33
|
OptimizerContract = Literal[
|
|
32
34
|
"optimizer-correctness-v1",
|
|
33
35
|
"optimizer-correctness-v2",
|
|
@@ -51,11 +53,25 @@ class _Data(BaseModel):
|
|
|
51
53
|
class ModelRequirements(_Data):
|
|
52
54
|
"""Execution capabilities, not endpoint discovery or proof of model quality."""
|
|
53
55
|
|
|
54
|
-
protocol: Literal["openai-chat-completions"]
|
|
56
|
+
protocol: Literal["openai-chat-completions", "fastino_gliner", "system_one"]
|
|
55
57
|
capabilities: tuple[Capability, ...] = Field(min_length=1, max_length=3)
|
|
56
58
|
context_length: int = Field(strict=True, ge=1, le=100_000_000)
|
|
57
59
|
max_output_tokens: int = Field(strict=True, ge=1, le=10_000_000)
|
|
58
60
|
revision: str | None = Field(max_length=256)
|
|
61
|
+
upstream_model: str | None = Field(default=None, min_length=1, max_length=256)
|
|
62
|
+
native_modes: tuple[Literal["legacy", "pairs", "spans", "records"], ...] = ()
|
|
63
|
+
native_answers: tuple[Literal["choice", "boolean", "noul", "score"], ...] = ()
|
|
64
|
+
native_max_levels: int = Field(default=10, strict=True, ge=2, le=10)
|
|
65
|
+
native_profile: dict[str, Any] = Field(default_factory=dict)
|
|
66
|
+
|
|
67
|
+
@model_validator(mode="after")
|
|
68
|
+
def valid_native_contract(self):
|
|
69
|
+
validate_native_model(self)
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def upstream_model_name(self):
|
|
74
|
+
return self.upstream_model
|
|
59
75
|
|
|
60
76
|
|
|
61
77
|
class Evidence(_Data):
|
|
@@ -70,8 +86,8 @@ class ArtifactManifest(_Data):
|
|
|
70
86
|
version: Literal["compiler-artifact-v1"]
|
|
71
87
|
compiler_version: str = Field(min_length=1, max_length=64, pattern=r"^[a-zA-Z0-9.+_-]+$")
|
|
72
88
|
# Explicit reviewed reader compatibility, never a version-prefix/range guess.
|
|
73
|
-
#
|
|
74
|
-
runtime_version: Literal["0.1.1.dev1", "0.1.1.dev2"]
|
|
89
|
+
# dev3 adds explicit native bindings; older artifacts retain their restrictions.
|
|
90
|
+
runtime_version: Literal["0.1.1.dev1", "0.1.1.dev2", "0.1.1.dev3", "0.1.1.dev4"]
|
|
75
91
|
optimizer_contract_version: OptimizerContract
|
|
76
92
|
instruction_envelope: Literal["instruction-envelope-v1"] | None
|
|
77
93
|
conditional: bool = Field(strict=True)
|
|
@@ -124,6 +140,8 @@ def _required_capabilities(plan: Plan, spec: FunctionSpec) -> dict[str, set[str]
|
|
|
124
140
|
for step in plan.steps:
|
|
125
141
|
if step.op == "llm":
|
|
126
142
|
add(step.model, calls[step.call], output_schema=step.output_schema)
|
|
143
|
+
elif step.op in {"choice", "extract"}:
|
|
144
|
+
required.setdefault(step.model, set()).add(step.op)
|
|
127
145
|
if plan.fallback:
|
|
128
146
|
for call in spec.calls:
|
|
129
147
|
add(call.model, call)
|
|
@@ -141,11 +159,18 @@ def _parse(data: bytes) -> ArtifactManifest:
|
|
|
141
159
|
if raw.get("spec", {}).get("reference_binding") is not None:
|
|
142
160
|
raise ValueError
|
|
143
161
|
if any(
|
|
144
|
-
step.get("op")
|
|
145
|
-
for step in raw.get("plan", {}).get("steps", [])
|
|
162
|
+
step.get("op") == "generated_kernel" for step in raw.get("plan", {}).get("steps", [])
|
|
146
163
|
):
|
|
147
164
|
raise ValueError
|
|
148
165
|
manifest = ArtifactManifest.model_validate(raw)
|
|
166
|
+
native = [step for step in manifest.plan.steps if step.op in {"choice", "extract"}]
|
|
167
|
+
if native and manifest.runtime_version not in {"0.1.1.dev3", "0.1.1.dev4"}:
|
|
168
|
+
raise ValueError
|
|
169
|
+
if (
|
|
170
|
+
manifest.spec.reference_program is not None
|
|
171
|
+
and manifest.runtime_version != RUNTIME_VERSION
|
|
172
|
+
):
|
|
173
|
+
raise ValueError
|
|
149
174
|
if (
|
|
150
175
|
digest({k: v for k, v in raw.items() if k != "manifest_digest"})
|
|
151
176
|
!= manifest.manifest_digest
|
|
@@ -158,16 +183,26 @@ def _parse(data: bytes) -> ArtifactManifest:
|
|
|
158
183
|
raise ValueError
|
|
159
184
|
plan = manifest.plan
|
|
160
185
|
contract = manifest.optimizer_contract_version
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if
|
|
167
|
-
|
|
168
|
-
or contract in {f"optimizer-correctness-v{i}" for i in range(1, 5)}
|
|
186
|
+
checked_plans = [plan]
|
|
187
|
+
if manifest.spec.reference_program is not None:
|
|
188
|
+
checked_plans.append(manifest.spec.reference_program)
|
|
189
|
+
from .semantic import SPAN_REVIEW_OPERATORS
|
|
190
|
+
|
|
191
|
+
if manifest.runtime_version != RUNTIME_VERSION and any(
|
|
192
|
+
step.op in SPAN_REVIEW_OPERATORS for checked in checked_plans for step in checked.steps
|
|
169
193
|
):
|
|
170
194
|
raise ValueError
|
|
195
|
+
for checked in checked_plans:
|
|
196
|
+
if checked.version == "function-plan-v4" and contract in {
|
|
197
|
+
"optimizer-correctness-v1",
|
|
198
|
+
"optimizer-correctness-v2",
|
|
199
|
+
}:
|
|
200
|
+
raise ValueError
|
|
201
|
+
if checked.version == "function-plan-v5" and (
|
|
202
|
+
not manifest.conditional
|
|
203
|
+
or contract in {f"optimizer-correctness-v{i}" for i in range(1, 5)}
|
|
204
|
+
):
|
|
205
|
+
raise ValueError
|
|
171
206
|
validate_program(plan, manifest.spec)
|
|
172
207
|
required = _required_capabilities(plan, manifest.spec)
|
|
173
208
|
if set(manifest.models) != set(required):
|
|
@@ -178,6 +213,8 @@ def _parse(data: bytes) -> ArtifactManifest:
|
|
|
178
213
|
raise ValueError
|
|
179
214
|
if len(set(model.capabilities)) != len(model.capabilities):
|
|
180
215
|
raise ValueError
|
|
216
|
+
for step in native:
|
|
217
|
+
validate_native_config(manifest.models[step.model], step.op, step.config)
|
|
181
218
|
return manifest
|
|
182
219
|
except ArtifactError:
|
|
183
220
|
raise
|
|
@@ -196,6 +233,11 @@ def _bindings(manifest, bindings):
|
|
|
196
233
|
if not isinstance(actual, ModelRequirements) or (
|
|
197
234
|
actual.protocol != required.protocol
|
|
198
235
|
or actual.revision != required.revision
|
|
236
|
+
or actual.upstream_model != required.upstream_model
|
|
237
|
+
or actual.native_profile != required.native_profile
|
|
238
|
+
or actual.native_max_levels != required.native_max_levels
|
|
239
|
+
or not set(required.native_modes) <= set(actual.native_modes)
|
|
240
|
+
or not set(required.native_answers) <= set(actual.native_answers)
|
|
199
241
|
or actual.context_length < required.context_length
|
|
200
242
|
# Omitted max_tokens preserves endpoint-default behavior, so an
|
|
201
243
|
# enlarged endpoint output ceiling cannot silently enlarge the bound.
|
|
@@ -233,18 +275,21 @@ class Artifact:
|
|
|
233
275
|
|
|
234
276
|
async def provider(model, payload):
|
|
235
277
|
required = manifest.models[model]
|
|
236
|
-
|
|
237
|
-
if
|
|
278
|
+
primitive = payload.get("primitive")
|
|
279
|
+
needed = {primitive["kind"]} if isinstance(primitive, dict) else {"chat"}
|
|
280
|
+
if not primitive and payload.get("tools"):
|
|
238
281
|
needed.add("tools")
|
|
239
|
-
if payload.get("response_format"):
|
|
282
|
+
if not primitive and payload.get("response_format"):
|
|
240
283
|
needed.add("structured_output")
|
|
241
|
-
if
|
|
284
|
+
if not needed <= set(required.capabilities):
|
|
242
285
|
raise ArtifactError("model_capability_mismatch")
|
|
286
|
+
if primitive:
|
|
287
|
+
native_request(required, payload)
|
|
243
288
|
bounded, _, _ = resolve(
|
|
244
289
|
payload,
|
|
245
290
|
required,
|
|
246
291
|
manifest.spec.output_token_policy,
|
|
247
|
-
body=lambda value, _: value,
|
|
292
|
+
body=lambda value, _: native_request(required, value)[1] if primitive else value,
|
|
248
293
|
estimator_for=lambda _: None,
|
|
249
294
|
)
|
|
250
295
|
try:
|
|
@@ -275,6 +320,10 @@ class Artifact:
|
|
|
275
320
|
upstream_status=429 if exc.upstream_status == 429 else None,
|
|
276
321
|
provider_dispatched=exc.provider_dispatched,
|
|
277
322
|
) from None
|
|
323
|
+
except ValueError as exc:
|
|
324
|
+
if str(exc) in NATIVE_CONTRACT_ERRORS | {"invalid_provider_output"}:
|
|
325
|
+
raise ValueError(str(exc)) from None
|
|
326
|
+
raise ArtifactError("execution_failed") from None
|
|
278
327
|
except Exception:
|
|
279
328
|
raise ArtifactError("execution_failed") from None
|
|
280
329
|
|
|
@@ -297,7 +346,12 @@ class Artifact:
|
|
|
297
346
|
except asyncio.CancelledError:
|
|
298
347
|
raise
|
|
299
348
|
except Exception as exc:
|
|
300
|
-
safe =
|
|
349
|
+
safe = NATIVE_CONTRACT_ERRORS | {
|
|
350
|
+
"token_limit",
|
|
351
|
+
"context_unverified",
|
|
352
|
+
"output_schema",
|
|
353
|
+
"invalid_provider_output",
|
|
354
|
+
}
|
|
301
355
|
code = (
|
|
302
356
|
str(exc) if isinstance(exc, ValueError) and str(exc) in safe else "execution_failed"
|
|
303
357
|
)
|
seldon_runtime/components.py
CHANGED
|
@@ -45,7 +45,7 @@ def collection(properties, maximum, required=None):
|
|
|
45
45
|
"items": {
|
|
46
46
|
"type": "object",
|
|
47
47
|
"properties": properties,
|
|
48
|
-
"required":
|
|
48
|
+
"required": list(properties) if required is None else required,
|
|
49
49
|
},
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -84,7 +84,106 @@ LINKS = collection(
|
|
|
84
84
|
32,
|
|
85
85
|
)
|
|
86
86
|
|
|
87
|
+
SPAN_TEXT = {"type": "string", "maxLength": 262144}
|
|
88
|
+
SPAN_LABEL = {"type": "string", "minLength": 1, "maxLength": 128}
|
|
89
|
+
SPAN_PROPERTIES = {
|
|
90
|
+
"text": SPAN_TEXT,
|
|
91
|
+
"label": SPAN_LABEL,
|
|
92
|
+
"start": {"type": "integer", "minimum": 0},
|
|
93
|
+
"end": {"type": "integer", "minimum": 1},
|
|
94
|
+
"accepted": {"type": "boolean"},
|
|
95
|
+
"source_priority": {"type": "integer", "minimum": 0},
|
|
96
|
+
"source_instance": {"type": "string", "maxLength": 256},
|
|
97
|
+
"score_group": {"type": "string", "maxLength": 256},
|
|
98
|
+
"score": {"type": "number"},
|
|
99
|
+
}
|
|
100
|
+
REVIEW_CANDIDATES = collection(
|
|
101
|
+
{
|
|
102
|
+
**SPAN_PROPERTIES,
|
|
103
|
+
"id": {"type": "string", "minLength": 1, "maxLength": 128},
|
|
104
|
+
"needs_review": {"type": "boolean"},
|
|
105
|
+
},
|
|
106
|
+
1000,
|
|
107
|
+
["id", "text", "label", "start", "end"],
|
|
108
|
+
)
|
|
109
|
+
REVIEW_DECISIONS = collection(
|
|
110
|
+
{
|
|
111
|
+
"id": {"type": "string", "maxLength": 128},
|
|
112
|
+
"decision": {"enum": [None, "keep", "drop", "reclass"]},
|
|
113
|
+
"proposed_label": {"type": ["string", "null"], "maxLength": 128},
|
|
114
|
+
},
|
|
115
|
+
1000,
|
|
116
|
+
[],
|
|
117
|
+
)
|
|
118
|
+
REVIEW_SPANS = collection(
|
|
119
|
+
SPAN_PROPERTIES, 1000, ["text", "label", "start", "end", "accepted", "source_priority"]
|
|
120
|
+
)
|
|
121
|
+
SPAN_POLICY = {
|
|
122
|
+
"type": "object",
|
|
123
|
+
"properties": {
|
|
124
|
+
"allowed_labels": {"type": ["array", "null"], "maxItems": 128, "items": SPAN_LABEL},
|
|
125
|
+
"excluded_labels": {"type": "array", "maxItems": 128, "items": SPAN_LABEL},
|
|
126
|
+
},
|
|
127
|
+
"additionalProperties": False,
|
|
128
|
+
}
|
|
129
|
+
SPAN_QUOTES = collection(
|
|
130
|
+
{"label": SPAN_LABEL, "reason": {"type": ["string", "null"]}}, 1000, ["label"]
|
|
131
|
+
)
|
|
132
|
+
GROUNDED_QUOTES = {
|
|
133
|
+
"type": "object",
|
|
134
|
+
"properties": {
|
|
135
|
+
"spans": REVIEW_SPANS,
|
|
136
|
+
"failed_quotes": collection(
|
|
137
|
+
{
|
|
138
|
+
"index": {"type": "integer", "minimum": 0},
|
|
139
|
+
"quote": {"type": "object"},
|
|
140
|
+
"reason": {
|
|
141
|
+
"enum": [
|
|
142
|
+
"non_verbatim_value",
|
|
143
|
+
"missing_context",
|
|
144
|
+
"non_verbatim_context",
|
|
145
|
+
"zero_contextual_matches",
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
1000,
|
|
150
|
+
),
|
|
151
|
+
"failed_count": {"type": "integer", "minimum": 0, "maximum": 1000},
|
|
152
|
+
"repair_quotes": {"type": "array", "maxItems": 1000, "items": {"type": "object"}},
|
|
153
|
+
"normalized_quotes": SPAN_QUOTES,
|
|
154
|
+
},
|
|
155
|
+
"required": ["spans", "failed_quotes", "failed_count", "repair_quotes", "normalized_quotes"],
|
|
156
|
+
"additionalProperties": False,
|
|
157
|
+
}
|
|
158
|
+
|
|
87
159
|
SEMANTIC_IO = {
|
|
160
|
+
"apply_span_decisions": (
|
|
161
|
+
[
|
|
162
|
+
SPAN_TEXT,
|
|
163
|
+
REVIEW_CANDIDATES,
|
|
164
|
+
{"anyOf": [REVIEW_DECISIONS, {"type": "object"}]},
|
|
165
|
+
SPAN_POLICY,
|
|
166
|
+
],
|
|
167
|
+
REVIEW_SPANS,
|
|
168
|
+
),
|
|
169
|
+
"ground_span_quotes": (
|
|
170
|
+
[SPAN_TEXT, {"anyOf": [SPAN_QUOTES, {"type": "object"}]}, SPAN_POLICY],
|
|
171
|
+
GROUNDED_QUOTES,
|
|
172
|
+
),
|
|
173
|
+
"reconcile_span_candidates": (
|
|
174
|
+
[
|
|
175
|
+
SPAN_TEXT,
|
|
176
|
+
{
|
|
177
|
+
"type": "object",
|
|
178
|
+
"maxProperties": 1000,
|
|
179
|
+
"additionalProperties": collection(
|
|
180
|
+
SPAN_PROPERTIES, 1000, ["text", "label", "start", "end"]
|
|
181
|
+
),
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
REVIEW_SPANS,
|
|
185
|
+
),
|
|
186
|
+
"encode_json": ([{}], {"type": "string", "maxLength": 262144}),
|
|
88
187
|
"align_spans": (
|
|
89
188
|
[STRING, collection({"text": STRING, "label": STRING}, 32)],
|
|
90
189
|
collection(
|
|
@@ -134,6 +233,18 @@ SEMANTIC_IO = {
|
|
|
134
233
|
}
|
|
135
234
|
|
|
136
235
|
CONFIG_FIELDS = {
|
|
236
|
+
"decisions_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
|
|
237
|
+
"quotes_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
|
|
238
|
+
"quote_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
|
|
239
|
+
"before_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
|
|
240
|
+
"after_field": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"},
|
|
241
|
+
"source_priority": {"type": "integer", "minimum": 0},
|
|
242
|
+
"field_order": {
|
|
243
|
+
"type": "array",
|
|
244
|
+
"maxItems": 64,
|
|
245
|
+
"uniqueItems": True,
|
|
246
|
+
"items": {"type": "string", "minLength": 1, "maxLength": 128},
|
|
247
|
+
},
|
|
137
248
|
"casefold": {"type": "boolean"},
|
|
138
249
|
"unique": {"type": "boolean"},
|
|
139
250
|
"size": {"type": "integer", "minimum": 1, "maximum": 16384},
|
seldon_runtime/conditional.py
CHANGED
|
@@ -225,6 +225,8 @@ def binding_states(plan, spec):
|
|
|
225
225
|
if step.bind_call not in calls:
|
|
226
226
|
raise ValueError("unknown_call")
|
|
227
227
|
shared[step.bind_call] = step.id
|
|
228
|
+
if spec.reference_program is not None:
|
|
229
|
+
shared[step.id] = step.id
|
|
228
230
|
after[step.id] = shared
|
|
229
231
|
return before
|
|
230
232
|
|
seldon_runtime/contracts.py
CHANGED
|
@@ -545,6 +545,7 @@ class FunctionSpec(Contract):
|
|
|
545
545
|
template_syntax: Literal["python_format", "jinja_variables"] | None = None
|
|
546
546
|
bindings: list[Binding] = Field(default_factory=list, max_length=64)
|
|
547
547
|
output_schema: dict[str, Any]
|
|
548
|
+
reference_program: Plan | None = None
|
|
548
549
|
evaluator: Literal["exact", "records", "decimal", "rubric"] = "exact"
|
|
549
550
|
evaluation_pending: bool = False
|
|
550
551
|
rubric: Rubric | None = None
|
|
@@ -566,6 +567,8 @@ class FunctionSpec(Contract):
|
|
|
566
567
|
value.pop("evaluation", None)
|
|
567
568
|
if self.input_schema is None:
|
|
568
569
|
value.pop("input_schema", None)
|
|
570
|
+
if self.reference_program is None:
|
|
571
|
+
value.pop("reference_program", None)
|
|
569
572
|
if self.preparation is None:
|
|
570
573
|
value.pop("preparation", None)
|
|
571
574
|
if self.template_syntax is None:
|
|
@@ -622,13 +625,49 @@ class FunctionSpec(Contract):
|
|
|
622
625
|
ids = [c.id for c in self.calls]
|
|
623
626
|
if len(set(ids)) != len(ids) or "input" in ids:
|
|
624
627
|
raise ValueError("duplicate_call_id")
|
|
628
|
+
if self.reference_program is not None:
|
|
629
|
+
program = self.reference_program
|
|
630
|
+
if program.fallback:
|
|
631
|
+
raise ValueError("reference_program_has_fallback")
|
|
632
|
+
declared = {call.id: call for call in self.calls}
|
|
633
|
+
bound = []
|
|
634
|
+
for step in program.steps:
|
|
635
|
+
if step.op in {"generated_kernel", "choice", "extract"}:
|
|
636
|
+
raise ValueError("unsupported_reference_operation")
|
|
637
|
+
if step.op == "llm":
|
|
638
|
+
call = declared.get(step.call)
|
|
639
|
+
if call is None or step.id != call.id or step.model != call.model:
|
|
640
|
+
raise ValueError("reference_call_mismatch")
|
|
641
|
+
if (
|
|
642
|
+
step.instruction_mode != "original_call_ref"
|
|
643
|
+
or step.prompt is not None
|
|
644
|
+
or step.messages is not None
|
|
645
|
+
or step.output_schema is not None
|
|
646
|
+
or step.inputs
|
|
647
|
+
or step.config
|
|
648
|
+
or step.output_binding != "call"
|
|
649
|
+
or step.over is not None
|
|
650
|
+
or step.max_chunks is not None
|
|
651
|
+
):
|
|
652
|
+
raise ValueError("reference_call_modified")
|
|
653
|
+
bound.append(step.call)
|
|
654
|
+
if len(bound) != len(self.calls) or set(bound) != set(declared):
|
|
655
|
+
raise ValueError("reference_calls_incomplete")
|
|
656
|
+
from .program_validation import validate_program
|
|
657
|
+
|
|
658
|
+
validate_program(program, self)
|
|
625
659
|
occupied = set()
|
|
626
660
|
for binding in self.bindings:
|
|
627
661
|
if binding.call not in ids:
|
|
628
662
|
raise ValueError("unknown_call")
|
|
629
663
|
call = self.calls[ids.index(binding.call)]
|
|
630
664
|
root, _ = reference(binding.source)
|
|
631
|
-
|
|
665
|
+
prior_roots = ids[: ids.index(binding.call)]
|
|
666
|
+
if self.reference_program is not None:
|
|
667
|
+
steps = self.reference_program.steps
|
|
668
|
+
call_position = next(i for i, step in enumerate(steps) if step.call == binding.call)
|
|
669
|
+
prior_roots = [step.id for step in steps[:call_position]]
|
|
670
|
+
if root != "input" and root not in prior_roots:
|
|
632
671
|
raise ValueError("forward_reference")
|
|
633
672
|
if binding.message >= len(call.messages):
|
|
634
673
|
raise ValueError("missing_message")
|
|
@@ -682,6 +721,10 @@ class Step(Contract):
|
|
|
682
721
|
"merge_spans",
|
|
683
722
|
"merge_records",
|
|
684
723
|
"merge_labels",
|
|
724
|
+
"apply_span_decisions",
|
|
725
|
+
"ground_span_quotes",
|
|
726
|
+
"reconcile_span_candidates",
|
|
727
|
+
"encode_json",
|
|
685
728
|
]
|
|
686
729
|
inputs: list[str] = Field(default_factory=list, max_length=32)
|
|
687
730
|
config: dict[str, Any] = Field(default_factory=dict)
|
|
@@ -858,3 +901,31 @@ class Plan(Contract):
|
|
|
858
901
|
elif learned > 3:
|
|
859
902
|
raise ValueError("model_call_limit")
|
|
860
903
|
return self
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
def reference_plan(
|
|
907
|
+
spec: FunctionSpec,
|
|
908
|
+
*,
|
|
909
|
+
model_overrides: dict[str, str] | None = None,
|
|
910
|
+
version: str = "function-plan-v2",
|
|
911
|
+
) -> Plan:
|
|
912
|
+
"""Preserve declared workflow control and deterministic processing in every reader."""
|
|
913
|
+
overrides = model_overrides or {}
|
|
914
|
+
if not set(overrides) <= {call.id for call in spec.calls}:
|
|
915
|
+
raise ValueError("unknown_call")
|
|
916
|
+
if spec.reference_program is not None:
|
|
917
|
+
values = spec.reference_program.model_dump(mode="json")
|
|
918
|
+
for step in values["steps"]:
|
|
919
|
+
if step["op"] == "llm":
|
|
920
|
+
step["model"] = overrides.get(step["call"], step["model"])
|
|
921
|
+
return Plan.model_validate(values)
|
|
922
|
+
return Plan(
|
|
923
|
+
version=version,
|
|
924
|
+
steps=[
|
|
925
|
+
Step(id=call.id, op="llm", model=overrides.get(call.id, call.model), call=call.id)
|
|
926
|
+
for call in spec.calls
|
|
927
|
+
],
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
FunctionSpec.model_rebuild()
|
seldon_runtime/executor.py
CHANGED
|
@@ -17,7 +17,15 @@ from typing import Any
|
|
|
17
17
|
|
|
18
18
|
from jsonschema import Draft202012Validator
|
|
19
19
|
|
|
20
|
-
from .contracts import
|
|
20
|
+
from .contracts import (
|
|
21
|
+
FunctionSpec,
|
|
22
|
+
Plan,
|
|
23
|
+
canonical,
|
|
24
|
+
digest,
|
|
25
|
+
reference,
|
|
26
|
+
reference_plan,
|
|
27
|
+
semantic_plan,
|
|
28
|
+
)
|
|
21
29
|
from .provider_error import ProviderError
|
|
22
30
|
|
|
23
31
|
|
|
@@ -381,7 +389,8 @@ def step_payload(spec, step, inputs, prior, values, *, instruction_envelope=None
|
|
|
381
389
|
|
|
382
390
|
if instruction_envelope != INSTRUCTION_ENVELOPE_CONTRACT:
|
|
383
391
|
raise ValueError("instruction_envelope_unsupported")
|
|
384
|
-
|
|
392
|
+
bindings = {**values, **prior} if spec.reference_program is not None else prior
|
|
393
|
+
payload = render_request(spec, step.call, inputs, bindings)
|
|
385
394
|
if "max_tokens" not in payload:
|
|
386
395
|
# Explicit null freezes provider omission even when a run normally sizes
|
|
387
396
|
# output itself; the request marker also reserves the endpoint ceiling.
|
|
@@ -598,6 +607,9 @@ async def _execute(
|
|
|
598
607
|
if not probe and len(canonical(value).encode()) > 262144:
|
|
599
608
|
raise ValueError("intermediate_size_limit")
|
|
600
609
|
values[step.id] = value
|
|
610
|
+
if spec.reference_program is not None:
|
|
611
|
+
# Match validation's latest dominating producer for step/call collisions.
|
|
612
|
+
prior[step.id] = value
|
|
601
613
|
if trace is not None:
|
|
602
614
|
record["output"] = evidence_value(value)
|
|
603
615
|
predecessor = step.id
|
|
@@ -683,8 +695,9 @@ async def execute(
|
|
|
683
695
|
in {EVALUATION_FIDELITY_CONTRACT, SPAN_GROUNDING_CONTRACT, CORRECTNESS_REPAIR_CONTRACT}
|
|
684
696
|
and conditional is not False
|
|
685
697
|
)
|
|
686
|
-
|
|
687
|
-
|
|
698
|
+
checked_plans = [plan]
|
|
699
|
+
if spec.reference_program is not None:
|
|
700
|
+
checked_plans.append(spec.reference_program)
|
|
688
701
|
chunking = {
|
|
689
702
|
CONTEXT_CHUNKING_CONTRACT,
|
|
690
703
|
"optimizer-correctness-v4",
|
|
@@ -693,12 +706,15 @@ async def execute(
|
|
|
693
706
|
SPAN_GROUNDING_CONTRACT,
|
|
694
707
|
CORRECTNESS_REPAIR_CONTRACT,
|
|
695
708
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
contract not in chunking
|
|
700
|
-
|
|
701
|
-
|
|
709
|
+
for checked in checked_plans:
|
|
710
|
+
if checked.version == "function-plan-v5" and not v5_allowed:
|
|
711
|
+
raise ValueError("plan_version_unsupported")
|
|
712
|
+
if checked.version == "function-plan-v4" and contract not in chunking:
|
|
713
|
+
raise ValueError("plan_version_unsupported")
|
|
714
|
+
if any(step.config.get("view") == "bindings" for step in checked.steps) and (
|
|
715
|
+
contract not in chunking
|
|
716
|
+
):
|
|
717
|
+
raise ValueError("view_requires_v3")
|
|
702
718
|
from .deadline import admission_deadline
|
|
703
719
|
|
|
704
720
|
with admission_deadline(time.monotonic() + timeout):
|
|
@@ -829,9 +845,7 @@ async def _execute_with_fallback(
|
|
|
829
845
|
)
|
|
830
846
|
if not plan.fallback or not allowed:
|
|
831
847
|
raise
|
|
832
|
-
original =
|
|
833
|
-
steps=[Step(id=c.id, op="llm", model=c.model, call=c.id) for c in spec.calls]
|
|
834
|
-
)
|
|
848
|
+
original = reference_plan(spec, version="function-plan-v1")
|
|
835
849
|
fallback_phase = True
|
|
836
850
|
remaining = timeout - (time.monotonic() - start)
|
|
837
851
|
result = await _execute(
|