Skip to content

Commit fc72d8b

Browse files
author
Max Hniebergall
committed
precommit
1 parent 6de692b commit fc72d8b

File tree

17 files changed

+97
-539
lines changed

17 files changed

+97
-539
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/PutInferenceModelAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import java.util.Map;
3131
import java.util.Objects;
3232

33-
import static org.elasticsearch.inference.ModelConfigurations.TASK_SETTINGS;
3433
import static org.elasticsearch.inference.ModelConfigurations.PARAMETERS;
34+
import static org.elasticsearch.inference.ModelConfigurations.TASK_SETTINGS;
3535

3636
public class PutInferenceModelAction extends ActionType<PutInferenceModelAction.Response> {
3737

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/inference/action/PutInferenceModelActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.Locale;
2525
import java.util.Map;
2626

27-
import static org.elasticsearch.inference.ModelConfigurations.TASK_SETTINGS;
2827
import static org.elasticsearch.inference.ModelConfigurations.PARAMETERS;
28+
import static org.elasticsearch.inference.ModelConfigurations.TASK_SETTINGS;
2929

3030
public class PutInferenceModelActionTests extends ESTestCase {
3131
public static TaskType TASK_TYPE;

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/ModelRegistryIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ private static Model buildModelWithUnknownField(String inferenceEntityId) {
518518
}
519519

520520
public static Model createModel(String inferenceEntityId, TaskType taskType, String services) {
521-
return new Model(new ModelConfigurations(inferenceEntityId, taskType, service, new TestModelOfAnyKind.TestModelServiceSettings()));
521+
return new Model(new ModelConfigurations(inferenceEntityId, taskType, services, new TestModelOfAnyKind.TestModelServiceSettings()));
522522
}
523523

524524
public static Model createModelWithSecrets(String inferenceEntityId, TaskType taskType, String service, String secret) {
@@ -619,7 +619,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
619619
}
620620
}
621621

622-
TestModelOfAnyKind(String inferenceEntityId, TaskType taskType, String services) {
622+
TestModelOfAnyKind(String inferenceEntityId, TaskType taskType, String service) {
623623
super(inferenceEntityId, taskType, service, new TestModelServiceSettings(), new TestTaskSettings());
624624
}
625625

@@ -644,7 +644,7 @@ private static class ModelWithUnknownField extends ModelConfigurations {
644644
TaskType taskType,
645645
String service,
646646
ServiceSettings serviceSettings,
647-
TaskSettings taskSettingss
647+
TaskSettings taskSettings
648648
) {
649649
super(inferenceEntityId, taskType, service, serviceSettings, taskSettings);
650650
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/ModelConfigurationsTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.inference.TaskSettings;
1515
import org.elasticsearch.inference.TaskType;
1616
import org.elasticsearch.test.AbstractWireSerializingTestCase;
17-
import org.elasticsearch.test.EnumSerializationTestUtils;
1817
import org.elasticsearch.xpack.core.inference.ChunkingSettingsFeatureFlag;
1918
import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsTests;
2019
import org.elasticsearch.xpack.inference.services.elasticsearch.ElserInternalServiceSettingsTests;

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/TransportInferenceUsageActionTests.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,42 +81,12 @@ public void test() throws Exception {
8181
listener.onResponse(
8282
new GetInferenceModelAction.Response(
8383
List.of(
84-
new ModelConfigurations(
85-
"model-001",
86-
TaskType.TEXT_EMBEDDING,
87-
"openai",
88-
mock(ServiceSettings.class)
89-
),
90-
new ModelConfigurations(
91-
"model-002",
92-
TaskType.TEXT_EMBEDDING,
93-
"openai",
94-
mock(ServiceSettings.class)
95-
),
96-
new ModelConfigurations(
97-
"model-003",
98-
TaskType.SPARSE_EMBEDDING,
99-
"hugging_face_elser",
100-
mock(ServiceSettings.class)
101-
),
102-
new ModelConfigurations(
103-
"model-004",
104-
TaskType.TEXT_EMBEDDING,
105-
"openai",
106-
mock(ServiceSettings.class)
107-
),
108-
new ModelConfigurations(
109-
"model-005",
110-
TaskType.SPARSE_EMBEDDING,
111-
"openai",
112-
mock(ServiceSettings.class)
113-
),
114-
new ModelConfigurations(
115-
"model-006",
116-
TaskType.SPARSE_EMBEDDING,
117-
"hugging_face_elser",
118-
mock(ServiceSettings.class)
119-
)
84+
new ModelConfigurations("model-001", TaskType.TEXT_EMBEDDING, "openai", mock(ServiceSettings.class)),
85+
new ModelConfigurations("model-002", TaskType.TEXT_EMBEDDING, "openai", mock(ServiceSettings.class)),
86+
new ModelConfigurations("model-003", TaskType.SPARSE_EMBEDDING, "hugging_face_elser", mock(ServiceSettings.class)),
87+
new ModelConfigurations("model-004", TaskType.TEXT_EMBEDDING, "openai", mock(ServiceSettings.class)),
88+
new ModelConfigurations("model-005", TaskType.SPARSE_EMBEDDING, "openai", mock(ServiceSettings.class)),
89+
new ModelConfigurations("model-006", TaskType.SPARSE_EMBEDDING, "hugging_face_elser", mock(ServiceSettings.class))
12090
)
12191
)
12292
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/azureopenai/AzureOpenAiActionCreatorTests.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,7 @@ public void testInfer_AzureOpenAiCompletion_WithOverriddenUser() throws IOExcept
468468
var apiKey = "api_key";
469469
var completionInput = "some input";
470470

471-
var model = createCompletionModel(
472-
"resource",
473-
"deployment",
474-
"apiversion",
475-
originalUser,
476-
apiKey,
477-
null,
478-
"id"
479-
);
471+
var model = createCompletionModel("resource", "deployment", "apiversion", originalUser, apiKey, null, "id");
480472
model.setUri(new URI(getUrl(webServer)));
481473
var actionCreator = new AzureOpenAiActionCreator(sender, createWithEmptySettings(threadPool));
482474
var taskSettingsWithUserOverride = createRequestTaskSettingsMap(overriddenUser);
@@ -532,15 +524,7 @@ public void testInfer_AzureOpenAiCompletionModel_WithoutUser() throws IOExceptio
532524

533525
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
534526

535-
var model = createCompletionModel(
536-
"resource",
537-
"deployment",
538-
"apiversion",
539-
null,
540-
apiKey,
541-
null,
542-
"id"
543-
);
527+
var model = createCompletionModel("resource", "deployment", "apiversion", null, apiKey, null, "id");
544528
model.setUri(new URI(getUrl(webServer)));
545529
var actionCreator = new AzureOpenAiActionCreator(sender, createWithEmptySettings(threadPool));
546530
var requestTaskSettingsWithoutUser = createRequestTaskSettingsMap(null);
@@ -598,15 +582,7 @@ public void testInfer_AzureOpenAiCompletionModel_FailsFromInvalidResponseFormat(
598582

599583
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
600584

601-
var model = createCompletionModel(
602-
"resource",
603-
"deployment",
604-
"apiversion",
605-
null,
606-
apiKey,
607-
null,
608-
"id"
609-
);
585+
var model = createCompletionModel("resource", "deployment", "apiversion", null, apiKey, null, "id");
610586
model.setUri(new URI(getUrl(webServer)));
611587
var actionCreator = new AzureOpenAiActionCreator(sender, createWithEmptySettings(threadPool));
612588
var requestTaskSettingsWithoutUser = createRequestTaskSettingsMap(userOverride);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/registry/ModelRegistryTests.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,7 @@ public void testStoreModel_ThrowsException_WhenFailureIsNotAVersionConflict() {
295295
@SuppressWarnings("unchecked")
296296
public void testDeepCopyDefaultConfig() {
297297
{
298-
var toCopy = new UnparsedModel(
299-
"tocopy",
300-
randomFrom(TaskType.values()),
301-
"service-a",
302-
Map.of(),
303-
Map.of()
304-
);
298+
var toCopy = new UnparsedModel("tocopy", randomFrom(TaskType.values()), "service-a", Map.of(), Map.of());
305299
var copied = ModelRegistry.deepCopyDefaultConfig(toCopy);
306300
assertThat(copied, not(sameInstance(toCopy)));
307301
assertThat(copied.taskType(), is(toCopy.taskType()));
@@ -324,13 +318,7 @@ public void testDeepCopyDefaultConfig() {
324318
Map<String, Object> service = Map.of("num_threads", 1, "adaptive_allocations", Map.of("enabled", true));
325319
Map<String, Object> settings = Map.of("chunking_settings", chunking, "service_settings", service, "task_settings", task);
326320

327-
var toCopy = new UnparsedModel(
328-
"tocopy",
329-
randomFrom(TaskType.values()),
330-
"service-a",
331-
settings,
332-
secretsMap
333-
);
321+
var toCopy = new UnparsedModel("tocopy", randomFrom(TaskType.values()), "service-a", settings, secretsMap);
334322
var copied = ModelRegistry.deepCopyDefaultConfig(toCopy);
335323
assertThat(copied, not(sameInstance(toCopy)));
336324

@@ -364,20 +352,10 @@ public void testDuplicateDefaultIds() {
364352

365353
var id = "my-inference";
366354

367-
registry.addDefaultConfiguration(
368-
new UnparsedModel(id, randomFrom(TaskType.values()), "service-a", Map.of(), Map.of())
369-
);
355+
registry.addDefaultConfiguration(new UnparsedModel(id, randomFrom(TaskType.values()), "service-a", Map.of(), Map.of()));
370356
var ise = expectThrows(
371357
IllegalStateException.class,
372-
() -> registry.addDefaultConfiguration(
373-
new UnparsedModel(
374-
id,
375-
randomFrom(TaskType.values()),
376-
"service-b",
377-
Map.of(),
378-
Map.of()
379-
)
380-
)
358+
() -> registry.addDefaultConfiguration(new UnparsedModel(id, randomFrom(TaskType.values()), "service-b", Map.of(), Map.of()))
381359
);
382360
assertThat(
383361
ise.getMessage(),

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/amazonbedrock/AmazonBedrockServiceTests.java

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,7 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInConfig() throws I
205205
}
206206
);
207207

208-
service.parseRequestConfig(
209-
"id",
210-
TaskType.TEXT_EMBEDDING,
211-
config,
212-
modelVerificationListener
213-
);
208+
service.parseRequestConfig("id", TaskType.TEXT_EMBEDDING, config, modelVerificationListener);
214209
}
215210
}
216211

@@ -231,12 +226,7 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInServiceSettingsMa
231226
);
232227
});
233228

234-
service.parseRequestConfig(
235-
"id",
236-
TaskType.TEXT_EMBEDDING,
237-
config,
238-
modelVerificationListener
239-
);
229+
service.parseRequestConfig("id", TaskType.TEXT_EMBEDDING, config, modelVerificationListener);
240230
}
241231
}
242232

@@ -260,12 +250,7 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInTaskSettingsMap()
260250
);
261251
});
262252

263-
service.parseRequestConfig(
264-
"id",
265-
TaskType.COMPLETION,
266-
config,
267-
modelVerificationListener
268-
);
253+
service.parseRequestConfig("id", TaskType.COMPLETION, config, modelVerificationListener);
269254
}
270255
}
271256

@@ -289,12 +274,7 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInSecretSettingsMap
289274
);
290275
});
291276

292-
service.parseRequestConfig(
293-
"id",
294-
TaskType.COMPLETION,
295-
config,
296-
modelVerificationListener
297-
);
277+
service.parseRequestConfig("id", TaskType.COMPLETION, config, modelVerificationListener);
298278
}
299279
}
300280

@@ -546,11 +526,7 @@ public void testParsePersistedConfig_CreatesAnAmazonBedrockEmbeddingsModel() thr
546526

547527
var persistedConfig = getPersistedConfigMap(settingsMap, new HashMap<String, Object>(Map.of()), secretSettingsMap);
548528

549-
var model = service.parsePersistedConfig(
550-
"id",
551-
TaskType.TEXT_EMBEDDING,
552-
persistedConfig.config()
553-
);
529+
var model = service.parsePersistedConfig("id", TaskType.TEXT_EMBEDDING, persistedConfig.config());
554530

555531
assertThat(model, instanceOf(AmazonBedrockEmbeddingsModel.class));
556532

@@ -569,11 +545,7 @@ public void testParsePersistedConfig_CreatesAnAmazonBedrockChatCompletionModel()
569545
var secretSettingsMap = getAmazonBedrockSecretSettingsMap("access", "secret");
570546

571547
var persistedConfig = getPersistedConfigMap(settingsMap, taskSettingsMap, secretSettingsMap);
572-
var model = service.parsePersistedConfig(
573-
"id",
574-
TaskType.COMPLETION,
575-
persistedConfig.config()
576-
);
548+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
577549

578550
assertThat(model, instanceOf(AmazonBedrockChatCompletionModel.class));
579551

@@ -599,11 +571,7 @@ public void testParsePersistedConfig_ThrowsErrorTryingToParseInvalidModel() thro
599571

600572
var thrownException = expectThrows(
601573
ElasticsearchStatusException.class,
602-
() -> service.parsePersistedConfig(
603-
"id",
604-
TaskType.SPARSE_EMBEDDING,
605-
persistedConfig.config()
606-
)
574+
() -> service.parsePersistedConfig("id", TaskType.SPARSE_EMBEDDING, persistedConfig.config())
607575
);
608576

609577
assertThat(
@@ -621,11 +589,7 @@ public void testParsePersistedConfig_DoesNotThrowWhenAnExtraKeyExistsInConfig()
621589
var persistedConfig = getPersistedConfigMap(settingsMap, new HashMap<String, Object>(Map.of()), secretSettingsMap);
622590
persistedConfig.config().put("extra_key", "value");
623591

624-
var model = service.parsePersistedConfig(
625-
"id",
626-
TaskType.TEXT_EMBEDDING,
627-
persistedConfig.config()
628-
);
592+
var model = service.parsePersistedConfig("id", TaskType.TEXT_EMBEDDING, persistedConfig.config());
629593

630594
assertThat(model, instanceOf(AmazonBedrockEmbeddingsModel.class));
631595

@@ -646,11 +610,7 @@ public void testParsePersistedConfig_NotThrowWhenAnExtraKeyExistsInServiceSettin
646610
var persistedConfig = getPersistedConfigMap(settingsMap, new HashMap<String, Object>(Map.of()), secretSettingsMap);
647611
persistedConfig.config().put("extra_key", "value");
648612

649-
var model = service.parsePersistedConfig(
650-
"id",
651-
TaskType.TEXT_EMBEDDING,
652-
persistedConfig.config()
653-
);
613+
var model = service.parsePersistedConfig("id", TaskType.TEXT_EMBEDDING, persistedConfig.config());
654614

655615
assertThat(model, instanceOf(AmazonBedrockEmbeddingsModel.class));
656616

@@ -670,11 +630,7 @@ public void testParsePersistedConfig_NotThrowWhenAnExtraKeyExistsInTaskSettings(
670630
var secretSettingsMap = getAmazonBedrockSecretSettingsMap("access", "secret");
671631

672632
var persistedConfig = getPersistedConfigMap(settingsMap, taskSettingsMap, secretSettingsMap);
673-
var model = service.parsePersistedConfig(
674-
"id",
675-
TaskType.COMPLETION,
676-
persistedConfig.config()
677-
);
633+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
678634

679635
assertThat(model, instanceOf(AmazonBedrockChatCompletionModel.class));
680636

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/anthropic/AnthropicServiceTests.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,7 @@ public void testParsePersistedConfig_CreatesACompletionModel() throws IOExceptio
360360
AnthropicChatCompletionTaskSettingsTests.getChatCompletionTaskSettingsMap(1, 1.0, 2.1, 3)
361361
);
362362

363-
var model = service.parsePersistedConfig(
364-
"id",
365-
TaskType.COMPLETION,
366-
persistedConfig.config()
367-
);
363+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
368364

369365
assertThat(model, instanceOf(AnthropicChatCompletionModel.class));
370366

@@ -385,11 +381,7 @@ public void testParsePersistedConfig_DoesNotThrowWhenAnExtraKeyExistsInConfig()
385381
);
386382
persistedConfig.config().put("extra_key", "value");
387383

388-
var model = service.parsePersistedConfig(
389-
"id",
390-
TaskType.COMPLETION,
391-
persistedConfig.config()
392-
);
384+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
393385

394386
assertThat(model, instanceOf(AnthropicChatCompletionModel.class));
395387

@@ -412,11 +404,7 @@ public void testParsePersistedConfig_DoesNotThrowWhenAnExtraKeyExistsInServiceSe
412404
AnthropicChatCompletionTaskSettingsTests.getChatCompletionTaskSettingsMap(1, 1.0, 2.1, 3)
413405
);
414406

415-
var model = service.parsePersistedConfig(
416-
"id",
417-
TaskType.COMPLETION,
418-
persistedConfig.config()
419-
);
407+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
420408

421409
assertThat(model, instanceOf(AnthropicChatCompletionModel.class));
422410

@@ -436,11 +424,7 @@ public void testParsePersistedConfig_DoesNotThrowWhenAnExtraKeyExistsInTaskSetti
436424

437425
var persistedConfig = getPersistedConfigMap(new HashMap<>(Map.of(ServiceFields.MODEL_ID, modelId)), taskSettings);
438426

439-
var model = service.parsePersistedConfig(
440-
"id",
441-
TaskType.COMPLETION,
442-
persistedConfig.config()
443-
);
427+
var model = service.parsePersistedConfig("id", TaskType.COMPLETION, persistedConfig.config());
444428

445429
assertThat(model, instanceOf(AnthropicChatCompletionModel.class));
446430

0 commit comments

Comments
 (0)