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 869e511
Show file tree
Hide file tree
Showing 2 changed files with 17 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 @@ -23,6 +23,8 @@
import java.util.Map;
import java.util.Optional;

import jakarta.validation.constraints.NotNull;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -121,7 +123,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 869e511

Please sign in to comment.