Skip to content

Code extraction error for the previous substeps for specific questions 13, 62 and 76 #49

@amaand-cerebras

Description

@amaand-cerebras

The entire code is not being used for the previous code which causes a cascading issue in the next steps.

if self.previous_llm_code[prev_step] is None:
                    if (
                        (prob_id == "13" and prev_step == 5) or 
                        (prob_id == "62" and prev_step == 0) or 
                        (prob_id == "76" and prev_step == 2)
                    ):
                        prev_file_path = Path(
                            "../data",
                            f"{prob_id}.{prev_step+1}.txt"
                        )
                    else:
                        prev_file_path = Path(
                            self.output_dir,
                            self._get_background_dir(),
                            f"{prob_id}.{prev_step + 1}.py"
                        )
                    if prev_file_path.is_file():
                        prev_file_content = prev_file_path.read_text(encoding='utf-8')
                        func_name = extract_function_name(
                            prob_data["sub_steps"][prev_step]["function_header"]
                        )
                        function_code = get_function_from_code(
                            prev_file_content, func_name
                        )
                        self.previous_llm_code[prev_step] = function_code
                    else:
                        raise Exception(f'Generating problem {prob_id} step {num_steps} ahead of step {prev_step + 1}.')

A simple fix to this is to not do any extraction from the .txt files and use the entire code as it is:

if self.previous_llm_code[prev_step] is None:
                    if (
                        (prob_id == "13" and prev_step == 5) or 
                        (prob_id == "62" and prev_step == 0) or 
                        (prob_id == "76" and prev_step == 2)
                    ):
                        prev_file_path = Path(
                            "../data",
                            f"{prob_id}.{prev_step+1}.txt"
                        )
                    else:
                        prev_file_path = Path(
                            self.output_dir,
                            self._get_background_dir(),
                            f"{prob_id}.{prev_step + 1}.py"
                        )

                    if prev_file_path.is_file():
                        prev_file_content = prev_file_path.read_text(encoding='utf-8')
                        
                        if (
                            (prob_id == "13" and prev_step == 5) or 
                            (prob_id == "62" and prev_step == 0) or 
                            (prob_id == "76" and prev_step == 2)
                        ):
                            # Use the entire .txt content for these special cases
                            self.previous_llm_code[prev_step] = prev_file_content
                        else:
                            # Extract the function code for all other cases
                            func_name = extract_function_name(
                                prob_data["sub_steps"][prev_step]["function_header"]
                            )
                            function_code = get_function_from_code(
                                prev_file_content, func_name
                            )
                            self.previous_llm_code[prev_step] = function_code
                    else:
                        raise Exception(f'Generating problem {prob_id} step {num_steps} ahead of step {prev_step + 1}.')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions