|
42 | 42 | import org.elasticsearch.xpack.inference.services.SenderService; |
43 | 43 | import org.elasticsearch.xpack.inference.services.ServiceComponents; |
44 | 44 | import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionModel; |
| 45 | +import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionServiceSettings; |
45 | 46 | import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings; |
46 | 47 | import org.elasticsearch.xpack.inference.telemetry.TraceContext; |
47 | 48 |
|
@@ -72,6 +73,10 @@ public class ElasticInferenceService extends SenderService { |
72 | 73 | private static final EnumSet<TaskType> supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING, TaskType.COMPLETION); |
73 | 74 | private static final String SERVICE_NAME = "Elastic"; |
74 | 75 |
|
| 76 | + public static final String V1_EIS_COMPLETION_MODEL_ID = "temp1"; |
| 77 | + |
| 78 | + public static final String DEFAULT_EIS_COMPLETION_ENDPOINT_ID = "eis-alpha-1"; |
| 79 | + |
75 | 80 | public ElasticInferenceService( |
76 | 81 | HttpRequestSender.Factory factory, |
77 | 82 | ServiceComponents serviceComponents, |
@@ -210,6 +215,32 @@ public EnumSet<TaskType> supportedTaskTypes() { |
210 | 215 | return supportedTaskTypes; |
211 | 216 | } |
212 | 217 |
|
| 218 | + @Override |
| 219 | + public List<DefaultConfigId> defaultConfigIds() { |
| 220 | + return List.of(new DefaultConfigId(DEFAULT_EIS_COMPLETION_ENDPOINT_ID, TaskType.COMPLETION, this)); |
| 221 | + } |
| 222 | + |
| 223 | + @Override |
| 224 | + public void defaultConfigs(ActionListener<List<Model>> defaultsListener) { |
| 225 | + var serviceSettings = new HashMap<String, Object>(1); |
| 226 | + serviceSettings.put(MODEL_ID, "elastic-model"); // TODO |
| 227 | + |
| 228 | + defaultsListener.onResponse( |
| 229 | + 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 | + ) |
| 241 | + ); |
| 242 | + } |
| 243 | + |
213 | 244 | private static ElasticInferenceServiceModel createModel( |
214 | 245 | String inferenceEntityId, |
215 | 246 | TaskType taskType, |
@@ -271,16 +302,30 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M |
271 | 302 | Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS); |
272 | 303 | Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS); |
273 | 304 |
|
274 | | - return createModelFromPersistent( |
275 | | - inferenceEntityId, |
276 | | - taskType, |
277 | | - serviceSettingsMap, |
278 | | - taskSettingsMap, |
279 | | - null, |
280 | | - parsePersistedConfigErrorMsg(inferenceEntityId, NAME) |
281 | | - ); |
| 305 | + if (DEFAULT_EIS_COMPLETION_ENDPOINT_ID.equals(inferenceEntityId)) { |
| 306 | + return V1_EIS_COMPLETION_MODEL; |
| 307 | + } else { |
| 308 | + return createModelFromPersistent( |
| 309 | + inferenceEntityId, |
| 310 | + taskType, |
| 311 | + serviceSettingsMap, |
| 312 | + taskSettingsMap, |
| 313 | + null, |
| 314 | + parsePersistedConfigErrorMsg(inferenceEntityId, NAME) |
| 315 | + ); |
| 316 | + } |
282 | 317 | } |
283 | 318 |
|
| 319 | + private static final Model V1_EIS_COMPLETION_MODEL = new ElasticInferenceServiceCompletionModel( |
| 320 | + V1_EIS_COMPLETION_MODEL_ID, |
| 321 | + TaskType.COMPLETION, |
| 322 | + NAME, |
| 323 | + (ElasticInferenceServiceCompletionServiceSettings) Map.of(MODEL_ID, DEFAULT_EIS_COMPLETION_ENDPOINT_ID), |
| 324 | + EmptyTaskSettings.INSTANCE, |
| 325 | + null, |
| 326 | + null |
| 327 | + ); |
| 328 | + |
284 | 329 | @Override |
285 | 330 | public TransportVersion getMinimalSupportedVersion() { |
286 | 331 | return TransportVersions.V_8_16_0; |
|
0 commit comments