Skip to content

Commit 8ebe833

Browse files
author
Max Hniebergall
committed
add default endpoint for EIS completion
1 parent 31fe29c commit 8ebe833

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

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

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.xpack.inference.services.SenderService;
4343
import org.elasticsearch.xpack.inference.services.ServiceComponents;
4444
import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionModel;
45+
import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionServiceSettings;
4546
import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings;
4647
import org.elasticsearch.xpack.inference.telemetry.TraceContext;
4748

@@ -72,6 +73,10 @@ public class ElasticInferenceService extends SenderService {
7273
private static final EnumSet<TaskType> supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING, TaskType.COMPLETION);
7374
private static final String SERVICE_NAME = "Elastic";
7475

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+
7580
public ElasticInferenceService(
7681
HttpRequestSender.Factory factory,
7782
ServiceComponents serviceComponents,
@@ -210,6 +215,32 @@ public EnumSet<TaskType> supportedTaskTypes() {
210215
return supportedTaskTypes;
211216
}
212217

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+
213244
private static ElasticInferenceServiceModel createModel(
214245
String inferenceEntityId,
215246
TaskType taskType,
@@ -271,16 +302,30 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M
271302
Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS);
272303
Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS);
273304

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+
}
282317
}
283318

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+
284329
@Override
285330
public TransportVersion getMinimalSupportedVersion() {
286331
return TransportVersions.V_8_16_0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public ElasticInferenceServiceCompletionModel(
9090

9191
}
9292

93-
ElasticInferenceServiceCompletionModel(
93+
public ElasticInferenceServiceCompletionModel(
9494
String inferenceEntityId,
9595
TaskType taskType,
9696
String service,

0 commit comments

Comments
 (0)