seldon-runtime 0.1.1.dev1__py3-none-any.whl → 0.1.1.dev3__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.
@@ -1,3 +1,3 @@
1
1
  """Standalone Seldon Functions interpreter and local execution client."""
2
2
 
3
- __version__ = "0.1.1.dev1"
3
+ __version__ = "0.1.1.dev3"
@@ -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.dev1"
30
+ RUNTIME_VERSION = "0.1.1.dev3"
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):
@@ -69,9 +85,9 @@ class Evidence(_Data):
69
85
  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
- # Exact runtime identity keeps unpublished semantic readers from being guessed
73
- # compatible by numeric-prefix comparison (for example dev0 versus dev1).
74
- runtime_version: Literal["0.1.1.dev1"]
88
+ # Explicit reviewed reader compatibility, never a version-prefix/range guess.
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"]
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,13 @@ 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") in {"generated_kernel", "choice", "extract"}
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 != RUNTIME_VERSION:
168
+ raise ValueError
149
169
  if (
150
170
  digest({k: v for k, v in raw.items() if k != "manifest_digest"})
151
171
  != manifest.manifest_digest
@@ -178,6 +198,8 @@ def _parse(data: bytes) -> ArtifactManifest:
178
198
  raise ValueError
179
199
  if len(set(model.capabilities)) != len(model.capabilities):
180
200
  raise ValueError
201
+ for step in native:
202
+ validate_native_config(manifest.models[step.model], step.op, step.config)
181
203
  return manifest
182
204
  except ArtifactError:
183
205
  raise
@@ -196,6 +218,11 @@ def _bindings(manifest, bindings):
196
218
  if not isinstance(actual, ModelRequirements) or (
197
219
  actual.protocol != required.protocol
198
220
  or actual.revision != required.revision
221
+ or actual.upstream_model != required.upstream_model
222
+ or actual.native_profile != required.native_profile
223
+ or actual.native_max_levels != required.native_max_levels
224
+ or not set(required.native_modes) <= set(actual.native_modes)
225
+ or not set(required.native_answers) <= set(actual.native_answers)
199
226
  or actual.context_length < required.context_length
200
227
  # Omitted max_tokens preserves endpoint-default behavior, so an
201
228
  # enlarged endpoint output ceiling cannot silently enlarge the bound.
@@ -233,18 +260,21 @@ class Artifact:
233
260
 
234
261
  async def provider(model, payload):
235
262
  required = manifest.models[model]
236
- needed = {"chat"}
237
- if payload.get("tools"):
263
+ primitive = payload.get("primitive")
264
+ needed = {primitive["kind"]} if isinstance(primitive, dict) else {"chat"}
265
+ if not primitive and payload.get("tools"):
238
266
  needed.add("tools")
239
- if payload.get("response_format"):
267
+ if not primitive and payload.get("response_format"):
240
268
  needed.add("structured_output")
241
- if "primitive" in payload or not needed <= set(required.capabilities):
269
+ if not needed <= set(required.capabilities):
242
270
  raise ArtifactError("model_capability_mismatch")
271
+ if primitive:
272
+ native_request(required, payload)
243
273
  bounded, _, _ = resolve(
244
274
  payload,
245
275
  required,
246
276
  manifest.spec.output_token_policy,
247
- body=lambda value, _: value,
277
+ body=lambda value, _: native_request(required, value)[1] if primitive else value,
248
278
  estimator_for=lambda _: None,
249
279
  )
250
280
  try:
@@ -275,6 +305,10 @@ class Artifact:
275
305
  upstream_status=429 if exc.upstream_status == 429 else None,
276
306
  provider_dispatched=exc.provider_dispatched,
277
307
  ) from None
308
+ except ValueError as exc:
309
+ if str(exc) in NATIVE_CONTRACT_ERRORS | {"invalid_provider_output"}:
310
+ raise ValueError(str(exc)) from None
311
+ raise ArtifactError("execution_failed") from None
278
312
  except Exception:
279
313
  raise ArtifactError("execution_failed") from None
280
314
 
@@ -297,7 +331,12 @@ class Artifact:
297
331
  except asyncio.CancelledError:
298
332
  raise
299
333
  except Exception as exc:
300
- safe = {"token_limit", "context_unverified", "output_schema", "invalid_provider_output"}
334
+ safe = NATIVE_CONTRACT_ERRORS | {
335
+ "token_limit",
336
+ "context_unverified",
337
+ "output_schema",
338
+ "invalid_provider_output",
339
+ }
301
340
  code = (
302
341
  str(exc) if isinstance(exc, ValueError) and str(exc) in safe else "execution_failed"
303
342
  )