lex-llm-vertex 0.3.3 → 0.3.5
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +35 -0
- data/Gemfile +7 -2
- data/RULES.md +97 -0
- data/lex-llm-vertex.gemspec +4 -1
- data/lib/legion/extensions/llm/vertex/actors/discovery.rb +24 -0
- data/lib/legion/extensions/llm/vertex/{callable.rb → helpers/callable.rb} +51 -8
- data/lib/legion/extensions/llm/vertex/provider.rb +222 -376
- data/lib/legion/extensions/llm/vertex/runners/discovery.rb +232 -0
- data/lib/legion/extensions/llm/vertex/runners/fleet_worker.rb +5 -3
- data/lib/legion/extensions/llm/vertex/version.rb +1 -1
- data/lib/legion/extensions/llm/vertex.rb +13 -4
- metadata +7 -5
- data/lib/legion/extensions/llm/vertex/actors/discovery_refresh.rb +0 -646
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d4f8692faa325cfbd5b8d72ed00208dc1023d112a688f92d245efa8acb1e57b
|
|
4
|
+
data.tar.gz: 514f813574d1c555f4fd35374359e226b79f968ae2601992efb0861f15b2fd2d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fb6e60b85142ec54bf5d0bc637763e2ea78e4b028ba1d376965e5c2557199313ddeff19859b77c13f39957f6d92c5f3e2ae8478b316650299bc245d1469e0e0
|
|
7
|
+
data.tar.gz: ab51ecb1ef789105c321028408f31fd4094084f61d406f9693b948acae0693976f38a9225b36d86c7b3d6a1063e0fbd6d3f8f0bfe29bde42e5db51f5a9c31d41
|
data/.rubocop.yml
CHANGED
|
@@ -24,6 +24,10 @@ Metrics/PerceivedComplexity:
|
|
|
24
24
|
Enabled: false
|
|
25
25
|
Metrics/ClassLength:
|
|
26
26
|
Enabled: false
|
|
27
|
+
# default ModuleLength (100) is too strict for a discovery runner carrying the
|
|
28
|
+
# full evidence-building surface. Length is still bounded (Max 350).
|
|
29
|
+
Metrics/ModuleLength:
|
|
30
|
+
Max: 350
|
|
27
31
|
RSpec/MultipleExpectations:
|
|
28
32
|
Enabled: false
|
|
29
33
|
RSpec/ExampleLength:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.5] - 2026-08-20
|
|
4
|
+
|
|
5
|
+
0.8.0 conformance release against the lex-llm 0.8.0 contract cut.
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- Migrate the provider to the lex-llm 0.8.0 canonical contract: `chat`/`stream_chat` run through the base's single `complete` funnel (central `enforce_canonical_messages!` — the provider no longer re-implements the check), `render_payload` renders the Vertex wire FROM canonical values, `parse_completion_response` returns a `Canonical::Response`, and `build_chunk` yields `Canonical::Chunk` objects through the base `Streaming` module (real SSE chunk lifecycle ending in exactly one done chunk).
|
|
9
|
+
- Enforce the canonical dispatch boundary end to end: the callable's chat, stream_chat, and count_tokens operations keep the shared `Provider#enforce_canonical_messages!` call at the exact-execution boundary, and the base funnel enforces centrally before rendering — plain-Hash messages (the 2026-08-19 incident class) raise a loud ArgumentError at both boundaries, and the dual-shape render-seam tolerance (provider-native `Message` acceptance) is gone.
|
|
10
|
+
- `count_tokens` returns the provider's real `totalTokens` as an Integer and raises `NotImplementedError` for non-generateContent partner models (unsupported operations fail loud; the discovery writer publishes `:unsupported` operation evidence for them).
|
|
11
|
+
- `embed` returns the 0.8.0 documented artifact `{ text:, model:, embedding:, usage: Canonical::Usage }`.
|
|
12
|
+
- The provider's offering read path now serves activated inventory offerings from the SSOT registry snapshot (base `discover_offerings`, 07 C5); the discovery actor's writer remains the sole publication path.
|
|
13
|
+
- Raise the `lex-llm` dependency floor to 0.8.0.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Vertex wire `finishReason` spellings map to canonical stop reasons via `StopReasonMapping#stop_reason_map_additions`; sync responses and rawPredict partner responses carry `stop_reason`.
|
|
17
|
+
- Vertex `thought` parts surface as a canonical `Thinking` member (content + `thoughtSignature`) in sync responses and as `thinking_delta` chunks in streams, instead of being dropped.
|
|
18
|
+
- The fleet worker runner dispatches protocol-v3 exact-only envelopes against the SSOT registry (`ProviderResponder.call` with `registry:`).
|
|
19
|
+
- Conformance: the ssot_v3 spec runs the shared kit's B1 (central canonical enforcement) and B2 (canonical outputs, asserted by type) groups against the real callable boundary, and the raw-string model dispatch examples now feed canonical messages through the real render path.
|
|
20
|
+
- Keep a local-tree `lex-llm` path dependency in the test group so the adjacent checkout resolves against the unreleased 0.8.0 cut during development.
|
|
21
|
+
|
|
22
|
+
### Removed
|
|
23
|
+
- Legacy type construction in the parse paths: `Llm::Message` / `Llm::Chunk` / `Llm::ToolCall` from completion parsing, `Llm::Content` / `Llm::Content::Raw` handling in the content renderer, and `Llm::Embedding` from the embed path (replaced by `Canonical::*` types and the documented embedding artifact).
|
|
24
|
+
- The provider-native offering production path: the `discover_offerings` override, `offering_for` / `static_offerings` / `offering_from_live_model` / `offering_from_model` / `build_offering` (the `Routing::ModelOffering` production site), and the now-dead offering-feed helpers.
|
|
25
|
+
- The discovery actor's `Inventory::ScopedRefresher::LegacyCoordinatorAdapter` wiring (the file and the mixed-version window it served are deleted in lex-llm 0.8.0); the Publisher is a direct Registry wrapper.
|
|
26
|
+
|
|
27
|
+
## [0.3.4] - 2026-08-19
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Publish the validated four-axis lane-weight pair from every Vertex offering draft and reconcile weight-only changes atomically on the existing discovery cadence.
|
|
31
|
+
- Track initializing publications through readiness, serialize replacement/removal state, and report dormant configured weights without adding a Settings callback or operator workflow.
|
|
32
|
+
- Add callable-to-HTTP conformance coverage proving folded system messages render in Vertex's native `systemInstruction` field.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
- Validate startup offering weights before creating a callable or claiming its inventory scope, so malformed settings leave no untracked initializing publication and the next valid cadence pass recovers without operator action.
|
|
36
|
+
- Pin the raw-`Data` comparison exception with real-cadence regressions: frozen static catalog order and the per-instance evidence timestamp keep unchanged passes stable, while every authoritative draft member and duplicate-count change remains significant.
|
|
37
|
+
|
|
3
38
|
## [0.3.3] - 2026-08-18
|
|
4
39
|
|
|
5
40
|
### Fixed
|
data/Gemfile
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
|
-
gem 'lex-llm'
|
|
6
|
-
|
|
7
5
|
gemspec
|
|
8
6
|
|
|
7
|
+
# Local-tree resolution: use the adjacent lex-llm checkout when present so the
|
|
8
|
+
# 0.8.0 conformance work resolves against the unreleased 0.8.0 cut.
|
|
9
|
+
group :test do
|
|
10
|
+
lex_llm_path = File.expand_path('../lex-llm', __dir__)
|
|
11
|
+
gem 'lex-llm', path: lex_llm_path if Dir.exist?(lex_llm_path)
|
|
12
|
+
end
|
|
13
|
+
|
|
9
14
|
group :development do
|
|
10
15
|
gem 'bundler', '>= 2.0'
|
|
11
16
|
gem 'rake', '>= 13.0'
|
data/RULES.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
RULES.md — Legion LLM Architecture Law
|
|
2
|
+
These rules apply to every task, file, repository, agent, model, session, test, refactor, migration, incident, and release.
|
|
3
|
+
The requested task defines what may change. These rules define how the system ALWAYS works.
|
|
4
|
+
Every rule remains active 100% of the time. If requested work conflicts with these rules, stop and surface the conflict before changing code.
|
|
5
|
+
These are architecture laws. Scope, compatibility, urgency, convenience, tests, existing behavior, and model judgment do not change them.
|
|
6
|
+
1. Canonical is the only internal language.
|
|
7
|
+
Every client translates client wire -> Canonical before shared execution.
|
|
8
|
+
Shared execution carries Canonical through context, tools, routing, direct dispatch, fleet dispatch, and response handling.
|
|
9
|
+
Every provider translates Canonical -> provider wire at the provider boundary, then provider wire -> Canonical before returning to shared execution.
|
|
10
|
+
Every internal boundary validates the Canonical type it is defined to receive and raises immediately when that contract is violated.
|
|
11
|
+
Client Wire -> Client Translator -> Canonical -> Shared Execution -> Canonical -> Provider Translator -> Provider Wire.
|
|
12
|
+
2. Serialization preserves Canonical.
|
|
13
|
+
Transport may serialize Canonical state. The receiving transport boundary ALWAYS rehydrates the exact Canonical type before execution continues.
|
|
14
|
+
Fleet follows Canonical -> serialize -> wire -> deserialize -> rehydrate Canonical -> Canonical.
|
|
15
|
+
Serialization changes encoding only. Ownership, identity, model, operation, capability, selection, and meaning remain exactly the same.
|
|
16
|
+
After rehydration, shared execution continues only with Canonical objects.
|
|
17
|
+
3. Every authoritative fact has exactly one owner.
|
|
18
|
+
The owner creates the fact once. Every downstream layer carries, projects, serializes, rehydrates, verifies, or executes that exact fact.
|
|
19
|
+
A downstream layer receiving missing or contradictory authoritative state raises and returns the defect to the owning layer.
|
|
20
|
+
Authority ALWAYS moves forward by preservation.
|
|
21
|
+
Authority is created once and is never recreated downstream.
|
|
22
|
+
4. Requirements describe the request. Inventory describes reality. Router chooses. Dispatch executes.
|
|
23
|
+
Canonical request construction owns request semantics. RequestRequirements expresses operation, capabilities, modality, context, output, tools, and explicit pins.
|
|
24
|
+
Providers publish exact executable facts into Inventory. Inventory owns canonical instance, offering, lane, capability, context, quota, health, and published weight state.
|
|
25
|
+
Router.next_lane consumes Requirements plus one immutable Inventory snapshot and produces one authoritative Selection.
|
|
26
|
+
Dispatch executes that Selection exactly. Once Selection exists, routing is finished.
|
|
27
|
+
5. Inventory facts are immutable executable facts.
|
|
28
|
+
Providers publish exact instances and complete offering snapshots through the Inventory publication contract.
|
|
29
|
+
Identity, capability evidence, context evidence, quota domains, availability, and write-time weights are consumed from published Inventory state.
|
|
30
|
+
A changed fact becomes authoritative only through the owning publication or reconciliation path and a new Inventory snapshot.
|
|
31
|
+
Routing reads Inventory. Dispatch verifies and executes Inventory-backed Selection.
|
|
32
|
+
6. Identity, capabilities, weights, and context policy retain exact ownership.
|
|
33
|
+
Inventory::Identity owns instance, offering, and lane identity; canonical instance identity is provider family plus the operator/configured instance name; physical endpoint data remains secondary.
|
|
34
|
+
Providers publish capability evidence. Requirements state required capabilities. Candidate evaluation compares the two and determines capability eligibility.
|
|
35
|
+
The weight owner computes lane weight at publication time; Inventory stores it; ranking consumes that stored weight; a stored zero disables the lane.
|
|
36
|
+
Preferred-context binning orders eligible candidates into preference bands and preserves eligibility. Capability, health, binning, and weight ALWAYS retain distinct meanings.
|
|
37
|
+
7. Routing chooses exactly once.
|
|
38
|
+
Router.next_lane is the sole routing authority.
|
|
39
|
+
Candidate evaluation determines eligibility from Requirements and Inventory. Ranking orders eligible candidates from published routing facts.
|
|
40
|
+
Selection freezes the exact provider, instance, offering, lane, model, operation, and routing identity required for execution.
|
|
41
|
+
Every downstream component consumes the Selection it receives.
|
|
42
|
+
Selection is preserved, not reconstructed.
|
|
43
|
+
8. Exact execution stays exact through every boundary.
|
|
44
|
+
Direct dispatch executes the exact Selection-derived binding it receives.
|
|
45
|
+
Fleet dispatch serializes and signs that exact binding; fleet validation verifies it; fleet rehydration restores it; worker resolution verifies it against authoritative Inventory.
|
|
46
|
+
The selected provider, instance, offering, lane, model, and operation remain identical through projection, signing, transport, validation, rehydration, resolution, and callable invocation.
|
|
47
|
+
A mismatch raises before provider execution.
|
|
48
|
+
An exact execution request ALWAYS remains exact execution.
|
|
49
|
+
9. Health and errors preserve one authoritative meaning.
|
|
50
|
+
Inventory owns exact-instance availability. An authoritative instance-unavailable result removes that exact instance; readiness probing owns recovery; successful readiness republish re-admits it.
|
|
51
|
+
Overload, timeout, rate limit, model-not-ready, and transient provider failures remain request-local according to ProviderOutcome semantics.
|
|
52
|
+
The first layer that can authoritatively classify an error performs that classification once. Every downstream layer preserves it.
|
|
53
|
+
Programming errors remain programming errors. Contract violations remain contract violations. Routing exhaustion remains the defined typed Rejection.
|
|
54
|
+
10. Compatibility exists only at explicit edges.
|
|
55
|
+
Supported legacy clients and protocols are translated into the current Canonical and SSOT architecture at explicit compatibility boundaries.
|
|
56
|
+
Shared execution remains Canonical. Routing remains SSOT-driven. Exact execution remains exact.
|
|
57
|
+
Compatibility code adapts an external contract to the current internal architecture.
|
|
58
|
+
The current internal architecture ALWAYS has one representation, one routing authority, one identity system, and one execution truth.
|
|
59
|
+
11. Fix every defect at its owner.
|
|
60
|
+
Trace the incorrect value to the layer that owns it, then fix that owner.
|
|
61
|
+
Fix client wire in the client translator; Canonical shape in Canonical construction; Requirements in Requirements construction; provider facts in publication; identity in Inventory identity; weights in publication/reconciliation.
|
|
62
|
+
Fix eligibility in candidate evaluation; ordering in ranking; choice in Router.next_lane; execution preservation in dispatch; provider wire in the provider translator.
|
|
63
|
+
The layer where a defect becomes visible is evidence. The owning layer is where the correction belongs.
|
|
64
|
+
12. A discovered issue remains in its owning domain.
|
|
65
|
+
Complete the requested task inside its stated scope.
|
|
66
|
+
When investigation exposes a separate defect owned by another architectural domain, record and surface it as separate work unless the requested task is explicitly expanded.
|
|
67
|
+
Routing work consumes existing Canonical Requirements and Inventory facts. Canonical work changes Canonical contracts. Provider work changes publication or translation. Transport work changes transport.
|
|
68
|
+
Nearby code never changes ownership. “While we are here” never changes architecture.
|
|
69
|
+
13. N x N ALWAYS converges through Canonical.
|
|
70
|
+
Equivalent client semantics produce equivalent Canonical state before shared execution. Every provider consumes the same Canonical semantics for the same request.
|
|
71
|
+
When two paths disagree, capture the state at every involved boundary and locate the FIRST point where Canonical meaning diverges.
|
|
72
|
+
Fix that first divergent boundary, then run the exact failing path again.
|
|
73
|
+
Client behavior is proven at client-wire <-> Canonical. Provider behavior is proven at Canonical <-> provider-wire. Shared execution is proven with Canonical throughout.
|
|
74
|
+
14. Debug from captured authoritative state.
|
|
75
|
+
Capture the actual input at the failing boundary before reasoning from symptoms.
|
|
76
|
+
For translation or transport defects, capture Canonical immediately before and after every involved boundary.
|
|
77
|
+
For routing or dispatch defects, capture Requirements, relevant Inventory facts, Selection, execution binding, and ProviderOutcome.
|
|
78
|
+
Compare each captured value to the contract owned by that layer. Find the first divergence. Fix its owner. Re-run the exact path.
|
|
79
|
+
Then inspect sibling implementations for the same defect class.
|
|
80
|
+
15. Tests prove the real boundary and the invariant.
|
|
81
|
+
A boundary test exercises the real boundary it claims to protect.
|
|
82
|
+
Fleet tests exercise real serialization, deserialization, Canonical rehydration, signing, validation, exact resolution, and callable dispatch.
|
|
83
|
+
Provider tests exercise the real callable boundary and provider translator. Routing tests exercise real Requirements, Inventory records, candidate evaluation, ranking, and Selection.
|
|
84
|
+
Regression tests prove the violated invariant, not only the observed symptom.
|
|
85
|
+
A green suite is release evidence only when the tested path traverses the real architecture.
|
|
86
|
+
16. Shared contracts are consumed directly.
|
|
87
|
+
Shared Canonical types own execution representation. Shared Inventory types own inventory state. Shared Routing types own routing state.
|
|
88
|
+
Shared taxonomy owns canonical mappings. Shared ProviderOutcome owns provider-neutral outcomes. Shared fleet protocol owns exact execution claims.
|
|
89
|
+
Every repository consumes these shared owners directly.
|
|
90
|
+
A defect in one shared boundary triggers an audit of every sibling implementation of that boundary. Fix the shared owner centrally whenever the defect belongs to a shared contract.
|
|
91
|
+
17. Architecture is the release gate.
|
|
92
|
+
Every change preserves every rule in this file.
|
|
93
|
+
Tests, compatibility, historical behavior, migration phase, patch urgency, nearby code, task wording, and model judgment are evaluated UNDER these rules.
|
|
94
|
+
A contradiction between existing behavior and these rules is surfaced as an architecture conflict and resolved at the owning boundary before release.
|
|
95
|
+
Limited scope means do less. Limited scope NEVER means fewer rules apply.
|
|
96
|
+
These rules apply 100% of the time.
|
|
97
|
+
These are the law.
|
data/lex-llm-vertex.gemspec
CHANGED
|
@@ -27,5 +27,8 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.add_dependency 'legion-logging', '>= 1.3.2'
|
|
28
28
|
spec.add_dependency 'legion-settings', '>= 1.4.2'
|
|
29
29
|
spec.add_dependency 'legion-transport', '>= 1.4.14'
|
|
30
|
-
|
|
30
|
+
# 0.8.0 is the canonical contract cut: base complete funnel with central
|
|
31
|
+
# canonical enforcement, Canonical::* types, SSOT registry writer path, and
|
|
32
|
+
# the fleet v3 exact-execution responder the two-file wiring dispatches to.
|
|
33
|
+
spec.add_dependency 'lex-llm', '>= 0.8.0'
|
|
31
34
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/llm/discovery/actor'
|
|
4
|
+
|
|
5
|
+
# The base discovery actor only exists inside the daemon (it inherits the
|
|
6
|
+
# LegionIO time-based Every actor). In a standalone load, define nothing.
|
|
7
|
+
return unless defined?(Legion::Extensions::Llm::Discovery::Actor)
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Llm
|
|
12
|
+
module Vertex
|
|
13
|
+
module Actor
|
|
14
|
+
# Vertex discovery actor: an EMPTY subclass of the shared base. The
|
|
15
|
+
# timer, dispatch, and runner-resolution convention are inherited — this
|
|
16
|
+
# class redefines nothing. The Vertex-specific work lives in
|
|
17
|
+
# Vertex::Runners::Discovery, resolved by the base from this
|
|
18
|
+
# namespace.
|
|
19
|
+
class Discovery < Legion::Extensions::Llm::Discovery::Actor; end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -8,14 +8,27 @@ module Legion
|
|
|
8
8
|
module Extensions
|
|
9
9
|
module Llm
|
|
10
10
|
module Vertex
|
|
11
|
-
module
|
|
11
|
+
module Helpers
|
|
12
12
|
# Callable wrapper for a Vertex AI provider instance. Delegates the
|
|
13
13
|
# fleet dispatch operations to a per-instance Vertex::Provider (real
|
|
14
14
|
# HTTP dispatch; provider/Faraday errors propagate so
|
|
15
15
|
# normalize_dispatch_error classifies them) and implements the
|
|
16
16
|
# `disconnect` and `normalize_dispatch_error(error:)` contracts
|
|
17
17
|
# required by Inventory::CallableHandle and Routing::ProviderOutcome.
|
|
18
|
-
|
|
18
|
+
# 0.8.0 callable contract: chat/stream_chat take the rehydrated
|
|
19
|
+
# message array positionally (WorkerExecution dispatch shape) and
|
|
20
|
+
# the Selection-derived model as a bare String; folded wire params
|
|
21
|
+
# become Canonical::Params at this boundary (05 O4).
|
|
22
|
+
class Callable
|
|
23
|
+
# Keys the base Provider exposes as named kwargs for the
|
|
24
|
+
# completion operations. Anything else the fleet passes (sampling
|
|
25
|
+
# scalars, `temperature` — a Canonical::Params member, 05 O4) is
|
|
26
|
+
# folded into Canonical::Params at the dispatch boundary.
|
|
27
|
+
COMPLETION_NAMED_KEYS = %i[tools schema thinking tool_prefs headers].freeze
|
|
28
|
+
# Named kwargs of Vertex's own embed dialect (task_type/title are
|
|
29
|
+
# Vertex wire spellings); anything else folds into params.
|
|
30
|
+
EMBED_NAMED_KEYS = %i[dimensions task_type title headers].freeze
|
|
31
|
+
|
|
19
32
|
attr_reader :provider
|
|
20
33
|
|
|
21
34
|
def initialize(instance_cfg:, logger:)
|
|
@@ -37,20 +50,30 @@ module Legion
|
|
|
37
50
|
|
|
38
51
|
# --- Fleet dispatch operations (Fleet::WorkerExecution contract) --
|
|
39
52
|
|
|
40
|
-
def chat(messages
|
|
41
|
-
|
|
53
|
+
def chat(messages, model:, **rest)
|
|
54
|
+
# Canonical boundary (N x N law): pipeline dispatch delivers
|
|
55
|
+
# Canonical::Message objects only. Hash/legacy shapes are the
|
|
56
|
+
# bypass class — reject loudly, never coerce.
|
|
57
|
+
provider.enforce_canonical_messages!(messages)
|
|
58
|
+
named, params = split_fleet_kwargs(rest, COMPLETION_NAMED_KEYS)
|
|
59
|
+
provider.chat(messages, model: model, params: canonical_params(params), **named)
|
|
42
60
|
end
|
|
43
61
|
|
|
44
|
-
def stream_chat(messages
|
|
45
|
-
provider.
|
|
62
|
+
def stream_chat(messages, model:, **rest, &)
|
|
63
|
+
provider.enforce_canonical_messages!(messages)
|
|
64
|
+
named, params = split_fleet_kwargs(rest, COMPLETION_NAMED_KEYS)
|
|
65
|
+
provider.stream_chat(messages, model: model, params: canonical_params(params), **named, &)
|
|
46
66
|
end
|
|
47
67
|
|
|
48
68
|
def embed(text:, model:, **rest)
|
|
49
|
-
|
|
69
|
+
named, params = split_fleet_kwargs(rest, EMBED_NAMED_KEYS)
|
|
70
|
+
provider.embed(text: text, model: model, params: params, **named)
|
|
50
71
|
end
|
|
51
72
|
|
|
52
73
|
def count_tokens(messages:, model:, **rest)
|
|
53
|
-
provider.
|
|
74
|
+
provider.enforce_canonical_messages!(messages)
|
|
75
|
+
_named, params = split_fleet_kwargs(rest, [])
|
|
76
|
+
provider.count_tokens(messages: messages, model: model, params: params)
|
|
54
77
|
end
|
|
55
78
|
|
|
56
79
|
# --- Error normalization ------------------------------------------
|
|
@@ -83,6 +106,26 @@ module Legion
|
|
|
83
106
|
|
|
84
107
|
private
|
|
85
108
|
|
|
109
|
+
# The 0.8.0 completion funnel receives canonical values only
|
|
110
|
+
# (08 F3): the folded wire params become a Canonical::Params at
|
|
111
|
+
# the dispatch boundary — temperature is a params member (05 O4),
|
|
112
|
+
# never a kwarg. A canonical Params already in flight round-trips
|
|
113
|
+
# through from_hash Data-equal (kit T3/T7); unknown keys fold into
|
|
114
|
+
# params metadata (04 L5), never dropped or raised.
|
|
115
|
+
def canonical_params(params)
|
|
116
|
+
Legion::Extensions::Llm::Canonical::Params.from_hash(params)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Split the fleet's **rest into the provider's named kwargs and a
|
|
120
|
+
# payload params hash (any passed :params merged with the unknown
|
|
121
|
+
# keys — sampling scalars, temperature, 0.7.x spellings).
|
|
122
|
+
def split_fleet_kwargs(rest, named_keys)
|
|
123
|
+
named = rest.slice(*named_keys)
|
|
124
|
+
extra = rest.reject { |key, _| named.key?(key) }
|
|
125
|
+
params = (extra.delete(:params) || {}).to_h.merge(extra)
|
|
126
|
+
[named, params]
|
|
127
|
+
end
|
|
128
|
+
|
|
86
129
|
def classify_client_error(error:)
|
|
87
130
|
case error.response_status
|
|
88
131
|
when 401 then :authentication
|