@@ -77,6 +77,8 @@ public class ElasticInferenceService extends SenderService {
7777
7878 public static final String DEFAULT_EIS_COMPLETION_ENDPOINT_ID = "eis-alpha-1" ;
7979
80+ public static final List <String > DEFAULT_EIS_ENDPOINT_IDS = List .of (DEFAULT_EIS_COMPLETION_ENDPOINT_ID );
81+
8082 public ElasticInferenceService (
8183 HttpRequestSender .Factory factory ,
8284 ServiceComponents serviceComponents ,
@@ -180,8 +182,18 @@ public void parseRequestConfig(
180182 Map <String , Object > config ,
181183 ActionListener <Model > parsedModelListener
182184 ) {
183- try {
184- Map <String , Object > serviceSettingsMap = removeFromMapOrThrowIfNull (config , ModelConfigurations .SERVICE_SETTINGS );
185+ if (DEFAULT_EIS_ENDPOINT_IDS .contains (inferenceEntityId )) {
186+ parsedModelListener .onFailure (
187+ new ElasticsearchStatusException (
188+ "[{}] is a reserved inference Id. Cannot create a new inference endpoint with a reserved Id" ,
189+ RestStatus .BAD_REQUEST ,
190+ inferenceEntityId
191+ )
192+ );
193+ return ;
194+ }
195+
196+ try {Map <String , Object > serviceSettingsMap = removeFromMapOrThrowIfNull (config , ModelConfigurations .SERVICE_SETTINGS );
185197 Map <String , Object > taskSettingsMap = removeFromMapOrDefaultEmpty (config , ModelConfigurations .TASK_SETTINGS );
186198
187199 ElasticInferenceServiceModel model = createModel (
@@ -222,25 +234,30 @@ public List<DefaultConfigId> defaultConfigIds() {
222234
223235 @ Override
224236 public void defaultConfigs (ActionListener <List <Model >> defaultsListener ) {
225- var serviceSettings = new HashMap <String , Object >(1 );
226- serviceSettings .put (MODEL_ID , "elastic-model" ); // TODO
227237
228238 defaultsListener .onResponse (
229239 List .of (
230- new ElasticInferenceServiceCompletionModel (
231- DEFAULT_EIS_COMPLETION_ENDPOINT_ID ,
232- TaskType .COMPLETION ,
233- NAME ,
234- serviceSettings ,
235- null ,
236- null ,
237- new ElasticInferenceServiceComponents ("http://localhost:8080" ), // TODO
238- ConfigurationParseContext .PERSISTENT
239- )
240+ firstDefaultCompletionModel ()
240241 )
241242 );
242243 }
243244
245+ private static ElasticInferenceServiceCompletionModel firstDefaultCompletionModel () {
246+ var serviceSettings = new HashMap <String , Object >(1 );
247+ serviceSettings .put (MODEL_ID , "elastic-model" ); // TODO
248+
249+ return new ElasticInferenceServiceCompletionModel (
250+ DEFAULT_EIS_COMPLETION_ENDPOINT_ID ,
251+ TaskType .COMPLETION ,
252+ NAME ,
253+ serviceSettings ,
254+ null ,
255+ null ,
256+ new ElasticInferenceServiceComponents ("http://localhost:8080" ), // TODO
257+ ConfigurationParseContext .PERSISTENT
258+ );
259+ }
260+
244261 private static ElasticInferenceServiceModel createModel (
245262 String inferenceEntityId ,
246263 TaskType taskType ,
@@ -302,33 +319,14 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M
302319 Map <String , Object > serviceSettingsMap = removeFromMapOrThrowIfNull (config , ModelConfigurations .SERVICE_SETTINGS );
303320 Map <String , Object > taskSettingsMap = removeFromMapOrDefaultEmpty (config , ModelConfigurations .TASK_SETTINGS );
304321
305- if (DEFAULT_EIS_COMPLETION_ENDPOINT_ID .equals (inferenceEntityId )) {
306- var defaultServiceSettings = new HashMap <String , Object >(1 );
307- defaultServiceSettings .put (MODEL_ID , "elastic-model" ); // TODO
308- var serviceSettings = ElasticInferenceServiceCompletionServiceSettings .fromMap (
309- defaultServiceSettings ,
310- ConfigurationParseContext .PERSISTENT
311- );
312-
313- return new ElasticInferenceServiceCompletionModel (
314- V1_EIS_COMPLETION_MODEL_ID ,
315- TaskType .COMPLETION ,
316- NAME ,
317- serviceSettings ,
318- EmptyTaskSettings .INSTANCE ,
319- null ,
320- null
321- );
322- } else {
323- return createModelFromPersistent (
324- inferenceEntityId ,
325- taskType ,
326- serviceSettingsMap ,
327- taskSettingsMap ,
328- null ,
329- parsePersistedConfigErrorMsg (inferenceEntityId , NAME )
330- );
331- }
322+ return createModelFromPersistent (
323+ inferenceEntityId ,
324+ taskType ,
325+ serviceSettingsMap ,
326+ taskSettingsMap ,
327+ null ,
328+ parsePersistedConfigErrorMsg (inferenceEntityId , NAME )
329+ );
332330 }
333331
334332 @ Override
0 commit comments