Skip to content

Commit 2e618dc

Browse files
Add test for IbmWatsonxService
1 parent 1839490 commit 2e618dc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ibmwatsonx/IbmWatsonxServiceTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.elasticsearch.xpack.inference.services.ServiceFields;
5151
import org.elasticsearch.xpack.inference.services.ibmwatsonx.embeddings.IbmWatsonxEmbeddingsModel;
5252
import org.elasticsearch.xpack.inference.services.ibmwatsonx.embeddings.IbmWatsonxEmbeddingsModelTests;
53+
import org.elasticsearch.xpack.inference.services.ibmwatsonx.rerank.IbmWatsonxRerankModel;
5354
import org.elasticsearch.xpack.inference.services.openai.completion.OpenAiChatCompletionModelTests;
5455
import org.hamcrest.MatcherAssert;
5556
import org.hamcrest.Matchers;
@@ -154,6 +155,42 @@ public void testParseRequestConfig_CreatesAIbmWatsonxEmbeddingsModel() throws IO
154155
}
155156
}
156157

158+
public void testParseRequestConfig_CreatesAIbmWatsonxRerankModel() throws IOException {
159+
try (var service = createIbmWatsonxService()) {
160+
ActionListener<Model> modelListener = ActionListener.wrap(model -> {
161+
assertThat(model, instanceOf(IbmWatsonxRerankModel.class));
162+
163+
var rerankModel = (IbmWatsonxRerankModel) model;
164+
assertThat(rerankModel.getServiceSettings().modelId(), is(modelId));
165+
assertThat(rerankModel.getServiceSettings().projectId(), is(projectId));
166+
assertThat(rerankModel.getServiceSettings().apiVersion(), is(apiVersion));
167+
assertThat(rerankModel.getSecretSettings().apiKey().toString(), is(apiKey));
168+
}, e -> fail("Model parsing should have succeeded, but failed: " + e.getMessage()));
169+
170+
service.parseRequestConfig(
171+
"id",
172+
TaskType.RERANK,
173+
getRequestConfigMap(
174+
new HashMap<>(
175+
Map.of(
176+
ServiceFields.MODEL_ID,
177+
modelId,
178+
IbmWatsonxServiceFields.PROJECT_ID,
179+
projectId,
180+
ServiceFields.URL,
181+
url,
182+
IbmWatsonxServiceFields.API_VERSION,
183+
apiVersion
184+
)
185+
),
186+
new HashMap<>(Map.of()),
187+
getSecretSettingsMap(apiKey)
188+
),
189+
modelListener
190+
);
191+
}
192+
}
193+
157194
public void testParseRequestConfig_CreatesAIbmWatsonxEmbeddingsModelWhenChunkingSettingsProvided() throws IOException {
158195
try (var service = createIbmWatsonxService()) {
159196
ActionListener<Model> modelListener = ActionListener.wrap(model -> {

0 commit comments

Comments
 (0)