Skip to content

Commit

Permalink
946 - User message template and variables cannot be null.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennysfredericci committed Oct 30, 2024
1 parent 5f55595 commit aaaa41b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void shouldWorkWithMemoryIdAndOneItemFromList() {
void shouldWorkWithNoUserMessage() {
// UserMessage annotation is not provided, then no user message template should be available
aiService.saySomething("Is this a parameter or a prompt?");
assertThat(guardrailValidation.spyUserMessageTemplate()).isNull();
assertThat(guardrailValidation.spyUserMessageTemplate()).isEmpty();
assertThat(guardrailValidation.spyVariables()).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void shouldWorkWithMemoryIdAndOneItemFromList() {
void shouldWorkWithNoUserMessage() {
// UserMessage annotation is not provided, then no user message template should be available
aiService.saySomething("Is this a parameter or a prompt?");
assertThat(guardrailValidation.spyUserMessageTemplate()).isNull();
assertThat(guardrailValidation.spyUserMessageTemplate()).isEmpty();
assertThat(guardrailValidation.spyVariables()).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* @param userMessage the user message, cannot be {@code null}
* @param memory the memory, can be {@code null} or empty
* @param augmentationResult the augmentation result, can be {@code null}
* @param userMessageTemplate the user message template, can be {@code null} when @UserMessage is not provided.
* @param variables the variable to be used with userMessageTemplate, can be {@code null} or empty
* @param userMessageTemplate the user message template, cannot be {@code null}
* @param variables the variable to be used with userMessageTemplate, cannot be {@code null}
*/
public record InputGuardrailParams(UserMessage userMessage, ChatMemory memory,
AugmentationResult augmentationResult, String userMessageTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* @param responseFromLLM the response from the LLM
* @param memory the memory, can be {@code null} or empty
* @param augmentationResult the augmentation result, can be {@code null}
* @param userMessageTemplate the user message template, can be {@code null} when @UserMessage is not provided.
* @param variables the variable to be used with userMessageTemplate, can be {@code null} or empty
* @param userMessageTemplate the user message template, cannot be {@code null}
* @param variables the variable to be used with userMessageTemplate, cannot be {@code null}
*/
public record OutputGuardrailParams(AiMessage responseFromLLM, ChatMemory memory,
AugmentationResult augmentationResult, String userMessageTemplate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkiverse.langchain4j.runtime.aiservice;

import static org.apache.commons.lang3.StringUtils.EMPTY;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -197,7 +199,7 @@ public String getUserMessageTemplate() {
Optional<String> userMessageTemplateOpt = this.getUserMessageInfo().template()
.flatMap(AiServiceMethodCreateInfo.TemplateInfo::text);

return userMessageTemplateOpt.orElse(null);
return userMessageTemplateOpt.orElse(EMPTY);
}

public record UserMessageInfo(Optional<TemplateInfo> template,
Expand Down

0 comments on commit aaaa41b

Please sign in to comment.