Skip to content

Commit 03b5d45

Browse files
author
Max Hniebergall
committed
match ElasticsearchInternalService implementation of defaults
1 parent c315364 commit 03b5d45

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.core.TimeValue;
1818
import org.elasticsearch.inference.ChunkedInference;
1919
import org.elasticsearch.inference.EmptySettingsConfiguration;
20-
import org.elasticsearch.inference.EmptyTaskSettings;
2120
import org.elasticsearch.inference.InferenceServiceConfiguration;
2221
import org.elasticsearch.inference.InferenceServiceResults;
2322
import org.elasticsearch.inference.InputType;
@@ -80,6 +79,8 @@ public class ElasticInferenceService extends SenderService {
8079

8180
public static final String DEFAULT_EIS_COMPLETION_ENDPOINT_ID = "eis-alpha-1";
8281

82+
public static final List<String> DEFAULT_EIS_ENDPOINT_IDS = List.of(DEFAULT_EIS_COMPLETION_ENDPOINT_ID);
83+
8384
public ElasticInferenceService(
8485
HttpRequestSender.Factory factory,
8586
ServiceComponents serviceComponents,
@@ -183,8 +184,18 @@ public void parseRequestConfig(
183184
Map<String, Object> config,
184185
ActionListener<Model> parsedModelListener
185186
) {
186-
try {
187-
Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS);
187+
if (DEFAULT_EIS_ENDPOINT_IDS.contains(inferenceEntityId)) {
188+
parsedModelListener.onFailure(
189+
new ElasticsearchStatusException(
190+
"[{}] is a reserved inference Id. Cannot create a new inference endpoint with a reserved Id",
191+
RestStatus.BAD_REQUEST,
192+
inferenceEntityId
193+
)
194+
);
195+
return;
196+
}
197+
198+
try {Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS);
188199
Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS);
189200

190201
ElasticInferenceServiceModel model = createModel(
@@ -225,25 +236,30 @@ public List<DefaultConfigId> defaultConfigIds() {
225236

226237
@Override
227238
public void defaultConfigs(ActionListener<List<Model>> defaultsListener) {
228-
var serviceSettings = new HashMap<String, Object>(1);
229-
serviceSettings.put(MODEL_ID, "elastic-model"); // TODO
230239

231240
defaultsListener.onResponse(
232241
List.of(
233-
new ElasticInferenceServiceCompletionModel(
234-
DEFAULT_EIS_COMPLETION_ENDPOINT_ID,
235-
TaskType.COMPLETION,
236-
NAME,
237-
serviceSettings,
238-
null,
239-
null,
240-
new ElasticInferenceServiceComponents("http://localhost:8080"), // TODO
241-
ConfigurationParseContext.PERSISTENT
242-
)
242+
firstDefaultCompletionModel()
243243
)
244244
);
245245
}
246246

247+
private static ElasticInferenceServiceCompletionModel firstDefaultCompletionModel() {
248+
var serviceSettings = new HashMap<String, Object>(1);
249+
serviceSettings.put(MODEL_ID, "elastic-model"); // TODO
250+
251+
return new ElasticInferenceServiceCompletionModel(
252+
DEFAULT_EIS_COMPLETION_ENDPOINT_ID,
253+
TaskType.COMPLETION,
254+
NAME,
255+
serviceSettings,
256+
null,
257+
null,
258+
new ElasticInferenceServiceComponents("http://localhost:8080"), // TODO
259+
ConfigurationParseContext.PERSISTENT
260+
);
261+
}
262+
247263
private static ElasticInferenceServiceModel createModel(
248264
String inferenceEntityId,
249265
TaskType taskType,
@@ -305,33 +321,14 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M
305321
Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS);
306322
Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS);
307323

308-
if (DEFAULT_EIS_COMPLETION_ENDPOINT_ID.equals(inferenceEntityId)) {
309-
var defaultServiceSettings = new HashMap<String, Object>(1);
310-
defaultServiceSettings.put(MODEL_ID, "elastic-model"); // TODO
311-
var serviceSettings = ElasticInferenceServiceCompletionServiceSettings.fromMap(
312-
defaultServiceSettings,
313-
ConfigurationParseContext.PERSISTENT
314-
);
315-
316-
return new ElasticInferenceServiceCompletionModel(
317-
V1_EIS_COMPLETION_MODEL_ID,
318-
TaskType.COMPLETION,
319-
NAME,
320-
serviceSettings,
321-
EmptyTaskSettings.INSTANCE,
322-
null,
323-
null
324-
);
325-
} else {
326-
return createModelFromPersistent(
327-
inferenceEntityId,
328-
taskType,
329-
serviceSettingsMap,
330-
taskSettingsMap,
331-
null,
332-
parsePersistedConfigErrorMsg(inferenceEntityId, NAME)
333-
);
334-
}
324+
return createModelFromPersistent(
325+
inferenceEntityId,
326+
taskType,
327+
serviceSettingsMap,
328+
taskSettingsMap,
329+
null,
330+
parsePersistedConfigErrorMsg(inferenceEntityId, NAME)
331+
);
335332
}
336333

337334
@Override

0 commit comments

Comments
 (0)