Skip to content

Commit

Permalink
Ignore known annotations in parameter binding
Browse files Browse the repository at this point in the history
Fixes: #88
  • Loading branch information
geoand committed Dec 4, 2023
1 parent 18ab50d commit ca6979c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private List<TemplateParameterInfo> gatherTemplateParamInfo(List<MethodParameter

List<TemplateParameterInfo> templateParams = new ArrayList<>();
for (MethodParameterInfo param : params) {
if (param.annotations().isEmpty()) { // if a parameter has no annotations it is considered a template variable
if (effectiveParamAnnotations(param).isEmpty()) { // if a parameter has no annotations it is considered a template variable
templateParams.add(new TemplateParameterInfo(param.position(), param.name()));
} else {
AnnotationInstance vInstance = param.annotation(V);
Expand All @@ -581,6 +581,19 @@ private List<TemplateParameterInfo> gatherTemplateParamInfo(List<MethodParameter
return templateParams;
}

private List<AnnotationInstance> effectiveParamAnnotations(MethodParameterInfo param) {
return param.annotations().stream().filter(ai -> {
String name = ai.name().toString();
if (name.startsWith("kotlin")) {
return false;
}
if (name.endsWith("NotNull")) {
return false;
}
return true;
}).collect(Collectors.toList());
}

private Optional<AiServiceMethodCreateInfo.TemplateInfo> gatherSystemMessageInfo(MethodInfo method,
List<TemplateParameterInfo> templateParams) {
AnnotationInstance instance = method.annotation(Langchain4jDotNames.SYSTEM_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;

import jakarta.validation.constraints.NotNull;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void test_simple_instruction_with_single_argument_and_no_annotations() th
interface Humorist {

@UserMessage("Tell me a joke about {{it}}")
String joke(String topic);
String joke(@NotNull String topic);
}

@Test
Expand Down

0 comments on commit ca6979c

Please sign in to comment.