All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.langchain4j.guardrails.OutputGuardrailParams Maven / Gradle / Ivy

There is a newer version: 0.21.0
Show newest version
package io.quarkiverse.langchain4j.guardrails;

import java.util.List;
import java.util.Map;

import dev.langchain4j.agent.tool.ToolExecutionRequest;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.rag.AugmentationResult;

/**
 * Represents the parameter passed to {@link OutputGuardrail#validate(OutputGuardrailParams)}.
 *
 * @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, 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,
        Map variables) implements GuardrailParams {

    @Override
    public OutputGuardrailParams withText(String text) {
        List tools = responseFromLLM.toolExecutionRequests();
        AiMessage aiMessage = tools != null && !tools.isEmpty() ? new AiMessage(text, tools) : new AiMessage(text);
        return new OutputGuardrailParams(aiMessage, memory, augmentationResult, userMessageTemplate, variables);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy