Package dev.dokimos.springai
Class SpringAiSupport
java.lang.Object
dev.dokimos.springai.SpringAiSupport
Utilities for integrating with Spring AI.
This class provides bridge methods to use Spring AI components with the Dokimos evaluation framework.
Using Spring AI ChatClient as a Judge
ChatClient.Builder clientBuilder = ChatClient.builder(chatModel);
JudgeLM judge = SpringAiSupport.asJudge(clientBuilder);
var evaluator = FaithfulnessEvaluator.builder()
.judge(judge)
.build();
Converting Spring AI Evaluation Objects
// Convert Spring AI EvaluationRequest to Dokimos EvalTestCase
EvaluationRequest request = ...;
EvalTestCase testCase = SpringAiSupport.toTestCase(request);
// Run Dokimos evaluation
EvalResult result = evaluator.evaluate(testCase);
// Convert back to Spring AI EvaluationResponse
EvaluationResponse response = SpringAiSupport.toEvaluationResponse(result);
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic JudgeLMasJudge(org.springframework.ai.chat.client.ChatClient.Builder builder) Creates aJudgeLMfrom a Spring AIChatClient.Builder.static JudgeLMasJudge(org.springframework.ai.chat.model.ChatModel model) Creates aJudgeLMfrom a Spring AIChatModel.static org.springframework.ai.evaluation.EvaluationResponsetoEvaluationResponse(EvalResult result) Converts a DokimosEvalResultto a Spring AIEvaluationResponse.static EvalTestCasetoTestCase(org.springframework.ai.evaluation.EvaluationRequest request) Converts a Spring AIEvaluationRequestto a DokimosEvalTestCase.
-
Field Details
-
OUTPUT_KEY
Default key for the model output in evaluation results.- See Also:
-
CONTEXT_KEY
Default key for additional context in evaluation results.- See Also:
-
INPUT_KEY
Default key for reading input from dataset examples.- See Also:
-
-
Method Details
-
asJudge
Creates aJudgeLMfrom a Spring AIChatClient.Builder.Use this to create judges for LLM-based evaluators like
LLMJudgeEvaluator,FaithfulnessEvaluator, etc.Example:
ChatClient.Builder clientBuilder = ChatClient.builder(chatModel); JudgeLM judge = SpringAiSupport.asJudge(clientBuilder); var evaluator = LLMJudgeEvaluator.builder() .judge(judge) .criteria("Is the response helpful?") .build();- Parameters:
builder- the ChatClient.Builder to use as judge- Returns:
- a JudgeLM that delegates to the ChatClient
-
asJudge
Creates aJudgeLMfrom a Spring AIChatModel.This is a convenience overload that accepts a ChatModel directly instead of a
ChatClient.Builder.Example:
ChatModel chatModel = OpenAiChatModel.builder()...build(); JudgeLM judge = SpringAiSupport.asJudge(chatModel); var evaluator = FaithfulnessEvaluator.builder() .judge(judge) .build();- Parameters:
model- the ChatModel to use as judge- Returns:
- a JudgeLM that delegates to the ChatModel
-
toTestCase
Converts a Spring AIEvaluationRequestto a DokimosEvalTestCase.Maps the following fields:
getUserText()→ inputgetResponseContent()→ actual outputgetDataList()→ context (list of document contents)
Example:
EvaluationRequest request = new EvaluationRequest( userText, retrievedDocuments, responseContent); EvalTestCase testCase = SpringAiSupport.toTestCase(request); EvalResult result = faithfulnessEvaluator.evaluate(testCase);- Parameters:
request- the Spring AI evaluation request- Returns:
- an EvalTestCase containing the request data
-
toEvaluationResponse
public static org.springframework.ai.evaluation.EvaluationResponse toEvaluationResponse(EvalResult result) Converts a DokimosEvalResultto a Spring AIEvaluationResponse.Maps the following fields:
score-> metadata["score"] (as float)success-> pass/fail statusreason-> the reasoning textmetadata-> preserved in response metadata
Example:
EvalResult result = evaluator.evaluate(testCase); EvaluationResponse response = SpringAiSupport.toEvaluationResponse(result); System.out.println("Score: " + response.getMetadata().get("score")); System.out.println("Passed: " + response.isPass()); System.out.println("Feedback: " + response.getFeedback());- Parameters:
result- the Dokimos evaluation result- Returns:
- an EvaluationResponse containing the result data
-