Skip to content

Commit 12745bf

Browse files
Fix comments
1 parent 1ebe45c commit 12745bf

File tree

11 files changed

+314
-103
lines changed

11 files changed

+314
-103
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static TransportVersion def(int id) {
353353
public static final TransportVersion NODE_WEIGHTS_ADDED_TO_NODE_BALANCE_STATS = def(9_129_0_00);
354354
public static final TransportVersion RERANK_SNIPPETS = def(9_130_0_00);
355355
public static final TransportVersion PIPELINE_TRACKING_INFO = def(9_131_0_00);
356-
public static final TransportVersion ML_INFERENCE_LLAMA_OPEN_AI_API_FIX = def(9_132_0_00);
356+
public static final TransportVersion ML_INFERENCE_LLAMA_REFACTORED = def(9_132_0_00);
357357

358358
/*
359359
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/LlamaService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public Model parsePersistedConfig(String modelId, TaskType taskType, Map<String,
379379

380380
@Override
381381
public TransportVersion getMinimalSupportedVersion() {
382-
return TransportVersions.ML_INFERENCE_LLAMA_ADDED;
382+
return TransportVersions.ML_INFERENCE_LLAMA_REFACTORED;
383383
}
384384

385385
@Override

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/action/LlamaActionVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface LlamaActionVisitor {
2222
* Creates an executable action for the given Llama embeddings model.
2323
*
2424
* @param model the Llama embeddings model
25-
* @param taskSettings the settings for the task, which may include parameters like user
25+
* @param taskSettings the settings for the task
2626
* @return an executable action for the embeddings model
2727
*/
2828
ExecutableAction create(LlamaEmbeddingsModel model, Map<String, Object> taskSettings);
@@ -31,7 +31,7 @@ public interface LlamaActionVisitor {
3131
* Creates an executable action for the given Llama chat completion model.
3232
*
3333
* @param model the Llama chat completion model
34-
* @param taskSettings the settings for the task, which may include parameters like user
34+
* @param taskSettings the settings for the task
3535
* @return an executable action for the chat completion model
3636
*/
3737
ExecutableAction create(LlamaChatCompletionModel model, Map<String, Object> taskSettings);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/completion/LlamaChatCompletionModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LlamaChatCompletionModel extends LlamaModel {
3333
* @param taskType the type of task this model is designed for
3434
* @param service the name of the inference service
3535
* @param serviceSettings the settings for the inference service, specific to chat completion
36-
* @param taskSettings the settings for the task, such as user or other parameters
36+
* @param taskSettings the settings for the task
3737
* @param secrets the secret settings for the model, such as API keys or tokens
3838
* @param context the context for parsing configuration settings
3939
*/
@@ -62,7 +62,7 @@ public LlamaChatCompletionModel(
6262
* @param taskType the type of task this model is designed for
6363
* @param service the name of the inference service
6464
* @param serviceSettings the settings for the inference service, specific to chat completion
65-
* @param taskSettings the settings for the task, such as user or other parameters
65+
* @param taskSettings the settings for the task
6666
* @param secrets the secret settings for the model, such as API keys or tokens
6767
*/
6868
public LlamaChatCompletionModel(
@@ -82,7 +82,7 @@ public LlamaChatCompletionModel(
8282
* If the request does not specify task settings, the original model is returned.
8383
*
8484
* @param model the original LlamaChatCompletionModel
85-
* @param taskSettings the task settings to override, which may include parameters like user
85+
* @param taskSettings the task settings to override
8686
* @return a new LlamaChatCompletionModel with overridden task settings or the original model if no overrides are specified
8787
*/
8888
public static LlamaChatCompletionModel of(LlamaChatCompletionModel model, Map<String, Object> taskSettings) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/completion/LlamaChatCompletionServiceSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public String getWriteableName() {
116116

117117
@Override
118118
public TransportVersion getMinimalSupportedVersion() {
119-
return TransportVersions.ML_INFERENCE_LLAMA_ADDED;
119+
return TransportVersions.ML_INFERENCE_LLAMA_REFACTORED;
120120
}
121121

122122
@Override

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/embeddings/LlamaEmbeddingsModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LlamaEmbeddingsModel extends LlamaModel {
3434
* @param taskType the type of task this model is designed for
3535
* @param service the name of the inference service
3636
* @param serviceSettings the settings for the inference service, specific to embeddings
37-
* @param taskSettings the settings for the task, such as user or other parameters
37+
* @param taskSettings the settings for the task
3838
* @param chunkingSettings the chunking settings for processing input data
3939
* @param secrets the secret settings for the model, such as API keys or tokens
4040
* @param context the context for parsing configuration settings
@@ -88,7 +88,7 @@ private void setPropertiesFromServiceSettings(LlamaEmbeddingsServiceSettings ser
8888
* @param taskType the type of task this model is designed for
8989
* @param service the name of the inference service
9090
* @param serviceSettings the settings for the inference service, specific to embeddings
91-
* @param taskSettings the settings for the task, such as user or other parameters
91+
* @param taskSettings the settings for the task
9292
* @param chunkingSettings the chunking settings for processing input data
9393
* @param secrets the secret settings for the model, such as API keys or tokens
9494
*/
@@ -113,7 +113,7 @@ public LlamaEmbeddingsModel(
113113
* If the request does not specify task settings, the original model is returned.
114114
*
115115
* @param model the original LlamaEmbeddingsModel
116-
* @param taskSettings the task settings to override, which may include parameters like user
116+
* @param taskSettings the task settings to override
117117
* @return a new LlamaEmbeddingsModel with overridden task settings or the original model if no overrides are specified
118118
*/
119119
public static LlamaEmbeddingsModel of(LlamaEmbeddingsModel model, Map<String, Object> taskSettings) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/llama/embeddings/LlamaEmbeddingsServiceSettings.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public static LlamaEmbeddingsServiceSettings fromMap(Map<String, Object> map, Co
9090
}
9191
dimensionsSetByUser = dimensions != null;
9292
} else if (context == ConfigurationParseContext.PERSISTENT && dimensionsSetByUser == null) {
93-
// If the context is persistent and dimensionsSetByUser is not specified, we default it to false
94-
dimensionsSetByUser = Boolean.FALSE;
93+
validationException.addValidationError(
94+
ServiceUtils.missingSettingErrorMsg(DIMENSIONS_SET_BY_USER, ModelConfigurations.SERVICE_SETTINGS)
95+
);
9596
}
9697

9798
var rateLimitSettings = RateLimitSettings.of(map, DEFAULT_RATE_LIMIT_SETTINGS, validationException, LlamaService.NAME, context);
@@ -123,11 +124,7 @@ public LlamaEmbeddingsServiceSettings(StreamInput in) throws IOException {
123124
this.dimensions = in.readOptionalVInt();
124125
this.similarity = in.readOptionalEnum(SimilarityMeasure.class);
125126
this.maxInputTokens = in.readOptionalVInt();
126-
if (in.getTransportVersion().onOrAfter(TransportVersions.ML_INFERENCE_LLAMA_OPEN_AI_API_FIX)) {
127-
this.dimensionsSetByUser = in.readBoolean();
128-
} else {
129-
this.dimensionsSetByUser = false;
130-
}
127+
this.dimensionsSetByUser = in.readBoolean();
131128
this.rateLimitSettings = new RateLimitSettings(in);
132129
}
133130

@@ -190,7 +187,7 @@ public String getWriteableName() {
190187

191188
@Override
192189
public TransportVersion getMinimalSupportedVersion() {
193-
return TransportVersions.ML_INFERENCE_LLAMA_ADDED;
190+
return TransportVersions.ML_INFERENCE_LLAMA_REFACTORED;
194191
}
195192

196193
@Override
@@ -247,19 +244,15 @@ public void writeTo(StreamOutput out) throws IOException {
247244
out.writeOptionalVInt(dimensions);
248245
out.writeOptionalEnum(SimilarityMeasure.translateSimilarity(similarity, out.getTransportVersion()));
249246
out.writeOptionalVInt(maxInputTokens);
250-
if (out.getTransportVersion().onOrAfter(TransportVersions.ML_INFERENCE_LLAMA_OPEN_AI_API_FIX)) {
251-
out.writeBoolean(dimensionsSetByUser);
252-
}
247+
out.writeBoolean(dimensionsSetByUser);
253248
rateLimitSettings.writeTo(out);
254249
}
255250

256251
@Override
257252
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
258253
builder.startObject();
259254
toXContentFragmentOfExposedFields(builder, params);
260-
if (dimensionsSetByUser != null) {
261-
builder.field(DIMENSIONS_SET_BY_USER, dimensionsSetByUser);
262-
}
255+
builder.field(DIMENSIONS_SET_BY_USER, dimensionsSetByUser);
263256
builder.endObject();
264257
return builder;
265258
}

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

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ public CommonConfig(TaskType taskType, @Nullable TaskType unsupportedTaskType) {
120120

121121
protected abstract SenderService createService(ThreadPool threadPool, HttpClientManager clientManager);
122122

123-
protected abstract Map<String, Object> createServiceSettingsMap(TaskType taskType);
123+
protected abstract Map<String, Object> createServiceSettingsMap(
124+
TaskType taskType,
125+
ConfigurationParseContext configurationParseContext
126+
);
124127

125128
protected abstract Map<String, Object> createTaskSettingsMap();
126129

@@ -160,7 +163,7 @@ public void testParseRequestConfig_CreatesAnEmbeddingsModel() throws Exception {
160163

161164
try (var service = parseRequestConfigTestConfig.createService(threadPool, clientManager)) {
162165
var config = getRequestConfigMap(
163-
parseRequestConfigTestConfig.createServiceSettingsMap(TaskType.TEXT_EMBEDDING),
166+
parseRequestConfigTestConfig.createServiceSettingsMap(TaskType.TEXT_EMBEDDING, ConfigurationParseContext.REQUEST),
164167
parseRequestConfigTestConfig.createTaskSettingsMap(),
165168
parseRequestConfigTestConfig.createSecretSettingsMap()
166169
);
@@ -177,7 +180,7 @@ public void testParseRequestConfig_CreatesACompletionModel() throws Exception {
177180

178181
try (var service = parseRequestConfigTestConfig.createService(threadPool, clientManager)) {
179182
var config = getRequestConfigMap(
180-
parseRequestConfigTestConfig.createServiceSettingsMap(TaskType.COMPLETION),
183+
parseRequestConfigTestConfig.createServiceSettingsMap(TaskType.COMPLETION, ConfigurationParseContext.REQUEST),
181184
parseRequestConfigTestConfig.createTaskSettingsMap(),
182185
parseRequestConfigTestConfig.createSecretSettingsMap()
183186
);
@@ -194,7 +197,10 @@ public void testParseRequestConfig_ThrowsUnsupportedModelType() throws Exception
194197

195198
try (var service = parseRequestConfigTestConfig.createService(threadPool, clientManager)) {
196199
var config = getRequestConfigMap(
197-
parseRequestConfigTestConfig.createServiceSettingsMap(parseRequestConfigTestConfig.taskType),
200+
parseRequestConfigTestConfig.createServiceSettingsMap(
201+
parseRequestConfigTestConfig.taskType,
202+
ConfigurationParseContext.REQUEST
203+
),
198204
parseRequestConfigTestConfig.createTaskSettingsMap(),
199205
parseRequestConfigTestConfig.createSecretSettingsMap()
200206
);
@@ -215,7 +221,10 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInConfig() throws I
215221

216222
try (var service = parseRequestConfigTestConfig.createService(threadPool, clientManager)) {
217223
var config = getRequestConfigMap(
218-
parseRequestConfigTestConfig.createServiceSettingsMap(parseRequestConfigTestConfig.taskType),
224+
parseRequestConfigTestConfig.createServiceSettingsMap(
225+
parseRequestConfigTestConfig.taskType,
226+
ConfigurationParseContext.REQUEST
227+
),
219228
parseRequestConfigTestConfig.createTaskSettingsMap(),
220229
parseRequestConfigTestConfig.createSecretSettingsMap()
221230
);
@@ -232,7 +241,10 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInConfig() throws I
232241
public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInServiceSettingsMap() throws IOException {
233242
var parseRequestConfigTestConfig = testConfiguration.commonConfig;
234243
try (var service = parseRequestConfigTestConfig.createService(threadPool, clientManager)) {
235-
var serviceSettings = parseRequestConfigTestConfig.createServiceSettingsMap(parseRequestConfigTestConfig.taskType);
244+
var serviceSettings = parseRequestConfigTestConfig.createServiceSettingsMap(
245+
parseRequestConfigTestConfig.taskType,
246+
ConfigurationParseContext.REQUEST
247+
);
236248
serviceSettings.put("extra_key", "value");
237249
var config = getRequestConfigMap(
238250
serviceSettings,
@@ -254,7 +266,10 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInTaskSettingsMap()
254266
var taskSettings = parseRequestConfigTestConfig.createTaskSettingsMap();
255267
taskSettings.put("extra_key", "value");
256268
var config = getRequestConfigMap(
257-
parseRequestConfigTestConfig.createServiceSettingsMap(parseRequestConfigTestConfig.taskType),
269+
parseRequestConfigTestConfig.createServiceSettingsMap(
270+
parseRequestConfigTestConfig.taskType,
271+
ConfigurationParseContext.REQUEST
272+
),
258273
taskSettings,
259274
parseRequestConfigTestConfig.createSecretSettingsMap()
260275
);
@@ -273,7 +288,10 @@ public void testParseRequestConfig_ThrowsWhenAnExtraKeyExistsInSecretSettingsMap
273288
var secretSettingsMap = parseRequestConfigTestConfig.createSecretSettingsMap();
274289
secretSettingsMap.put("extra_key", "value");
275290
var config = getRequestConfigMap(
276-
parseRequestConfigTestConfig.createServiceSettingsMap(parseRequestConfigTestConfig.taskType),
291+
parseRequestConfigTestConfig.createServiceSettingsMap(
292+
parseRequestConfigTestConfig.taskType,
293+
ConfigurationParseContext.REQUEST
294+
),
277295
parseRequestConfigTestConfig.createTaskSettingsMap(),
278296
secretSettingsMap
279297
);
@@ -293,7 +311,7 @@ public void testParsePersistedConfigWithSecrets_CreatesAnEmbeddingsModel() throw
293311

294312
try (var service = parseConfigTestConfig.createService(threadPool, clientManager)) {
295313
var persistedConfigMap = getPersistedConfigMap(
296-
parseConfigTestConfig.createServiceSettingsMap(TaskType.TEXT_EMBEDDING),
314+
parseConfigTestConfig.createServiceSettingsMap(TaskType.TEXT_EMBEDDING, ConfigurationParseContext.PERSISTENT),
297315
parseConfigTestConfig.createTaskSettingsMap(),
298316
parseConfigTestConfig.createSecretSettingsMap()
299317
);
@@ -313,7 +331,7 @@ public void testParsePersistedConfigWithSecrets_CreatesACompletionModel() throws
313331

314332
try (var service = parseConfigTestConfig.createService(threadPool, clientManager)) {
315333
var persistedConfigMap = getPersistedConfigMap(
316-
parseConfigTestConfig.createServiceSettingsMap(TaskType.COMPLETION),
334+
parseConfigTestConfig.createServiceSettingsMap(TaskType.COMPLETION, ConfigurationParseContext.PERSISTENT),
317335
parseConfigTestConfig.createTaskSettingsMap(),
318336
parseConfigTestConfig.createSecretSettingsMap()
319337
);
@@ -333,7 +351,7 @@ public void testParsePersistedConfigWithSecrets_ThrowsUnsupportedModelType() thr
333351

334352
try (var service = parseConfigTestConfig.createService(threadPool, clientManager)) {
335353
var persistedConfigMap = getPersistedConfigMap(
336-
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType),
354+
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType, ConfigurationParseContext.PERSISTENT),
337355
parseConfigTestConfig.createTaskSettingsMap(),
338356
parseConfigTestConfig.createSecretSettingsMap()
339357
);
@@ -366,7 +384,7 @@ public void testParsePersistedConfigWithSecrets_DoesNotThrowWhenAnExtraKeyExists
366384

367385
try (var service = parseConfigTestConfig.createService(threadPool, clientManager)) {
368386
var persistedConfigMap = getPersistedConfigMap(
369-
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType),
387+
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType, ConfigurationParseContext.PERSISTENT),
370388
parseConfigTestConfig.createTaskSettingsMap(),
371389
parseConfigTestConfig.createSecretSettingsMap()
372390
);
@@ -386,7 +404,10 @@ public void testParsePersistedConfigWithSecrets_DoesNotThrowWhenAnExtraKeyExists
386404
public void testParsePersistedConfigWithSecrets_ThrowsWhenAnExtraKeyExistsInServiceSettingsMap() throws IOException {
387405
var parseConfigTestConfig = testConfiguration.commonConfig;
388406
try (var service = parseConfigTestConfig.createService(threadPool, clientManager)) {
389-
var serviceSettings = parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType);
407+
var serviceSettings = parseConfigTestConfig.createServiceSettingsMap(
408+
parseConfigTestConfig.taskType,
409+
ConfigurationParseContext.PERSISTENT
410+
);
390411
serviceSettings.put("extra_key", "value");
391412
var persistedConfigMap = getPersistedConfigMap(
392413
serviceSettings,
@@ -411,7 +432,7 @@ public void testParsePersistedConfigWithSecrets_ThrowsWhenAnExtraKeyExistsInTask
411432
var taskSettings = parseConfigTestConfig.createTaskSettingsMap();
412433
taskSettings.put("extra_key", "value");
413434
var config = getPersistedConfigMap(
414-
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType),
435+
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType, ConfigurationParseContext.PERSISTENT),
415436
taskSettings,
416437
parseConfigTestConfig.createSecretSettingsMap()
417438
);
@@ -428,7 +449,7 @@ public void testParsePersistedConfigWithSecrets_ThrowsWhenAnExtraKeyExistsInSecr
428449
var secretSettingsMap = parseConfigTestConfig.createSecretSettingsMap();
429450
secretSettingsMap.put("extra_key", "value");
430451
var config = getPersistedConfigMap(
431-
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType),
452+
parseConfigTestConfig.createServiceSettingsMap(parseConfigTestConfig.taskType, ConfigurationParseContext.PERSISTENT),
432453
parseConfigTestConfig.createTaskSettingsMap(),
433454
secretSettingsMap
434455
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/custom/CustomServiceTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.xpack.inference.external.http.HttpClientManager;
3535
import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSenderTests;
3636
import org.elasticsearch.xpack.inference.services.AbstractInferenceServiceTests;
37+
import org.elasticsearch.xpack.inference.services.ConfigurationParseContext;
3738
import org.elasticsearch.xpack.inference.services.SenderService;
3839
import org.elasticsearch.xpack.inference.services.ServiceFields;
3940
import org.elasticsearch.xpack.inference.services.custom.response.CompletionResponseParser;
@@ -80,7 +81,7 @@ protected SenderService createService(ThreadPool threadPool, HttpClientManager c
8081
}
8182

8283
@Override
83-
protected Map<String, Object> createServiceSettingsMap(TaskType taskType) {
84+
protected Map<String, Object> createServiceSettingsMap(TaskType taskType, ConfigurationParseContext configurationParseContext) {
8485
return CustomServiceTests.createServiceSettingsMap(taskType);
8586
}
8687

0 commit comments

Comments
 (0)