import evoagentx.workflow.operators as operator import examples.aflow.mbpp_new_full.optimized.round_5.prompt as prompt_custom from evoagentx.models.model_configs import LLMConfig from evoagentx.benchmark.benchmark import Benchmark from evoagentx.models.model_utils import create_llm_instance class Workflow: def __init__( self, name: str, llm_config: LLMConfig, benchmark: Benchmark ): self.name = name self.llm = create_llm_instance(llm_config) self.benchmark = benchmark self.custom = operator.Custom(self.llm) self.custom_code_generate = operator.CustomCodeGenerate(self.llm) self.test = operator.Test(self.llm) # Added test operator to enhance solution checks self.sc_ensemble = operator.ScEnsemble(self.llm) # Added ensemble operator for better selection async def __call__(self, problem: str, entry_point: str): """ Implementation of the workflow Custom operator to generate anything you want. But when you want to get standard code, you should use custom_code_generate operator. """ solution = await self.custom_code_generate(problem=problem, entry_point=entry_point, instruction=prompt_custom.GENERATE_PYTHON_CODE_PROMPT) test_result = await self.test(problem=problem, solution=solution['response'], entry_point=entry_point, benchmark=self.benchmark) # Implementing test functionality attempts = 0 # Added an attempt counter to manage retries while not test_result['result'] and attempts < 2: # Allow up to 2 attempts attempts += 1 # Gather multiple attempts for the same problem to apply the ensemble method alternate_solutions = await self.custom(input=problem, instruction=prompt_custom.ALTERNATE_SOLUTIONS_PROMPT) selected_solution = await self.sc_ensemble(solutions=alternate_solutions['response'], problem=problem) # Enhancing solution selection revision_response = await self.custom(input=problem+f" Current Solution: {selected_solution['response']}", instruction=prompt_custom.REVISE_PROMPT) test_result = await self.test(problem=problem, solution=revision_response['response'], entry_point=entry_point, benchmark=self.benchmark) # Retest with revised solution return revision_response['response'] if not test_result['result'] else solution['response']