Commit 1b267152 authored by jameskrw's avatar jameskrw
Browse files

udpated format rule

parent 11d011aa
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -15,13 +15,14 @@ def parse_freethink(response: str, special_token_list=None, action_sep=',', max_
    - format_correct: whether the response strictly follows the expected format
    """
    # Pattern to check for content strictly in the format <think>...</think><answer>...</answer>
    strict_pattern = r'^\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*$'
    strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    format_correct = strict_match is not None
    # strict_pattern = r'^\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*$'
    # strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    
    
    # Pattern to extract content from think and answer tags
    extraction_pattern = r'<think>(.*?)</think>\s*<answer>(.*?)</answer>'
    match = re.search(extraction_pattern, response, re.DOTALL)
    format_correct = match is not None
    
    if not match:
        think_content, action_content, actions = "", "", []
@@ -59,13 +60,14 @@ def parse_no_think(response: str, special_token_list=None, action_sep=',', max_a
    - format_correct: whether the response strictly follows the expected format
    """
    # Pattern to check for content strictly in the format <answer>...</answer>
    strict_pattern = r'^\s*<answer>(.*?)</answer>\s*$'
    strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    format_correct = strict_match is not None
    # strict_pattern = r'^\s*<answer>(.*?)</answer>\s*$'
    # strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    # format_correct = strict_match is not None
    
    # Pattern to extract content from answer tag
    extraction_pattern = r'<answer>(.*?)</answer>'
    match = re.search(extraction_pattern, response, re.DOTALL)
    format_correct = match is not None
    
    if not match:
        think_content, action_content, actions = "", "", []
@@ -104,13 +106,14 @@ def parse_grounding(response: str, special_token_list=None, action_sep=',', max_
    - format_correct: whether the response strictly follows the expected format
    """
    # Pattern to check for content strictly in the expected format
    strict_pattern = r'^\s*<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*$'
    strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    format_correct = strict_match is not None
    # strict_pattern = r'^\s*<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*$'
    # strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    # format_correct = strict_match is not None
    
    # Pattern to extract content from tags
    extraction_pattern = r'<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>'
    match = re.search(extraction_pattern, response, re.DOTALL)
    format_correct = match is not None
    
    if not match:
        current_state_content, think_content, action_content, actions = "", "", "", []
@@ -153,13 +156,14 @@ def parse_worldmodeling(response: str, special_token_list=None, action_sep=',',
    - format_correct: whether the response strictly follows the expected format
    """
    # Pattern to check for content strictly in the expected format
    strict_pattern = r'^\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>\s*$'
    strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    format_correct = strict_match is not None
    # strict_pattern = r'^\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>\s*$'
    # strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    # format_correct = strict_match is not None
    
    # Pattern to extract content from tags
    extraction_pattern = r'<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>'
    match = re.search(extraction_pattern, response, re.DOTALL)
    format_correct = match is not None
    
    if not match:
        think_content, action_content, next_state_content, actions = "", "", "", []
@@ -203,13 +207,14 @@ def parse_grounding_worldmodeling(response: str, special_token_list=None, action
    - format_correct: whether the response strictly follows the expected format
    """
    # Pattern to check for content strictly in the expected format
    strict_pattern = r'^\s*<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>\s*$'
    strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    format_correct = strict_match is not None
    # strict_pattern = r'^\s*<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>\s*$'
    # strict_match = re.match(strict_pattern, response.strip(), re.DOTALL)
    # format_correct = strict_match is not None
    
    # Pattern to extract content from tags
    extraction_pattern = r'<current_state>(.*?)</current_state>\s*<think>(.*?)</think>\s*<answer>(.*?)</answer>\s*<next_state>(.*?)</next_state>'
    match = re.search(extraction_pattern, response, re.DOTALL)
    format_correct = match is not None
    
    if not match:
        current_state_content, think_content, action_content, next_state_content, actions = "", "", "", "", []