|
3 | 3 | import com.comet.opik.api.FeedbackScoreBatchItem;
|
4 | 4 | import com.comet.opik.api.ScoreSource;
|
5 | 5 | import com.comet.opik.api.Trace;
|
| 6 | +import com.comet.opik.utils.MustacheUtils; |
6 | 7 | import com.fasterxml.jackson.core.JsonProcessingException;
|
7 | 8 | import com.fasterxml.jackson.databind.JsonNode;
|
8 | 9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
|
26 | 27 | import lombok.Builder;
|
27 | 28 | import lombok.experimental.UtilityClass;
|
28 | 29 | import lombok.extern.slf4j.Slf4j;
|
29 |
| -import org.apache.commons.text.StringSubstitutor; |
30 | 30 |
|
31 | 31 | import java.util.Arrays;
|
32 | 32 | import java.util.Collections;
|
|
46 | 46 | @Slf4j
|
47 | 47 | public class OnlineScoringEngine {
|
48 | 48 |
|
49 |
| - final String SCORE_FIELD_NAME = "score"; |
50 |
| - final String REASON_FIELD_NAME = "reason"; |
51 |
| - final String SCORE_FIELD_DESCRIPTION = "the score for "; |
52 |
| - final String REASON_FIELD_DESCRIPTION = "the reason for the score for "; |
53 |
| - final String DEFAULT_SCHEMA_NAME = "scoring_schema"; |
| 49 | + static final String SCORE_FIELD_NAME = "score"; |
| 50 | + static final String REASON_FIELD_NAME = "reason"; |
| 51 | + static final String SCORE_FIELD_DESCRIPTION = "the score for "; |
| 52 | + static final String REASON_FIELD_DESCRIPTION = "the reason for the score for "; |
| 53 | + static final String DEFAULT_SCHEMA_NAME = "scoring_schema"; |
54 | 54 |
|
55 | 55 | /**
|
56 | 56 | * Prepare a request to a LLM-as-Judge evaluator (a ChatLanguageModel) rendering the template messages with
|
@@ -103,14 +103,10 @@ static List<ChatMessage> renderMessages(List<LlmAsJudgeMessage> templateMessages
|
103 | 103 | .collect(
|
104 | 104 | Collectors.toMap(MessageVariableMapping::variableName, MessageVariableMapping::valueToReplace));
|
105 | 105 |
|
106 |
| - // will convert all '{{key}}' into 'value' |
107 |
| - // TODO: replace with Mustache Java to be in confirm with FE |
108 |
| - var templateRenderer = new StringSubstitutor(replacements, "{{", "}}"); |
109 |
| - |
110 | 106 | // render the message templates from evaluator rule
|
111 | 107 | return templateMessages.stream()
|
112 | 108 | .map(templateMessage -> {
|
113 |
| - var renderedMessage = templateRenderer.replace(templateMessage.content()); |
| 109 | + var renderedMessage = MustacheUtils.render(templateMessage.content(), replacements); |
114 | 110 |
|
115 | 111 | return switch (templateMessage.role()) {
|
116 | 112 | case USER -> UserMessage.from(renderedMessage);
|
|
0 commit comments