|
17 | 17 | import org.elasticsearch.core.TimeValue; |
18 | 18 | import org.elasticsearch.inference.ChunkedInference; |
19 | 19 | import org.elasticsearch.inference.EmptySettingsConfiguration; |
20 | | -import org.elasticsearch.inference.EmptyTaskSettings; |
21 | 20 | import org.elasticsearch.inference.InferenceServiceConfiguration; |
22 | 21 | import org.elasticsearch.inference.InferenceServiceResults; |
23 | 22 | import org.elasticsearch.inference.InputType; |
@@ -80,6 +79,8 @@ public class ElasticInferenceService extends SenderService { |
80 | 79 |
|
81 | 80 | public static final String DEFAULT_EIS_COMPLETION_ENDPOINT_ID = "eis-alpha-1"; |
82 | 81 |
|
| 82 | + public static final List<String> DEFAULT_EIS_ENDPOINT_IDS = List.of(DEFAULT_EIS_COMPLETION_ENDPOINT_ID); |
| 83 | + |
83 | 84 | public ElasticInferenceService( |
84 | 85 | HttpRequestSender.Factory factory, |
85 | 86 | ServiceComponents serviceComponents, |
@@ -183,8 +184,18 @@ public void parseRequestConfig( |
183 | 184 | Map<String, Object> config, |
184 | 185 | ActionListener<Model> parsedModelListener |
185 | 186 | ) { |
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); |
188 | 199 | Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS); |
189 | 200 |
|
190 | 201 | ElasticInferenceServiceModel model = createModel( |
@@ -225,25 +236,30 @@ public List<DefaultConfigId> defaultConfigIds() { |
225 | 236 |
|
226 | 237 | @Override |
227 | 238 | public void defaultConfigs(ActionListener<List<Model>> defaultsListener) { |
228 | | - var serviceSettings = new HashMap<String, Object>(1); |
229 | | - serviceSettings.put(MODEL_ID, "elastic-model"); // TODO |
230 | 239 |
|
231 | 240 | defaultsListener.onResponse( |
232 | 241 | 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() |
243 | 243 | ) |
244 | 244 | ); |
245 | 245 | } |
246 | 246 |
|
| 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 | + |
247 | 263 | private static ElasticInferenceServiceModel createModel( |
248 | 264 | String inferenceEntityId, |
249 | 265 | TaskType taskType, |
@@ -305,33 +321,14 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M |
305 | 321 | Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS); |
306 | 322 | Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS); |
307 | 323 |
|
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 | + ); |
335 | 332 | } |
336 | 333 |
|
337 | 334 | @Override |
|
0 commit comments