|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.inference.services.custom; |
9 | 9 |
|
| 10 | +import org.elasticsearch.ElasticsearchStatusException; |
10 | 11 | import org.elasticsearch.action.support.PlainActionFuture; |
| 12 | +import org.elasticsearch.common.Strings; |
11 | 13 | import org.elasticsearch.core.Nullable; |
12 | 14 | import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper; |
13 | 15 | import org.elasticsearch.inference.InferenceServiceResults; |
@@ -269,6 +271,42 @@ private static CustomServiceSettings.TextEmbeddingSettings getDefaultTextEmbeddi |
269 | 271 | : CustomServiceSettings.TextEmbeddingSettings.NON_TEXT_EMBEDDING_TASK_TYPE_SETTINGS; |
270 | 272 | } |
271 | 273 |
|
| 274 | + public void testInfer_ReturnsAnError_WithoutParsingTheResponseBody() throws IOException { |
| 275 | + try (var service = createService(threadPool, clientManager)) { |
| 276 | + String responseJson = "error"; |
| 277 | + |
| 278 | + webServer.enqueue(new MockResponse().setResponseCode(400).setBody(responseJson)); |
| 279 | + |
| 280 | + var model = createInternalEmbeddingModel(new TextEmbeddingResponseParser("$.data[*].embedding"), getUrl(webServer)); |
| 281 | + PlainActionFuture<InferenceServiceResults> listener = new PlainActionFuture<>(); |
| 282 | + service.infer( |
| 283 | + model, |
| 284 | + null, |
| 285 | + null, |
| 286 | + null, |
| 287 | + List.of("test input"), |
| 288 | + false, |
| 289 | + new HashMap<>(), |
| 290 | + InputType.INTERNAL_SEARCH, |
| 291 | + InferenceAction.Request.DEFAULT_TIMEOUT, |
| 292 | + listener |
| 293 | + ); |
| 294 | + |
| 295 | + var exception = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT)); |
| 296 | + |
| 297 | + assertThat( |
| 298 | + exception.getMessage(), |
| 299 | + is( |
| 300 | + Strings.format( |
| 301 | + "Received an unsuccessful status code for request " |
| 302 | + + "from inference entity id [inference_id] status [400]. Error message: [%s]", |
| 303 | + responseJson |
| 304 | + ) |
| 305 | + ) |
| 306 | + ); |
| 307 | + } |
| 308 | + } |
| 309 | + |
272 | 310 | public void testInfer_HandlesTextEmbeddingRequest_OpenAI_Format() throws IOException { |
273 | 311 | try (var service = createService(threadPool, clientManager)) { |
274 | 312 | String responseJson = """ |
|
0 commit comments