From 869e511a7d108d169d7f42df85ea49e767c6ff59 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 4 Dec 2023 17:20:26 +0200 Subject: [PATCH] Ignore known annotations in parameter binding Fixes: #88 --- .../deployment/AiServicesProcessor.java | 15 ++++++++++++++- .../acme/examples/aiservices/AiServicesTest.java | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiServicesProcessor.java b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiServicesProcessor.java index 26240583e..f171adc34 100644 --- a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiServicesProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiServicesProcessor.java @@ -560,7 +560,7 @@ private List gatherTemplateParamInfo(List 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); @@ -581,6 +581,19 @@ private List gatherTemplateParamInfo(List 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 gatherSystemMessageInfo(MethodInfo method, List templateParams) { AnnotationInstance instance = method.annotation(Langchain4jDotNames.SYSTEM_MESSAGE); diff --git a/openai/openai-vanilla/deployment/src/test/java/org/acme/examples/aiservices/AiServicesTest.java b/openai/openai-vanilla/deployment/src/test/java/org/acme/examples/aiservices/AiServicesTest.java index be05454a4..86e122889 100644 --- a/openai/openai-vanilla/deployment/src/test/java/org/acme/examples/aiservices/AiServicesTest.java +++ b/openai/openai-vanilla/deployment/src/test/java/org/acme/examples/aiservices/AiServicesTest.java @@ -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; @@ -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