Update AFlow

This commit is contained in:
didi 2024-10-17 15:47:09 +08:00
parent cea3473002
commit 6aedc4a068
70 changed files with 1516 additions and 178 deletions

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# @Date : 8/23/2024 20:00 PM
# @Author : didi
# @Desc : Experiment of graph optimization
# @Desc : Entrance of AFlow.
from examples.aflow.scripts.optimizer import Optimizer
from metagpt.configs.models_config import ModelsConfig
@ -13,40 +13,44 @@ QuestionType = Literal["math", "code", "quiz"]
OptimizerType = Literal["Graph", "Test"]
# Crucial Parameters
dataset: DatasetType = "GSM8K" # Ensure the type is consistent with DatasetType
dataset: DatasetType = "HotpotQA" # 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
question_type: QuestionType = "quiz" # Ensure the type is consistent with QuestionType
optimized_path: str = "examples/aflow/scripts/optimized" # Optimized Result Save Path
initial_round: int = 1 # Corrected the case from Initial_round to initial_round
max_rounds: int = 20
check_convergence: bool = True
# Initialize LLM Model
four_o_llm_config = ModelsConfig.default().get("gpt-4o")
deepseek_llm_config = ModelsConfig.default().get("deepseek-chat")
# 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")
# Initialize Operators List
# Config operators.
operators = [
"Custom"
"Custom", # It's basic unit of a fixed node. optimizer can modify its prompt to get vairous nodes.
# "CustomCodeGenerate", # It's for code
# "Test", # It's for code
"ScEnsemble", # It's for code, math and QA
# "Programmer", # It's for math
"AnswerGenerate" # It's for QA
]
# Create an optimizer instance
optimizer = Optimizer(
dataset=dataset,
question_type=question_type,
opt_llm_config=claude_llm_config,
exec_llm_config=mini_llm_config,
check_convergence=check_convergence,
operators=operators,
optimized_path=optimized_path,
sample=sample,
initial_round=initial_round,
max_rounds=max_rounds
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.
)
if __name__ == "__main__":
# Run the optimizer
# 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")