|
22 | 22 | import static org.mockito.Mockito.mock;
|
23 | 23 | import static org.mockito.Mockito.verify;
|
24 | 24 | import static org.mockito.Mockito.when;
|
| 25 | +import static org.opensearch.searchpipelines.questionanswering.generative.GenerativeQAResponseProcessor.IllegalArgumentMessage; |
25 | 26 |
|
26 | 27 | import java.time.Instant;
|
27 | 28 | import java.util.Collections;
|
@@ -407,4 +408,57 @@ public void testProcessorFeatureOffOnOff() throws Exception {
|
407 | 408 | }
|
408 | 409 | assertTrue(secondExceptionThrown);
|
409 | 410 | }
|
| 411 | + |
| 412 | + public void testProcessResponseNullValueInteractions() throws Exception { |
| 413 | + exceptionRule.expect(IllegalArgumentException.class); |
| 414 | + exceptionRule.expectMessage(IllegalArgumentMessage); |
| 415 | + |
| 416 | + Client client = mock(Client.class); |
| 417 | + Map<String, Object> config = new HashMap<>(); |
| 418 | + config.put(GenerativeQAProcessorConstants.CONFIG_NAME_MODEL_ID, "dummy-model"); |
| 419 | + config.put(GenerativeQAProcessorConstants.CONFIG_NAME_CONTEXT_FIELD_LIST, List.of("text")); |
| 420 | + |
| 421 | + GenerativeQAResponseProcessor processor = (GenerativeQAResponseProcessor) new GenerativeQAResponseProcessor.Factory( |
| 422 | + client, |
| 423 | + alwaysOn |
| 424 | + ).create(null, "tag", "desc", true, config, null); |
| 425 | + |
| 426 | + ConversationalMemoryClient memoryClient = mock(ConversationalMemoryClient.class); |
| 427 | + when(memoryClient.getInteractions(any(), anyInt())) |
| 428 | + .thenReturn(List.of(new Interaction("0", Instant.now(), "1", null, null, null, null, null))); |
| 429 | + processor.setMemoryClient(memoryClient); |
| 430 | + |
| 431 | + SearchRequest request = new SearchRequest(); |
| 432 | + SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); |
| 433 | + int contextSize = 5; |
| 434 | + GenerativeQAParameters params = new GenerativeQAParameters("12345", "llm_model", "You are kind.", contextSize, null, null); |
| 435 | + GenerativeQAParamExtBuilder extBuilder = new GenerativeQAParamExtBuilder(); |
| 436 | + extBuilder.setParams(params); |
| 437 | + request.source(sourceBuilder); |
| 438 | + sourceBuilder.ext(List.of(extBuilder)); |
| 439 | + |
| 440 | + int numHits = 10; |
| 441 | + SearchHit[] hitsArray = new SearchHit[numHits]; |
| 442 | + for (int i = 0; i < numHits; i++) { |
| 443 | + XContentBuilder sourceContent = JsonXContent |
| 444 | + .contentBuilder() |
| 445 | + .startObject() |
| 446 | + .field("_id", String.valueOf(i)) |
| 447 | + .field("text", "passage" + i) |
| 448 | + .field("title", "This is the title for document " + i) |
| 449 | + .endObject(); |
| 450 | + hitsArray[i] = new SearchHit(i, "doc" + i, Map.of(), Map.of()); |
| 451 | + hitsArray[i].sourceRef(BytesReference.bytes(sourceContent)); |
| 452 | + } |
| 453 | + |
| 454 | + SearchHits searchHits = new SearchHits(hitsArray, null, 1.0f); |
| 455 | + SearchResponseSections internal = new SearchResponseSections(searchHits, null, null, false, false, null, 0); |
| 456 | + SearchResponse response = new SearchResponse(internal, null, 1, 1, 0, 1, null, null, null); |
| 457 | + |
| 458 | + Llm llm = mock(Llm.class); |
| 459 | + when(llm.doChatCompletion(any())).thenThrow(new NullPointerException("Null Pointer in Interactions")); |
| 460 | + processor.setLlm(llm); |
| 461 | + |
| 462 | + SearchResponse res = processor.processResponse(request, response); |
| 463 | + } |
410 | 464 | }
|
0 commit comments