-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from cescoffier/response-augmenter
Initial implementation of the response augmenter idea.
- Loading branch information
Showing
26 changed files
with
1,584 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
.../src/main/java/io/quarkiverse/langchain4j/deployment/items/AiServicesMethodBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package io.quarkiverse.langchain4j.deployment.items; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.jboss.jandex.Type; | ||
|
||
import io.quarkiverse.langchain4j.guardrails.OutputGuardrailAccumulator; | ||
import io.quarkiverse.langchain4j.response.ResponseAugmenter; | ||
import io.quarkiverse.langchain4j.runtime.aiservice.AiServiceMethodCreateInfo; | ||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* A build item representing a method from an AI service. | ||
*/ | ||
public final class AiServicesMethodBuildItem extends MultiBuildItem { | ||
|
||
private final MethodInfo methodInfo; | ||
private final List<String> outputGuardrails; | ||
private final List<String> inputGuardrails; | ||
private final AiServiceMethodCreateInfo methodCreateInfo; | ||
private final String responseAugmenter; | ||
|
||
public AiServicesMethodBuildItem(MethodInfo methodInfo, List<String> inputGuardrails, List<String> outputGuardrails, | ||
String responseAugmenter, | ||
AiServiceMethodCreateInfo methodCreateInfo) { | ||
this.methodInfo = methodInfo; | ||
this.inputGuardrails = inputGuardrails; | ||
this.outputGuardrails = outputGuardrails; | ||
this.responseAugmenter = responseAugmenter; | ||
this.methodCreateInfo = methodCreateInfo; | ||
} | ||
|
||
public List<String> getOutputGuardrails() { | ||
return outputGuardrails; | ||
} | ||
|
||
public List<String> getInputGuardrails() { | ||
return inputGuardrails; | ||
} | ||
|
||
public MethodInfo getMethodInfo() { | ||
return methodInfo; | ||
} | ||
|
||
public AiServiceMethodCreateInfo getMethodCreateInfo() { | ||
return methodCreateInfo; | ||
} | ||
|
||
public String getResponseAugmenter() { | ||
return responseAugmenter; | ||
} | ||
|
||
public static List<String> gatherGuardrails(MethodInfo methodInfo, DotName annotation) { | ||
List<String> guardrails = new ArrayList<>(); | ||
AnnotationInstance instance = methodInfo.annotation(annotation); | ||
if (instance == null) { | ||
// Check on class | ||
instance = methodInfo.declaringClass().declaredAnnotation(annotation); | ||
} | ||
if (instance != null) { | ||
Type[] array = instance.value().asClassArray(); | ||
for (Type type : array) { | ||
// Make sure each guardrail is used only once | ||
if (!guardrails.contains(type.name().toString())) { | ||
guardrails.add(type.name().toString()); | ||
} | ||
} | ||
} | ||
return guardrails; | ||
} | ||
|
||
public static String gatherAccumulator(MethodInfo methodInfo) { | ||
DotName annotation = DotName.createSimple(OutputGuardrailAccumulator.class); | ||
AnnotationInstance instance = methodInfo.annotation(annotation); | ||
if (instance == null) { | ||
// Check on class | ||
instance = methodInfo.declaringClass().declaredAnnotation(annotation); | ||
} | ||
if (instance != null) { | ||
return instance.value().asClass().name().toString(); | ||
} | ||
return null; | ||
} | ||
|
||
public static String gatherResponseAugmenter(MethodInfo methodInfo) { | ||
DotName annotation = DotName.createSimple(ResponseAugmenter.class); | ||
AnnotationInstance instance = methodInfo.annotation(annotation); | ||
if (instance == null) { | ||
// Check on class | ||
instance = methodInfo.declaringClass().declaredAnnotation(annotation); | ||
} | ||
if (instance != null) { | ||
return instance.value().asClass().name().toString(); | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.