1111from fmcore .mapper .llm_response_json_mapper import LLMResponseJsonMapper
1212from fmcore .mapper .criteria_checker_mapper import CriteriaCheckerMapper
1313from fmcore .mapper .llm_inference_mapper import LLMInferenceMapper
14+ from fmcore .utils .logging_utils import Log
1415
1516
1617class LLMAsJudgeBooleanEvaluator (BaseEvaluator [Dict , bool ]):
@@ -72,19 +73,38 @@ def _get_instance(cls, *, evaluator_config: EvaluatorConfig) -> "LLMAsJudgeBoole
7273
7374 def evaluate (self , data : Dict ) -> bool :
7475 """
75- Processes the input data by using the llm_as_a_judge_boolean_mapper to evaluate the context.
76+ Processes the input data using the llm_as_a_judge_boolean_mapper to evaluate the context.
7677
7778 Args:
7879 data (BooleanLLMJudgeInput): Input data containing context for evaluation.
7980
8081 Returns:
81- BooleanLLMJudgeOutput : Evaluation result as a boolean decision.
82+ bool : Evaluation result as a boolean decision.
8283 """
83- # Format the context into messages using the template
84- formatted_message : BaseMessage = self .text_prompt_mapper .map (data )
85- llm_response : BaseMessage = self .llm_inference_mapper .map ([formatted_message ])
86- json_response : Dict = self .json_mapper .map (llm_response .content )
87- decision : bool = self .criteria_checker .map (json_response )
84+ formatted_message = llm_response = json_response = decision = None
85+
86+ try :
87+ formatted_message = self .text_prompt_mapper .map (data )
88+ llm_response = self .llm_inference_mapper .map ([formatted_message ])
89+ json_response = self .json_mapper .map (llm_response .content )
90+ decision = self .criteria_checker .map (json_response )
91+
92+ if not isinstance (decision , bool ):
93+ raise ValueError ("Decision is not a boolean value" )
94+
95+ except Exception as e :
96+ Log .error (
97+ "[SYNC EVALUATION ERROR]\t \t ->"
98+ f"[INPUT DATA]: { data } \t \t ->"
99+ f"[PROMPT]: { self .evaluator_config .evaluator_params .prompt } \t \t ->"
100+ f"[FORMATTED MESSAGE]: { formatted_message } \t \t ->"
101+ f"[LLM RESPONSE]: { llm_response } \t \t ->"
102+ f"[JSON RESPONSE]: { json_response } \t \t ->"
103+ f"[DECISION]: { decision } \t \t ->"
104+ f"[ERROR]: { e } "
105+ )
106+ raise
107+
88108 return decision
89109
90110 async def aevaluate (self , data : Dict ) -> bool :
@@ -95,11 +115,30 @@ async def aevaluate(self, data: Dict) -> bool:
95115 data (BooleanLLMJudgeInput): Input data containing context for evaluation.
96116
97117 Returns:
98- BooleanLLMJudgeOutput : Evaluation result as a boolean decision.
118+ bool : Evaluation result as a boolean decision.
99119 """
100- # Format the context into messages using the template
101- formatted_message : BaseMessage = await self .text_prompt_mapper .amap (data )
102- llm_response : BaseMessage = await self .llm_inference_mapper .amap ([formatted_message ])
103- json_response : Dict = await self .json_mapper .amap (llm_response .content )
104- decision : bool = await self .criteria_checker .amap (json_response )
120+ formatted_message = llm_response = json_response = decision = None
121+
122+ try :
123+ formatted_message = await self .text_prompt_mapper .amap (data )
124+ llm_response = await self .llm_inference_mapper .amap ([formatted_message ])
125+ json_response = await self .json_mapper .amap (llm_response .content )
126+ decision = await self .criteria_checker .amap (json_response )
127+
128+ if not isinstance (decision , bool ):
129+ raise ValueError ("Decision is not a boolean value" )
130+
131+ except Exception as e :
132+ Log .error (
133+ "[ASYNC EVALUATION ERROR]\t \t ->"
134+ f"[INPUT DATA]: { data } \t \t ->"
135+ f"[PROMPT]: { self .evaluator_config .evaluator_params .prompt } \t \t ->"
136+ f"[FORMATTED MESSAGE]: { formatted_message } \t \t ->"
137+ f"[LLM RESPONSE]: { llm_response } \t \t ->"
138+ f"[JSON RESPONSE]: { json_response } \t \t ->"
139+ f"[DECISION]: { decision } \t \t ->"
140+ f"[ERROR]: { e } "
141+ )
142+ raise
143+
105144 return decision
0 commit comments