lex-llm 0.6.15 → 0.7.0
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/CHANGELOG.md +19 -0
- data/lib/legion/extensions/llm/auto_registration.rb +3 -0
- data/lib/legion/extensions/llm/fleet/protocol.rb +12 -0
- data/lib/legion/extensions/llm/fleet/provider_responder.rb +40 -5
- data/lib/legion/extensions/llm/fleet/token_validator.rb +15 -0
- data/lib/legion/extensions/llm/fleet/worker_execution.rb +166 -2
- data/lib/legion/extensions/llm/inventory/callable_handle.rb +144 -0
- data/lib/legion/extensions/llm/inventory/errors.rb +34 -0
- data/lib/legion/extensions/llm/inventory/evidence.rb +134 -0
- data/lib/legion/extensions/llm/inventory/identity.rb +119 -0
- data/lib/legion/extensions/llm/inventory/immutable_value.rb +96 -0
- data/lib/legion/extensions/llm/inventory/probe_coordinator.rb +117 -0
- data/lib/legion/extensions/llm/inventory/probe_token.rb +146 -0
- data/lib/legion/extensions/llm/inventory/publisher.rb +110 -0
- data/lib/legion/extensions/llm/inventory/records.rb +592 -0
- data/lib/legion/extensions/llm/inventory/registry.rb +636 -0
- data/lib/legion/extensions/llm/inventory/scoped_refresher.rb +206 -0
- data/lib/legion/extensions/llm/inventory/snapshot.rb +91 -0
- data/lib/legion/extensions/llm/provider.rb +43 -0
- data/lib/legion/extensions/llm/routing/lane_key.rb +4 -0
- data/lib/legion/extensions/llm/routing/model_offering.rb +3 -0
- data/lib/legion/extensions/llm/routing/offering_registry.rb +2 -0
- data/lib/legion/extensions/llm/routing/provider_outcome.rb +54 -0
- data/lib/legion/extensions/llm/routing/records.rb +288 -0
- data/lib/legion/extensions/llm/stream_accumulator.rb +17 -4
- data/lib/legion/extensions/llm/taxonomies.rb +90 -0
- data/lib/legion/extensions/llm/tool_call.rb +7 -2
- data/lib/legion/extensions/llm/transport/messages/fleet_error.rb +3 -1
- data/lib/legion/extensions/llm/transport/messages/fleet_response.rb +3 -1
- data/lib/legion/extensions/llm/version.rb +1 -1
- data/lib/legion/extensions/llm.rb +15 -0
- data/spec/legion/extensions/llm/conformance/fixtures/ssot_identity_vectors.json +84 -0
- data/spec/legion/extensions/llm/conformance/ssot_provider_conformance_spec.rb +13 -0
- data/spec/legion/extensions/llm/conformance/ssot_provider_examples.rb +196 -0
- data/spec/legion/extensions/llm/fleet/exact_offering_spec.rb +179 -0
- data/spec/legion/extensions/llm/fleet/provider_responder_spec.rb +26 -0
- data/spec/legion/extensions/llm/fleet_messages_spec.rb +14 -0
- data/spec/legion/extensions/llm/inventory/boot_spec.rb +80 -0
- data/spec/legion/extensions/llm/inventory/callable_handle_spec.rb +127 -0
- data/spec/legion/extensions/llm/inventory/evidence_spec.rb +125 -0
- data/spec/legion/extensions/llm/inventory/identity_spec.rb +227 -0
- data/spec/legion/extensions/llm/inventory/immutable_value_spec.rb +132 -0
- data/spec/legion/extensions/llm/inventory/probe_coordinator_spec.rb +107 -0
- data/spec/legion/extensions/llm/inventory/probe_token_spec.rb +107 -0
- data/spec/legion/extensions/llm/inventory/publisher_spec.rb +104 -0
- data/spec/legion/extensions/llm/inventory/records_spec.rb +300 -0
- data/spec/legion/extensions/llm/inventory/registry_activation_spec.rb +140 -0
- data/spec/legion/extensions/llm/inventory/registry_availability_spec.rb +152 -0
- data/spec/legion/extensions/llm/inventory/registry_callable_spec.rb +63 -0
- data/spec/legion/extensions/llm/inventory/registry_replacement_spec.rb +69 -0
- data/spec/legion/extensions/llm/inventory/scoped_refresher_spec.rb +128 -0
- data/spec/legion/extensions/llm/inventory/snapshot_spec.rb +109 -0
- data/spec/legion/extensions/llm/provider_contract_spec.rb +20 -0
- data/spec/legion/extensions/llm/provider_spec.rb +83 -0
- data/spec/legion/extensions/llm/routing/provider_outcome_spec.rb +59 -0
- data/spec/legion/extensions/llm/routing/records_spec.rb +173 -0
- data/spec/legion/extensions/llm/taxonomies_spec.rb +51 -0
- data/spec/support/fake_llm_provider.rb +11 -0
- data/spec/support/fake_ssot_harness.rb +137 -0
- data/spec/support/ssot_registry_helpers.rb +75 -0
- metadata +36 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'legion/extensions/llm/routing/provider_outcome'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Legion::Extensions::Llm::Routing::ProviderOutcome do
|
|
7
|
+
inventory = Legion::Extensions::Llm::Inventory
|
|
8
|
+
routing = Legion::Extensions::Llm::Routing
|
|
9
|
+
errors = inventory::Errors
|
|
10
|
+
|
|
11
|
+
it 'builds a normalized outcome for each canonical kind' do
|
|
12
|
+
outcome = described_class.new(kind: :success, reason: 'ok')
|
|
13
|
+
expect(outcome.kind).to eq(:success)
|
|
14
|
+
expect(outcome.metadata).to be_frozen
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'rejects a kind outside PROVIDER_OUTCOMES' do
|
|
18
|
+
expect { described_class.new(kind: :made_up, reason: 'x') }.to raise_error(errors::ValidationError)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'has no HTTP status field: 503/529 cannot be an input' do
|
|
22
|
+
expect(described_class.members).not_to include(:http_status, :status_code)
|
|
23
|
+
expect(described_class.new(kind: :overloaded, reason: '503 overloaded').kind).to eq(:overloaded)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'never manufactures instance_unavailable from a raw status; only an explicit kind does' do
|
|
27
|
+
# An adapter that received HTTP 503 overload constructs :overloaded, not :instance_unavailable.
|
|
28
|
+
overloaded = described_class.new(kind: :overloaded, reason: 'HTTP 503 overloaded')
|
|
29
|
+
expect(overloaded.kind).not_to eq(:instance_unavailable)
|
|
30
|
+
# instance_unavailable exists only when an adapter explicitly constructs that kind.
|
|
31
|
+
explicit = described_class.new(kind: :instance_unavailable, reason: 'service unavailable')
|
|
32
|
+
expect(explicit.kind).to eq(:instance_unavailable)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'allows a quota_domain only for rate_limited' do
|
|
36
|
+
domain = routing::QuotaDomainKey.new(provider_family: 'vllm', opaque_id: 'q1')
|
|
37
|
+
expect(described_class.new(kind: :rate_limited, reason: 'quota', quota_domain: domain).quota_domain).to eq(domain)
|
|
38
|
+
expect { described_class.new(kind: :timeout, reason: 'x', quota_domain: domain) }
|
|
39
|
+
.to raise_error(errors::ValidationError)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'requires quota_domain to be a QuotaDomainKey' do
|
|
43
|
+
expect { described_class.new(kind: :rate_limited, reason: 'x', quota_domain: 'q1') }
|
|
44
|
+
.to raise_error(errors::ValidationError)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'accepts a finite nonnegative retry_after and rejects negatives/infinity' do
|
|
48
|
+
expect(described_class.new(kind: :rate_limited, reason: 'x', retry_after: 1.5).retry_after).to eq(1.5)
|
|
49
|
+
expect { described_class.new(kind: :rate_limited, reason: 'x', retry_after: -1) }
|
|
50
|
+
.to raise_error(errors::ValidationError)
|
|
51
|
+
expect { described_class.new(kind: :rate_limited, reason: 'x', retry_after: (1.0 / 0.0)) }
|
|
52
|
+
.to raise_error(errors::ValidationError)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'rejects secret metadata' do
|
|
56
|
+
expect { described_class.new(kind: :success, reason: 'ok', metadata: { api_key: 'x' }) }
|
|
57
|
+
.to raise_error(errors::ValidationError)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'legion/extensions/llm/routing/records'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Legion::Extensions::Llm::Routing::Records do
|
|
7
|
+
inventory = Legion::Extensions::Llm::Inventory
|
|
8
|
+
routing = Legion::Extensions::Llm::Routing
|
|
9
|
+
errors = inventory::Errors
|
|
10
|
+
identity = inventory::Identity
|
|
11
|
+
|
|
12
|
+
let(:callable_class) do
|
|
13
|
+
Class.new do
|
|
14
|
+
def disconnect; end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
let(:callable_handle) { inventory::CallableHandle.new(handle_id: 'call:v1:x', callable: callable_class.new) }
|
|
18
|
+
let(:instance_key) { identity::InstanceKey.new(provider_family: 'vllm', instance_id: 'h200') }
|
|
19
|
+
let(:offering_id) { identity.offering_id(instance_key: instance_key, provider_native_key: 'gemma4') }
|
|
20
|
+
let(:lane_id) do
|
|
21
|
+
identity.lane_id(instance_key: instance_key, operation: :chat, model: 'gemma4', offering_id: offering_id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe routing::AttemptTargetKey do
|
|
25
|
+
it 'treats the same model on two instances as distinct keys' do
|
|
26
|
+
a = described_class.new(provider_family: 'vllm', instance_id: 'h200', model: 'gemma4')
|
|
27
|
+
b = described_class.new(provider_family: 'vllm', instance_id: 'helios1', model: 'gemma4')
|
|
28
|
+
expect(a).not_to eq(b)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'is value-equal for equal normalized fields and hashes equally' do
|
|
32
|
+
a = described_class.new(provider_family: 'vllm', instance_id: 'h200', model: 'gemma4')
|
|
33
|
+
b = described_class.new(provider_family: :vllm, instance_id: ' h200 ', model: 'gemma4')
|
|
34
|
+
expect(a).to eq(b)
|
|
35
|
+
expect(a.hash).to eq(b.hash)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'contains only provider_family, instance_id, and model' do
|
|
39
|
+
key = described_class.new(provider_family: 'vllm', instance_id: 'h200', model: 'gemma4')
|
|
40
|
+
expect(key.to_h.keys).to contain_exactly(:provider_family, :instance_id, :model)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe routing::QuotaDomainKey do
|
|
45
|
+
it 'never compares equal across provider families' do
|
|
46
|
+
a = described_class.new(provider_family: 'vllm', opaque_id: 'q1')
|
|
47
|
+
b = described_class.new(provider_family: 'openai', opaque_id: 'q1')
|
|
48
|
+
expect(a).not_to eq(b)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe routing::Exclusion do
|
|
53
|
+
it 'requires the target class to match the target_kind' do
|
|
54
|
+
expect do
|
|
55
|
+
described_class.new(target_kind: :instance, target: instance_key, reason: 'x', evidence: {}, lifetime: :request)
|
|
56
|
+
end.not_to raise_error
|
|
57
|
+
expect do
|
|
58
|
+
described_class.new(target_kind: :instance, target: 'nope', reason: 'x', evidence: {}, lifetime: :request)
|
|
59
|
+
end.to raise_error(errors::ValidationError)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'normalizes a provider target to a canonical Symbol' do
|
|
63
|
+
exclusion = described_class.new(target_kind: :provider, target: 'VLLM', reason: 'x', evidence: {}, lifetime: :request)
|
|
64
|
+
expect(exclusion.target).to eq(:vllm)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'freezes evidence and rejects an invalid lifetime' do
|
|
68
|
+
exclusion = described_class.new(target_kind: :model, target: 'gemma4', reason: 'x', evidence: { a: 1 }, lifetime: :attempt_group)
|
|
69
|
+
expect(exclusion.evidence).to be_frozen
|
|
70
|
+
expect do
|
|
71
|
+
described_class.new(target_kind: :model, target: 'gemma4', reason: 'x', evidence: {}, lifetime: :forever)
|
|
72
|
+
end.to raise_error(errors::ValidationError)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe routing::Selection do
|
|
77
|
+
def build_selection(**overrides)
|
|
78
|
+
Legion::Extensions::Llm::Routing::Selection.new(
|
|
79
|
+
inventory_generation: 7, lane_id: lane_id, instance_key: instance_key, offering_id: offering_id,
|
|
80
|
+
provider_family: :vllm, instance_id: 'h200', model: 'gemma4', operation: :chat,
|
|
81
|
+
callable_handle: callable_handle, publisher_token_id: 'ptok:v1:abc', capability_evidence: {},
|
|
82
|
+
context_evidence: Legion::Extensions::Llm::Inventory::ValueEvidence.new(status: :unknown, source: :absent),
|
|
83
|
+
weight_inputs: { tier: 2, provider: 3, instance: 5, model_or_offering: 7 },
|
|
84
|
+
base_weight: 210, preference_ppm: 1_000_000, effective_weight: 210_000_000,
|
|
85
|
+
rendezvous_score: 12_345, **overrides
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'builds a valid selection and derives the attempt target key' do
|
|
90
|
+
selection = build_selection
|
|
91
|
+
key = selection.attempt_target_key
|
|
92
|
+
expect(key).to eq(routing::AttemptTargetKey.new(provider_family: :vllm, instance_id: 'h200', model: 'gemma4'))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'requires base_weight to equal the product of weight_inputs' do
|
|
96
|
+
expect { build_selection(base_weight: 211) }.to raise_error(errors::ValidationError)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'requires effective_weight to equal base_weight * preference_ppm' do
|
|
100
|
+
expect { build_selection(effective_weight: 1) }.to raise_error(errors::ValidationError)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'bounds preference_ppm to 500_000..1_500_000' do
|
|
104
|
+
expect { build_selection(preference_ppm: 400_000, effective_weight: 210 * 400_000) }
|
|
105
|
+
.to raise_error(errors::ValidationError)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'rejects a lane_id that does not reproduce' do
|
|
109
|
+
expect { build_selection(lane_id: "lane:v1:#{'0' * 64}") }.to raise_error(errors::ValidationError)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'rejects a publisher_token_id without the ptok:v1: prefix' do
|
|
113
|
+
expect { build_selection(publisher_token_id: 'nope') }.to raise_error(errors::ValidationError)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'freezes weight_inputs' do
|
|
117
|
+
expect(build_selection.weight_inputs).to be_frozen
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe routing::Rejection do
|
|
122
|
+
def build_rejection(**overrides)
|
|
123
|
+
Legion::Extensions::Llm::Routing::Rejection.new(
|
|
124
|
+
kind: :too_early, reason: 'initializing', inventory_generation: 0, candidate_counts: { eligible: 0 }, **overrides
|
|
125
|
+
)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'validates kind and freezes candidate_counts' do
|
|
129
|
+
rejection = build_rejection
|
|
130
|
+
expect(rejection.candidate_counts).to be_frozen
|
|
131
|
+
expect { build_rejection(kind: :made_up) }.to raise_error(errors::ValidationError)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'rejects candidate_counts with non-Symbol keys or negative values' do
|
|
135
|
+
expect { build_rejection(candidate_counts: { 'x' => 1 }) }.to raise_error(errors::ValidationError)
|
|
136
|
+
expect { build_rejection(candidate_counts: { eligible: -1 }) }.to raise_error(errors::ValidationError)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'allows only provider/instance/model/tier explicit pins' do
|
|
140
|
+
expect { build_rejection(explicit_pins: { provider: 'vllm', tier: 'local' }) }.not_to raise_error
|
|
141
|
+
expect { build_rejection(explicit_pins: { secret: 'x' }) }.to raise_error(errors::ValidationError)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'bounds http_status to 100..599' do
|
|
145
|
+
expect { build_rejection(http_status: 700) }.to raise_error(errors::ValidationError)
|
|
146
|
+
expect(build_rejection(http_status: 503).http_status).to eq(503)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe routing::BodyModelHintDecision do
|
|
151
|
+
it 'allows only honored to carry a model_constraint' do
|
|
152
|
+
expect do
|
|
153
|
+
described_class.new(
|
|
154
|
+
requested_model: 'gemma4', disposition: :honored, model_constraint: 'gemma4', settings_generation: 1
|
|
155
|
+
)
|
|
156
|
+
end.not_to raise_error
|
|
157
|
+
expect do
|
|
158
|
+
described_class.new(
|
|
159
|
+
requested_model: 'gemma4', disposition: :auto, model_constraint: 'gemma4', settings_generation: 1
|
|
160
|
+
)
|
|
161
|
+
end.to raise_error(errors::ValidationError)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'requires absent to carry a nil requested_model' do
|
|
165
|
+
expect do
|
|
166
|
+
described_class.new(requested_model: 'gemma4', disposition: :absent, settings_generation: 1)
|
|
167
|
+
end.to raise_error(errors::ValidationError)
|
|
168
|
+
expect do
|
|
169
|
+
described_class.new(requested_model: nil, disposition: :absent, settings_generation: 1)
|
|
170
|
+
end.not_to raise_error
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
@@ -25,4 +25,55 @@ RSpec.describe Legion::Extensions::Llm::Taxonomies do
|
|
|
25
25
|
expect(described_class::TYPES).to be_frozen
|
|
26
26
|
expect(described_class::CIRCUIT_STATES).to be_frozen
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
describe 'SSOT v3 enums' do
|
|
30
|
+
it 'OPERATIONS contains exactly the nine canonical operations' do
|
|
31
|
+
expect(described_class::OPERATIONS).to eq(
|
|
32
|
+
%i[chat stream_chat embed image transcribe translate speak moderate count_tokens]
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'freezes every SSOT enum constant' do
|
|
37
|
+
%i[
|
|
38
|
+
OPERATIONS CAPABILITY_EVIDENCE_STATES OPERATION_EVIDENCE_STATES VALUE_EVIDENCE_STATES
|
|
39
|
+
AVAILABILITY_STATES AVAILABILITY_SOURCES PROBE_OUTCOMES PUBLICATION_STATES CALLABLE_STATES
|
|
40
|
+
MUTATION_REASONS PROVIDER_OUTCOMES REJECTION_KINDS EXCLUSION_TARGET_KINDS EXCLUSION_LIFETIMES
|
|
41
|
+
BODY_MODEL_HINT_DISPOSITIONS EVIDENCE_SOURCES UNKNOWN_ONLY_EVIDENCE_SOURCES
|
|
42
|
+
].each { |const| expect(described_class.const_get(const)).to be_frozen }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'UNKNOWN_ONLY_EVIDENCE_SOURCES is a subset of EVIDENCE_SOURCES' do
|
|
46
|
+
expect(described_class::EVIDENCE_SOURCES).to include(*described_class::UNKNOWN_ONLY_EVIDENCE_SOURCES)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe '.normalize_operation' do
|
|
51
|
+
it 'returns a canonical operation unchanged' do
|
|
52
|
+
expect(described_class.normalize_operation(value: 'chat')).to eq(:chat)
|
|
53
|
+
expect(described_class.normalize_operation(value: :stream_chat)).to eq(:stream_chat)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'accepts only the documented aliases when allow_aliases is true' do
|
|
57
|
+
{
|
|
58
|
+
stream: :stream_chat, embedding: :embed, moderation: :moderate,
|
|
59
|
+
audio_translation: :translate, speech: :speak
|
|
60
|
+
}.each do |input, canonical|
|
|
61
|
+
expect(described_class.normalize_operation(value: input, allow_aliases: true)).to eq(canonical)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'raises on an alias when allow_aliases is false' do
|
|
66
|
+
expect { described_class.normalize_operation(value: :stream) }
|
|
67
|
+
.to raise_error(Legion::Extensions::Llm::Inventory::Errors::ValidationError)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'raises on unknown, empty, and invalid UTF-8 input' do
|
|
71
|
+
expect { described_class.normalize_operation(value: :nope) }
|
|
72
|
+
.to raise_error(Legion::Extensions::Llm::Inventory::Errors::ValidationError)
|
|
73
|
+
expect { described_class.normalize_operation(value: ' ') }
|
|
74
|
+
.to raise_error(Legion::Extensions::Llm::Inventory::Errors::ValidationError)
|
|
75
|
+
expect { described_class.normalize_operation(value: "\xFF".b) }
|
|
76
|
+
.to raise_error(Legion::Extensions::Llm::Inventory::Errors::ValidationError)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
28
79
|
end
|
|
@@ -96,6 +96,17 @@ module SpecSupport
|
|
|
96
96
|
def transcribe(_audio_file, model:, language:, **)
|
|
97
97
|
Legion::Extensions::Llm::Transcription.new(text: 'fake transcript', model: model, language: language)
|
|
98
98
|
end
|
|
99
|
+
|
|
100
|
+
# Records exactly-once disconnect for the callable-lifecycle contract; does
|
|
101
|
+
# not add disconnect to ProviderContract::REQUIRED_SIGNATURES.
|
|
102
|
+
def disconnect_count
|
|
103
|
+
@disconnect_count || 0
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def disconnect
|
|
107
|
+
@disconnect_count = disconnect_count + 1
|
|
108
|
+
super
|
|
109
|
+
end
|
|
99
110
|
end
|
|
100
111
|
|
|
101
112
|
class BackupFakeLLMProvider < FakeLLMProvider
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/llm/inventory/records'
|
|
4
|
+
require 'legion/extensions/llm/inventory/evidence'
|
|
5
|
+
require 'legion/extensions/llm/routing/provider_outcome'
|
|
6
|
+
require 'legion/extensions/llm/taxonomies'
|
|
7
|
+
|
|
8
|
+
module SpecSupport
|
|
9
|
+
# A distinct fake provider callable. Records inference calls and readiness
|
|
10
|
+
# probes separately so the conformance examples can prove that safe readiness
|
|
11
|
+
# performs no inference.
|
|
12
|
+
class FakeSsotCallable
|
|
13
|
+
attr_reader :inference_calls, :readiness_probes, :disconnects
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
@inference_calls = 0
|
|
17
|
+
@readiness_probes = 0
|
|
18
|
+
@disconnects = 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def disconnect
|
|
22
|
+
@disconnects += 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Non-inference control-plane readiness (e.g. a model-list/status call).
|
|
26
|
+
def control_plane_ready?
|
|
27
|
+
@readiness_probes += 1
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def chat(messages:, model:, **rest)
|
|
32
|
+
@inference_calls += 1
|
|
33
|
+
{ content: "fake chat #{model} #{messages.size} #{rest.size}" }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Runtime error normalization on the provider callable itself, mirroring the
|
|
37
|
+
# conservative Provider#normalize_dispatch_error base contract. Raw 503/529,
|
|
38
|
+
# ServiceUnavailableError, ServerError, and unknown errors return
|
|
39
|
+
# :provider_error, never :instance_unavailable. The reason is the bounded
|
|
40
|
+
# exception class name only.
|
|
41
|
+
def normalize_dispatch_error(error:)
|
|
42
|
+
llm = Legion::Extensions::Llm
|
|
43
|
+
kind = case error
|
|
44
|
+
when llm::OverloadedError then :overloaded
|
|
45
|
+
when llm::RateLimitError then :rate_limited
|
|
46
|
+
when llm::UnauthorizedError then :authentication
|
|
47
|
+
when llm::ForbiddenError then :authorization
|
|
48
|
+
when llm::BadRequestError then :invalid_request
|
|
49
|
+
else :provider_error
|
|
50
|
+
end
|
|
51
|
+
reason = error.class.name
|
|
52
|
+
reason = 'UnknownError' if reason.nil? || reason.empty?
|
|
53
|
+
llm::Routing::ProviderOutcome.new(kind: kind, reason: reason)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Phase 1 fake implementation of the shared SSOT v3 provider-harness interface
|
|
58
|
+
# consumed by 'an SSOT v3 provider adapter'. See phase-1-lex-llm-additive.md
|
|
59
|
+
# Task 12.
|
|
60
|
+
class FakeSsotHarness
|
|
61
|
+
def provider_family
|
|
62
|
+
:vllm
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def instance_configs
|
|
66
|
+
[{ instance_id: 'h200', model: 'gemma4' }, { instance_id: 'helios1', model: 'gemma4' }].freeze
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def instance_id(instance_config:)
|
|
70
|
+
instance_config.fetch(:instance_id)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def build_callable(instance_config:)
|
|
74
|
+
_ = instance_config
|
|
75
|
+
FakeSsotCallable.new
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def build_offering_drafts(instance_config:, callable:, tier: :local)
|
|
79
|
+
_ = callable
|
|
80
|
+
[offering_draft(instance_config.fetch(:model), tier)].freeze
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def safe_readiness(instance_config:, callable:)
|
|
84
|
+
_ = instance_config
|
|
85
|
+
callable.control_plane_ready?
|
|
86
|
+
Legion::Extensions::Llm::Inventory::ReadinessResult.new(ready: true, reason: 'control-plane model list ok')
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def inference_call_count(callable:)
|
|
90
|
+
callable.inference_calls
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def normalize_dispatch_error(error:)
|
|
94
|
+
routing = Legion::Extensions::Llm::Routing
|
|
95
|
+
case error[:kind]
|
|
96
|
+
when :instance_unavailable then routing::ProviderOutcome.new(kind: :instance_unavailable, reason: 'explicit service unavailable')
|
|
97
|
+
when :overloaded then routing::ProviderOutcome.new(kind: :overloaded, reason: 'HTTP 503 overloaded')
|
|
98
|
+
when :model_not_ready then routing::ProviderOutcome.new(kind: :model_not_ready, reason: 'HTTP 503 model loading')
|
|
99
|
+
else routing::ProviderOutcome.new(kind: :provider_error, reason: 'unclassified provider error')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def instance_unavailable_error
|
|
104
|
+
{ kind: :instance_unavailable, http_status: 503 }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def overloaded_error
|
|
108
|
+
{ kind: :overloaded, http_status: 503 }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def model_not_ready_error
|
|
112
|
+
{ kind: :model_not_ready, http_status: 503 }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def offering_draft(model, tier)
|
|
118
|
+
Legion::Extensions::Llm::Inventory::OfferingDraft.new(
|
|
119
|
+
provider_native_key: model, model: model, tier: tier, operation_evidence: operation_evidence,
|
|
120
|
+
context_evidence: unknown_value, max_output_evidence: unknown_value,
|
|
121
|
+
embedding_dimensions_evidence: unknown_value, model_revision_evidence: unknown_value,
|
|
122
|
+
tokenizer_evidence: unknown_value, publication_source: :provider_catalog
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def operation_evidence
|
|
127
|
+
Legion::Extensions::Llm::Taxonomies::OPERATIONS.to_h do |op|
|
|
128
|
+
status, source = op == :chat ? %i[supported provider_implementation] : %i[unknown absent]
|
|
129
|
+
[op, Legion::Extensions::Llm::Inventory::OperationEvidence.new(operation: op, status: status, source: source)]
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def unknown_value
|
|
134
|
+
Legion::Extensions::Llm::Inventory::ValueEvidence.new(status: :unknown, source: :absent)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/llm/inventory/registry'
|
|
4
|
+
require 'legion/extensions/llm/inventory/probe_coordinator'
|
|
5
|
+
|
|
6
|
+
# Shared builders for the SSOT v3 registry specs. Provides fake callables,
|
|
7
|
+
# instance keys, offering drafts, and a full claim -> probe -> activate helper so
|
|
8
|
+
# each registry spec exercises the public API rather than internal state.
|
|
9
|
+
module SsotRegistryHelpers
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def registry
|
|
13
|
+
Legion::Extensions::Llm::Inventory::Registry
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def instance_key(family: 'vllm', instance: 'h200')
|
|
17
|
+
Legion::Extensions::Llm::Inventory::Identity::InstanceKey.new(provider_family: family, instance_id: instance)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fake_callable
|
|
21
|
+
Class.new do
|
|
22
|
+
attr_reader :disconnect_count
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
@disconnect_count = 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def disconnect
|
|
29
|
+
@disconnect_count += 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def chat(**)
|
|
33
|
+
{ ok: true }
|
|
34
|
+
end
|
|
35
|
+
end.new
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def probe_coordinator(key, enqueue: ->(**) { true })
|
|
39
|
+
Legion::Extensions::Llm::Inventory::ProbeCoordinator.new(instance_key: key, enqueue: enqueue)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def unknown_value
|
|
43
|
+
Legion::Extensions::Llm::Inventory::ValueEvidence.new(status: :unknown, source: :absent)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def operation_evidence(supported: %i[chat])
|
|
47
|
+
Legion::Extensions::Llm::Taxonomies::OPERATIONS.to_h do |op|
|
|
48
|
+
status, source = supported.include?(op) ? %i[supported provider_implementation] : %i[unknown absent]
|
|
49
|
+
[op, Legion::Extensions::Llm::Inventory::OperationEvidence.new(operation: op, status: status, source: source)]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def drafts(model: 'gemma4', native: 'gemma4', supported: %i[chat], tier: :local)
|
|
54
|
+
[
|
|
55
|
+
Legion::Extensions::Llm::Inventory::OfferingDraft.new(
|
|
56
|
+
provider_native_key: native, model: model, tier: tier,
|
|
57
|
+
operation_evidence: operation_evidence(supported: supported),
|
|
58
|
+
context_evidence: unknown_value, max_output_evidence: unknown_value,
|
|
59
|
+
embedding_dimensions_evidence: unknown_value, model_revision_evidence: unknown_value,
|
|
60
|
+
tokenizer_evidence: unknown_value, publication_source: :provider_catalog
|
|
61
|
+
)
|
|
62
|
+
]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Full claim -> probe -> activation lifecycle; returns the publisher token.
|
|
66
|
+
# Extra keyword args (model:, native:, supported:, tier:) are forwarded to #drafts.
|
|
67
|
+
def claim_and_activate(key:, callable:, coordinator:, sequence: 0, **draft_opts)
|
|
68
|
+
token = registry.claim_instance(instance_key: key, callable: callable, probe_request_handle: coordinator)
|
|
69
|
+
probe = registry.readiness_probe_started(instance_key: key, publisher_token: token)
|
|
70
|
+
registry.activate_instance_snapshot(
|
|
71
|
+
publisher_token: token, instance_key: key, offerings: drafts(**draft_opts), sequence: sequence, probe_token: probe
|
|
72
|
+
)
|
|
73
|
+
token
|
|
74
|
+
end
|
|
75
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lex-llm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LegionIO
|
|
@@ -295,8 +295,19 @@ files:
|
|
|
295
295
|
- lib/legion/extensions/llm/fleet/token_validator.rb
|
|
296
296
|
- lib/legion/extensions/llm/fleet/worker_execution.rb
|
|
297
297
|
- lib/legion/extensions/llm/image.rb
|
|
298
|
+
- lib/legion/extensions/llm/inventory/callable_handle.rb
|
|
298
299
|
- lib/legion/extensions/llm/inventory/capabilities.rb
|
|
300
|
+
- lib/legion/extensions/llm/inventory/errors.rb
|
|
301
|
+
- lib/legion/extensions/llm/inventory/evidence.rb
|
|
302
|
+
- lib/legion/extensions/llm/inventory/identity.rb
|
|
303
|
+
- lib/legion/extensions/llm/inventory/immutable_value.rb
|
|
304
|
+
- lib/legion/extensions/llm/inventory/probe_coordinator.rb
|
|
305
|
+
- lib/legion/extensions/llm/inventory/probe_token.rb
|
|
306
|
+
- lib/legion/extensions/llm/inventory/publisher.rb
|
|
307
|
+
- lib/legion/extensions/llm/inventory/records.rb
|
|
308
|
+
- lib/legion/extensions/llm/inventory/registry.rb
|
|
299
309
|
- lib/legion/extensions/llm/inventory/scoped_refresher.rb
|
|
310
|
+
- lib/legion/extensions/llm/inventory/snapshot.rb
|
|
300
311
|
- lib/legion/extensions/llm/message.rb
|
|
301
312
|
- lib/legion/extensions/llm/mime_type.rb
|
|
302
313
|
- lib/legion/extensions/llm/model.rb
|
|
@@ -323,6 +334,8 @@ files:
|
|
|
323
334
|
- lib/legion/extensions/llm/routing/lane_key.rb
|
|
324
335
|
- lib/legion/extensions/llm/routing/model_offering.rb
|
|
325
336
|
- lib/legion/extensions/llm/routing/offering_registry.rb
|
|
337
|
+
- lib/legion/extensions/llm/routing/provider_outcome.rb
|
|
338
|
+
- lib/legion/extensions/llm/routing/records.rb
|
|
326
339
|
- lib/legion/extensions/llm/routing/registry_event.rb
|
|
327
340
|
- lib/legion/extensions/llm/stop_reason_mapping.rb
|
|
328
341
|
- lib/legion/extensions/llm/stream_accumulator.rb
|
|
@@ -393,8 +406,11 @@ files:
|
|
|
393
406
|
- spec/legion/extensions/llm/conformance/fixtures/canonical_tool_results_continuation_request.json
|
|
394
407
|
- spec/legion/extensions/llm/conformance/fixtures/canonical_tool_use_response.json
|
|
395
408
|
- spec/legion/extensions/llm/conformance/fixtures/canonical_tools_request.json
|
|
409
|
+
- spec/legion/extensions/llm/conformance/fixtures/ssot_identity_vectors.json
|
|
396
410
|
- spec/legion/extensions/llm/conformance/provider_tool_rendering_examples.rb
|
|
397
411
|
- spec/legion/extensions/llm/conformance/provider_translator_examples.rb
|
|
412
|
+
- spec/legion/extensions/llm/conformance/ssot_provider_conformance_spec.rb
|
|
413
|
+
- spec/legion/extensions/llm/conformance/ssot_provider_examples.rb
|
|
398
414
|
- spec/legion/extensions/llm/connection_close_spec.rb
|
|
399
415
|
- spec/legion/extensions/llm/connection_logging_spec.rb
|
|
400
416
|
- spec/legion/extensions/llm/connection_retry_spec.rb
|
|
@@ -402,13 +418,28 @@ files:
|
|
|
402
418
|
- spec/legion/extensions/llm/credential_sources_spec.rb
|
|
403
419
|
- spec/legion/extensions/llm/error_middleware_spec.rb
|
|
404
420
|
- spec/legion/extensions/llm/error_spec.rb
|
|
421
|
+
- spec/legion/extensions/llm/fleet/exact_offering_spec.rb
|
|
405
422
|
- spec/legion/extensions/llm/fleet/provider_responder_spec.rb
|
|
406
423
|
- spec/legion/extensions/llm/fleet/token_validator_spec.rb
|
|
407
424
|
- spec/legion/extensions/llm/fleet/worker_execution_spec.rb
|
|
408
425
|
- spec/legion/extensions/llm/fleet_messages_spec.rb
|
|
409
426
|
- spec/legion/extensions/llm/gemspec_spec.rb
|
|
427
|
+
- spec/legion/extensions/llm/inventory/boot_spec.rb
|
|
428
|
+
- spec/legion/extensions/llm/inventory/callable_handle_spec.rb
|
|
410
429
|
- spec/legion/extensions/llm/inventory/capabilities_spec.rb
|
|
430
|
+
- spec/legion/extensions/llm/inventory/evidence_spec.rb
|
|
431
|
+
- spec/legion/extensions/llm/inventory/identity_spec.rb
|
|
432
|
+
- spec/legion/extensions/llm/inventory/immutable_value_spec.rb
|
|
433
|
+
- spec/legion/extensions/llm/inventory/probe_coordinator_spec.rb
|
|
434
|
+
- spec/legion/extensions/llm/inventory/probe_token_spec.rb
|
|
435
|
+
- spec/legion/extensions/llm/inventory/publisher_spec.rb
|
|
436
|
+
- spec/legion/extensions/llm/inventory/records_spec.rb
|
|
437
|
+
- spec/legion/extensions/llm/inventory/registry_activation_spec.rb
|
|
438
|
+
- spec/legion/extensions/llm/inventory/registry_availability_spec.rb
|
|
439
|
+
- spec/legion/extensions/llm/inventory/registry_callable_spec.rb
|
|
440
|
+
- spec/legion/extensions/llm/inventory/registry_replacement_spec.rb
|
|
411
441
|
- spec/legion/extensions/llm/inventory/scoped_refresher_spec.rb
|
|
442
|
+
- spec/legion/extensions/llm/inventory/snapshot_spec.rb
|
|
412
443
|
- spec/legion/extensions/llm/message_spec.rb
|
|
413
444
|
- spec/legion/extensions/llm/model/info_spec.rb
|
|
414
445
|
- spec/legion/extensions/llm/models_spec.rb
|
|
@@ -423,6 +454,8 @@ files:
|
|
|
423
454
|
- spec/legion/extensions/llm/responses/thinking_extractor_spec.rb
|
|
424
455
|
- spec/legion/extensions/llm/routing/model_offering_spec.rb
|
|
425
456
|
- spec/legion/extensions/llm/routing/offering_registry_spec.rb
|
|
457
|
+
- spec/legion/extensions/llm/routing/provider_outcome_spec.rb
|
|
458
|
+
- spec/legion/extensions/llm/routing/records_spec.rb
|
|
426
459
|
- spec/legion/extensions/llm/routing/registry_event_spec.rb
|
|
427
460
|
- spec/legion/extensions/llm/stop_reason_mapping_spec.rb
|
|
428
461
|
- spec/legion/extensions/llm/stream_accumulator_spec.rb
|
|
@@ -436,9 +469,11 @@ files:
|
|
|
436
469
|
- spec/legion/extensions/llm_root_spec.rb
|
|
437
470
|
- spec/spec_helper.rb
|
|
438
471
|
- spec/support/fake_llm_provider.rb
|
|
472
|
+
- spec/support/fake_ssot_harness.rb
|
|
439
473
|
- spec/support/llm_configuration.rb
|
|
440
474
|
- spec/support/rspec_configuration.rb
|
|
441
475
|
- spec/support/simplecov_configuration.rb
|
|
476
|
+
- spec/support/ssot_registry_helpers.rb
|
|
442
477
|
homepage: https://github.com/LegionIO/lex-llm
|
|
443
478
|
licenses:
|
|
444
479
|
- MIT
|