Skip to content

Commit 25d962e

Browse files
atornsiiclaude
andcommitted
fix(server-ai): stop exposing model_key/model_version on ModelConfig
model_key/model_version should only be visible via the tracker's stamped event data, mirroring how variation_key/version are treated. They now flow from the already-parsed _ldMeta fields straight into the tracker factory instead of being attached to ModelConfig. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 7531228 commit 25d962e

2 files changed

Lines changed: 5 additions & 42 deletions

File tree

lib/server/ai/client.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ def to_h
3838
# The ModelConfig class represents an AI model configuration.
3939
#
4040
class ModelConfig
41-
attr_reader :name, :model_key, :model_version
41+
attr_reader :name
4242

43-
def initialize(name:, parameters: {}, custom: {}, model_key: nil, model_version: nil)
43+
def initialize(name:, parameters: {}, custom: {})
4444
@name = name
4545
@parameters = parameters
4646
@custom = custom
47-
@model_key = model_key
48-
@model_version = model_version
4947
end
5048

5149
#
@@ -77,14 +75,11 @@ def custom(key)
7775
end
7876

7977
def to_h
80-
result = {
78+
{
8179
name: @name,
8280
parameters: @parameters,
8381
custom: @custom,
8482
}
85-
result[:modelKey] = @model_key if @model_key && !@model_key.empty?
86-
result[:modelVersion] = @model_version unless @model_version.nil?
87-
result
8883
end
8984
end
9085

@@ -292,17 +287,15 @@ def _completion_config(key:, context:, default:, variables: nil)
292287
model = ModelConfig.new(
293288
name: variation[:model][:name],
294289
parameters: parameters,
295-
custom: custom,
296-
model_key: variation.dig(:_ldMeta, :modelKey),
297-
model_version: tracked_model_version
290+
custom: custom
298291
)
299292
end
300293

301294
variation_key = variation.dig(:_ldMeta, :variationKey) || ''
302295
version = variation.dig(:_ldMeta, :version) || 1
303296
model_name = model&.name || ''
304297
provider_name = provider_config&.name || ''
305-
model_key = model&.model_key
298+
model_key = variation.dig(:_ldMeta, :modelKey)
306299

307300
tracker_factory = lambda {
308301
LaunchDarkly::Server::AI::AIConfigTracker.new(

spec/server/ai/client_spec.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,6 @@
127127
expect(model.custom('name')).to be_nil
128128
end
129129

130-
it 'to_h omits modelKey and modelVersion when unset' do
131-
model = described_class.new(name: 'fakeModel', parameters: { temperature: 0.5 })
132-
expect(model.model_key).to be_nil
133-
expect(model.model_version).to be_nil
134-
result = model.to_h
135-
expect(result).not_to have_key(:modelKey)
136-
expect(result).not_to have_key(:modelVersion)
137-
end
138-
139-
it 'to_h includes modelKey and modelVersion when set' do
140-
model = described_class.new(name: 'fakeModel', model_key: 'my-model', model_version: 2)
141-
result = model.to_h
142-
expect(result[:modelKey]).to eq('my-model')
143-
expect(result[:modelVersion]).to eq(2)
144-
end
145-
146-
it 'to_h omits empty modelKey' do
147-
model = described_class.new(name: 'fakeModel', model_key: '')
148-
result = model.to_h
149-
expect(result).not_to have_key(:modelKey)
150-
end
151130
end
152131

153132
describe LaunchDarkly::Server::AI::Client do
@@ -447,15 +426,6 @@
447426
expect(flag_data).not_to have_key(:modelKey)
448427
end
449428

450-
it 'reads modelKey and modelVersion from flag payload' do
451-
context = LaunchDarkly::LDContext.create({ key: 'user-key', kind: 'user' })
452-
config = ai_client.completion_config(key: 'model-config-with-key-version', context:)
453-
454-
expect(config.model).not_to be_nil
455-
expect(config.model.model_key).to eq('my-model')
456-
expect(config.model.model_version).to eq(2)
457-
end
458-
459429
it 'stamps modelKey and modelVersion on track data' do
460430
context = LaunchDarkly::LDContext.create({ key: 'user-key', kind: 'user' })
461431
config = ai_client.completion_config(key: 'model-config-with-key-version', context:)

0 commit comments

Comments
 (0)