Skip to content

Commit 7f40459

Browse files
Refactor accept methods in OpenShift AI models to include task settings parameter
1 parent d68a636 commit 7f40459

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
import org.elasticsearch.inference.ModelSecrets;
1212
import org.elasticsearch.inference.ServiceSettings;
1313
import org.elasticsearch.inference.TaskSettings;
14+
import org.elasticsearch.xpack.inference.external.action.ExecutableAction;
1415
import org.elasticsearch.xpack.inference.services.RateLimitGroupingModel;
16+
import org.elasticsearch.xpack.inference.services.openshiftai.action.OpenShiftAiActionVisitor;
1517
import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings;
1618
import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings;
1719

20+
import java.util.Map;
1821
import java.util.Objects;
1922

2023
/**
@@ -55,4 +58,12 @@ public DefaultSecretSettings getSecretSettings() {
5558
return (DefaultSecretSettings) super.getSecretSettings();
5659
}
5760

61+
/**
62+
* Accepts a visitor to create an executable action for this OpenShift AI model.
63+
*
64+
* @param creator the visitor that creates the executable action
65+
* @param taskSettings the task settings to be used for the executable action
66+
* @return an {@link ExecutableAction} specific to this OpenShift AI model
67+
*/
68+
public abstract ExecutableAction accept(OpenShiftAiActionVisitor creator, Map<String, Object> taskSettings);
5869
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ protected void doInfer(
111111
TimeValue timeout,
112112
ActionListener<InferenceServiceResults> listener
113113
) {
114-
var actionCreator = new OpenShiftAiActionCreator(getSender(), getServiceComponents());
115-
116-
switch (model) {
117-
case OpenShiftAiChatCompletionModel chatCompletionModel -> chatCompletionModel.accept(actionCreator)
118-
.execute(inputs, timeout, listener);
119-
case OpenShiftAiEmbeddingsModel embeddingsModel -> embeddingsModel.accept(actionCreator).execute(inputs, timeout, listener);
120-
case OpenShiftAiRerankModel rerankModel -> rerankModel.accept(actionCreator, taskSettings).execute(inputs, timeout, listener);
121-
default -> listener.onFailure(createInvalidModelException(model));
114+
if (model instanceof OpenShiftAiModel == false) {
115+
listener.onFailure(createInvalidModelException(model));
116+
return;
122117
}
118+
var openShiftAiModel = (OpenShiftAiModel) model;
119+
var actionCreator = new OpenShiftAiActionCreator(getSender(), getServiceComponents());
120+
openShiftAiModel.accept(actionCreator, taskSettings).execute(inputs, timeout, listener);
123121
}
124122

125123
@Override
@@ -176,7 +174,7 @@ protected void doChunkedInfer(
176174
).batchRequestsWithListeners(listener);
177175

178176
for (var request : batchedRequests) {
179-
var action = openShiftAiEmbeddingsModel.accept(actionCreator);
177+
var action = openShiftAiEmbeddingsModel.accept(actionCreator, taskSettings);
180178
action.execute(new EmbeddingsInput(request.batch().inputs(), inputType), timeout, request.listener());
181179
}
182180
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openshiftai/completion/OpenShiftAiChatCompletionModel.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,9 @@ public OpenShiftAiChatCompletionServiceSettings getServiceSettings() {
114114
return (OpenShiftAiChatCompletionServiceSettings) super.getServiceSettings();
115115
}
116116

117-
/**
118-
* Accepts a visitor that creates an executable action for this OpenShift AI chat completion.
119-
*
120-
* @param creator the visitor that creates the executable action
121-
* @return an ExecutableAction representing this model
122-
*/
123-
public ExecutableAction accept(OpenShiftAiActionVisitor creator) {
117+
@Override
118+
public ExecutableAction accept(OpenShiftAiActionVisitor creator, Map<String, Object> taskSettings) {
119+
// Chat completion models do not have task settings, so we ignore the taskSettings parameter.
124120
return creator.create(this);
125121
}
126122
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openshiftai/embeddings/OpenShiftAiEmbeddingsModel.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,9 @@ public OpenShiftAiEmbeddingsServiceSettings getServiceSettings() {
7979
return (OpenShiftAiEmbeddingsServiceSettings) super.getServiceSettings();
8080
}
8181

82-
/**
83-
* Accepts a visitor to create an executable action for this OpenShift AI embeddings model.
84-
*
85-
* @param creator the visitor that creates the executable action
86-
* @return an ExecutableAction representing the OpenShift AI embeddings model
87-
*/
88-
public ExecutableAction accept(OpenShiftAiActionVisitor creator) {
82+
@Override
83+
public ExecutableAction accept(OpenShiftAiActionVisitor creator, Map<String, Object> taskSettings) {
84+
// Embeddings models do not have task settings, so we ignore the taskSettings parameter.
8985
return creator.create(this);
9086
}
9187
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/openshiftai/rerank/OpenShiftAiRerankModel.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ public OpenShiftAiRerankTaskSettings getTaskSettings() {
7373
return (OpenShiftAiRerankTaskSettings) super.getTaskSettings();
7474
}
7575

76-
/**
77-
* Accepts a visitor to create an executable action. The returned action will not return documents in the response.
78-
* @param visitor Interface for creating {@link ExecutableAction} instances for IBM watsonx models.
79-
* @param taskSettings Settings in the request to override the model's defaults
80-
* @return the rerank action
81-
*/
76+
@Override
8277
public ExecutableAction accept(OpenShiftAiActionVisitor visitor, Map<String, Object> taskSettings) {
8378
return visitor.create(this, taskSettings);
8479
}

0 commit comments

Comments
 (0)