Skip to content

Commit fd15e68

Browse files
prwhelandavidkyle
authored andcommitted
Create and assign model
1 parent 41c590e commit fd15e68

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.elasticsearch;
9+
10+
import org.elasticsearch.ResourceNotFoundException;
11+
import org.elasticsearch.action.ActionListener;
12+
import org.elasticsearch.inference.ChunkingSettings;
13+
import org.elasticsearch.inference.Model;
14+
import org.elasticsearch.inference.TaskType;
15+
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction;
16+
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
17+
18+
public class ElasticDeployedModel extends ElasticsearchInternalModel {
19+
public ElasticDeployedModel(
20+
String inferenceEntityId,
21+
TaskType taskType,
22+
String service,
23+
ElserInternalServiceSettings serviceSettings,
24+
ElserMlNodeTaskSettings taskSettings,
25+
ChunkingSettings chunkingSettings
26+
) {
27+
super(inferenceEntityId, taskType, service, serviceSettings, taskSettings, chunkingSettings);
28+
}
29+
30+
@Override
31+
public ActionListener<CreateTrainedModelAssignmentAction.Response> getCreateTrainedModelAssignmentActionListener(Model model, ActionListener<Boolean> listener) {
32+
return new ActionListener<>() {
33+
@Override
34+
public void onResponse(CreateTrainedModelAssignmentAction.Response response) {
35+
listener.onResponse(Boolean.TRUE);
36+
}
37+
38+
@Override
39+
public void onFailure(Exception e) {
40+
if (ExceptionsHelper.unwrapCause(e) instanceof ResourceNotFoundException) {
41+
listener.onFailure(
42+
new ResourceNotFoundException(
43+
"Could not start the inference as the deploymend model [{0}] cannot be found."
44+
+ " Trained Models must be deployed before they can be started.",
45+
internalServiceSettings.modelId()
46+
)
47+
);
48+
return;
49+
}
50+
listener.onFailure(e);
51+
}
52+
};
53+
}
54+
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,16 @@ public void parseRequestConfig(
146146
String modelId = (String) serviceSettingsMap.get(ElasticsearchInternalServiceSettings.MODEL_ID);
147147
String deploymentId = (String) serviceSettingsMap.get(ElasticsearchInternalServiceSettings.DEPLOYMENT_ID);
148148
if (deploymentId != null) {
149-
validateAgainstDeployment(modelId, deploymentId, taskType, ) // TODO create model
149+
validateAgainstDeployment(modelId, deploymentId, taskType, modelListener.delegateFailureAndWrap((l, settings) -> {
150+
l.onResponse(new ElasticDeployedModel(
151+
inferenceEntityId,
152+
taskType,
153+
NAME,
154+
new ElserInternalServiceSettings(settings.build()),
155+
ElserMlNodeTaskSettings.DEFAULT,
156+
chunkingSettings
157+
));
158+
}));
150159
} else if (modelId == null) {
151160
if (OLD_ELSER_SERVICE_NAME.equals(serviceName)) {
152161
// TODO complete deprecation of null model ID

0 commit comments

Comments
 (0)