@@ -405,21 +405,14 @@ def _parse_config(self, config: Union[DictConfig, Dict[str, Any]]):
405405 def _build_messages (self , example : dict ) -> List [dict ]:
406406 """Build chat messages from example - Pointwise mode with text format only."""
407407 messages = []
408-
409- # Check if it's the new JSON structure (has 'input' key with nested structure)
410- if "input" in example and isinstance (example ["input" ], dict ) and "query" in example ["input" ]:
411- # New JSON format
408+ # Check if example has 'query' directly at top level
409+ if "query" in example and isinstance (example ["query" ], str ) and example ["query" ]:
410+ query = example ["query" ]
411+ messages .append ({"role" : "user" , "content" : query })
412+ # Check if example has 'input' key with nested structure
413+ elif "input" in example and isinstance (example ["input" ], dict ) and "query" in example ["input" ]:
412414 query = example ["input" ].get ("query" , "" )
413- if query :
414- messages .append ({"role" : "user" , "content" : query })
415-
416- # Get chosen response (positive example)
417- if "chosen" in example and isinstance (example ["chosen" ], dict ):
418- response_data = example ["chosen" ].get ("response" , {})
419- if isinstance (response_data , dict ):
420- response_content = response_data .get ("content" , "" )
421- if response_content :
422- messages .append ({"role" : "assistant" , "content" : response_content })
415+ messages .append ({"role" : "user" , "content" : query })
423416 else :
424417 # Old format - handle standard structure
425418 messages = self ._build_old_format_messages (example )
@@ -615,8 +608,37 @@ def _format_grader_template(self, messages: List[dict], example: dict, grader_pr
615608 memory = ""
616609 action = ""
617610 reflection = ""
618- if "input" in example and isinstance (example ["input" ], dict ) and "query" in example ["input" ]:
619- # New JSON format
611+ query = ""
612+
613+ # Check if example has fields directly at top level
614+ if "query" in example and isinstance (example ["query" ], str ):
615+ query = example .get ("query" , "" )
616+ if "context" in example :
617+ context = example .get ("context" , "" )
618+ if isinstance (context , str ):
619+ try :
620+ parsed_data = json .loads (context )
621+ if isinstance (parsed_data , dict ):
622+ context = parsed_data .get ("task_context" , "" )
623+ tool_definitions = parsed_data .get ("tool_definitions" , "" )
624+ history = parsed_data .get ("history" , "" )
625+ except (json .JSONDecodeError , TypeError , Exception ):
626+ pass
627+ elif isinstance (context , dict ):
628+ context = context .get ("task_context" , "" )
629+ tool_definitions = context .get ("tool_definitions" , "" )
630+ history = context .get ("history" , "" )
631+ reference_response = example .get ("reference_response" , "" )
632+ # Extract fields directly from example top level
633+ response = example .get ("response" , "" )
634+ tool_calls = example .get ("tool_calls" , "" )
635+ tool_responses = example .get ("tool_responses" , "" )
636+ plan = example .get ("plan" , "" )
637+ observation = example .get ("observation" , "" )
638+ memory = example .get ("memory" , "" )
639+ action = example .get ("action" , "" )
640+ reflection = example .get ("reflection" , "" )
641+ elif "input" in example and isinstance (example ["input" ], dict ) and "query" in example ["input" ]:
620642 query = example ["input" ].get ("query" , "" )
621643 context = example ["input" ].get ("context" , "" )
622644 if context :
0 commit comments