MetaGPT/optimize.py

52 lines
1.8 KiB
Python
Raw Normal View History

2024-08-23 20:43:29 +08:00
# -*- coding: utf-8 -*-
# @Date : 8/23/2024 20:00 PM
# @Author : didi
# @Desc : Experiment of graph optimization
2024-10-16 11:44:01 +08:00
from examples.aflow.scripts.optimizer import Optimizer
2024-08-26 08:40:10 +08:00
from metagpt.configs.models_config import ModelsConfig
2024-10-16 11:44:01 +08:00
from typing import Literal
2024-08-26 08:40:10 +08:00
2024-10-16 11:44:01 +08:00
# DatasetType, QuestionType, and OptimizerType definitions
DatasetType = Literal["HumanEval", "MBPP", "GSM8K", "MATH", "HotpotQa", "DROP"]
QuestionType = Literal["math", "code", "quiz"]
OptimizerType = Literal["Graph", "Test"]
2024-08-26 08:40:10 +08:00
2024-09-25 16:46:20 +08:00
# Crucial Parameters
2024-10-16 11:44:01 +08:00
dataset: DatasetType = "GSM8K" # 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 = "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
2024-09-25 16:46:20 +08:00
# Initialize LLM Model
2024-09-26 20:06:57 +08:00
four_o_llm_config = ModelsConfig.default().get("gpt-4o")
deepseek_llm_config = ModelsConfig.default().get("deepseek-chat")
2024-09-25 16:46:20 +08:00
mini_llm_config = ModelsConfig.default().get("gpt-4o-mini")
2024-09-02 16:47:03 +08:00
claude_llm_config = ModelsConfig.default().get("claude-3-5-sonnet-20240620")
2024-09-25 16:46:20 +08:00
# Initialize Operators List
operators = [
2024-10-16 11:44:01 +08:00
"Custom"
2024-08-26 08:40:10 +08:00
]
2024-09-25 16:46:20 +08:00
# Create an optimizer instance
2024-08-26 08:40:10 +08:00
optimizer = Optimizer(
dataset=dataset,
2024-10-16 11:44:01 +08:00
question_type=question_type,
2024-08-26 08:40:10 +08:00
opt_llm_config=claude_llm_config,
2024-10-16 11:44:01 +08:00
exec_llm_config=mini_llm_config,
check_convergence=check_convergence,
2024-09-25 16:46:20 +08:00
operators=operators,
2024-08-26 08:40:10 +08:00
optimized_path=optimized_path,
sample=sample,
2024-10-16 11:44:01 +08:00
initial_round=initial_round,
max_rounds=max_rounds
2024-08-26 08:40:10 +08:00
)
2024-10-16 11:44:01 +08:00
if __name__ == "__main__":
# Run the optimizer
optimizer.optimize("Graph")
# optimizer.optimize("Test")