diff --git a/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/__init__.py b/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/graph.py b/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/graph.py deleted file mode 100644 index 7369cdb78..000000000 --- a/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/graph.py +++ /dev/null @@ -1,30 +0,0 @@ -from typing import Literal -import metagpt.ext.aflow.scripts.optimized.MATH.workflows.template.operator as operator -import metagpt.ext.aflow.scripts.optimized.MATH.workflows.round_2.prompt as prompt_custom -from metagpt.provider.llm_provider_registry import create_llm_instance -from metagpt.utils.cost_manager import CostManager - -DatasetType = Literal["HumanEval", "MBPP", "GSM8K", "MATH", "HotpotQA", "DROP"] - -class Workflow: - def __init__( - self, - name: str, - llm_config, - dataset: DatasetType, - ) -> None: - self.name = name - self.dataset = dataset - self.llm = create_llm_instance(llm_config) - self.llm.cost_manager = CostManager() - self.custom = operator.Custom(self.llm) - self.sc_ensemble = operator.ScEnsemble(self.llm) - - async def __call__(self, problem: str): - """ - Implementation of the workflow - """ - initial_solution = await self.custom(input=problem, instruction=prompt_custom.INITIAL_SOLUTION_PROMPT) - revised_solution = await self.custom(input=problem + f"\nInitial solution: {initial_solution['response']}", instruction=prompt_custom.REVISE_SOLUTION_PROMPT) - final_solution = await self.sc_ensemble(solutions=[initial_solution['response'], revised_solution['response']], problem=problem) - return final_solution['response'], self.llm.cost_manager.total_cost diff --git a/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/prompt.py b/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/prompt.py deleted file mode 100644 index 80554beb8..000000000 --- a/metagpt/ext/aflow/scripts/optimized/MATH/workflows/round_2/prompt.py +++ /dev/null @@ -1,17 +0,0 @@ -INITIAL_SOLUTION_PROMPT = """ -You are a math expert tasked with solving a complex problem. Please provide a step-by-step solution to the given problem, showing all your work and explaining your reasoning clearly. If the problem involves calculations, make sure to include them in your response. - -Problem: -""" - -REVISE_SOLUTION_PROMPT = """ -You are a math expert tasked with reviewing and improving a solution to a complex problem. An initial solution has been provided, but it may contain errors or be incomplete. Your task is to carefully review the initial solution, identify any mistakes or areas for improvement, and provide a revised, more accurate solution. - -Please follow these steps: -1. Review the initial solution thoroughly. -2. Identify any errors or areas that need improvement. -3. Provide a revised solution, explaining your changes and reasoning. -4. Ensure your revised solution is complete, accurate, and clearly explained. - -Problem: -""" \ No newline at end of file diff --git a/optimize.py b/optimize.py deleted file mode 100644 index 1ba938af4..000000000 --- a/optimize.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -# @Date : 8/23/2024 20:00 PM -# @Author : didi -# @Desc : Entrance of AFlow. - - -from metagpt.configs.models_config import ModelsConfig -from metagpt.ext.aflow.data.download_data import download -from metagpt.ext.aflow.scripts.optimizer import DatasetType, Optimizer, QuestionType - -# DatasetType, QuestionType, and OptimizerType definitions -# DatasetType = Literal["HumanEval", "MBPP", "GSM8K", "MATH", "HotpotQA", "DROP"] -# QuestionType = Literal["math", "code", "qa"] -# OptimizerType = Literal["Graph", "Test"] - -# When you fisrt use, please download the datasets and initial rounds; If you want to get a look of the results, please download the results. -download(["datasets", "initial_rounds"]) - -# Crucial Parameters -dataset: DatasetType = "MATH" # Ensure the type is consistent with DatasetType -sample: int = 4 # Sample Count, which means how many workflows will be resampled from generated workflows -question_type: QuestionType = "math" # Ensure the type is consistent with QuestionType -optimized_path: str = "metagpt/ext/aflow/scripts/optimized" # Optimized Result Save Path -initial_round: int = 1 # Corrected the case from Initial_round to initial_round -max_rounds: int = 20 # The max iteration of AFLOW. -check_convergence: bool = True # Whether Early Stop -validation_rounds: int = 5 # The validation rounds of AFLOW. - -# Config llm model, you can modify `config/config2.yaml` to use more llms. -mini_llm_config = ModelsConfig.default().get("gpt-4o-mini") -claude_llm_config = ModelsConfig.default().get("claude-3-5-sonnet-20240620") - -# Config operators. -operators = [ - "Custom", # It's basic unit of a fixed node. optimizer can modify its prompt to get vairous nodes. - # "AnswerGenerate", # It's for qa - # "CustomCodeGenerate", # It's for code - "ScEnsemble", # It's for code, math and qa - # "Test", # It's for code - "Programmer", # It's for math -] - -# Create an optimizer instance -optimizer = Optimizer( - dataset=dataset, # Config dataset - question_type=question_type, # Config Question Type - opt_llm_config=claude_llm_config, # Config Optimizer LLM - exec_llm_config=mini_llm_config, # Config Execution LLM - check_convergence=check_convergence, # Whether Early Stop - operators=operators, # Config Operators you want to use - optimized_path=optimized_path, # Config Optimized workflow's file path - sample=sample, # Only Top(sample) rounds will be selected. - initial_round=initial_round, # Optimize from initial round - max_rounds=max_rounds, # The max iteration of AFLOW. - validation_rounds=validation_rounds, # The validation rounds of AFLOW. -) - -if __name__ == "__main__": - # Optimize workflow via setting the optimizer's mode to 'Graph' - optimizer.optimize("Graph") - # Test workflow via setting the optimizer's mode to 'Test' - # optimizer.optimize("Test")