in the given code i am getting codes for test code asynchronously and then joining them…
- User
in the given code i am getting codes for test code asynchronously and then joining them together.
now i want to generate all test codes test at without async and at a single time by passing all scenarios at once. I've modified scenario_code_generator prompt to accept all scenarios at once and generate the code for all of them and give output in the format of {name: code for name, code in zip([scenario['scenario_name'] for scenario in scenarios], generated_scenario_codes)}
def test_code_generator(state): """Test Code Generator will generate the test code based on the provided context and the scenarios.""" logger.info("---START TestCodeGenerator---") language = state["metadata"]["language"] object_definition = state["object_definition"] dependency_descriptions = state["dependency_descriptions"] test_scenarios_json = state["test_scenarios_json"] test_scenarios_str = state["test_scenarios_str"] fmc_code = state["fmc_code"] clarifier_info = state["clarifier_info"] global_variables_and_custom_objects = state["global_variables_and_custom_objects"] file_name = state["metadata"]["file_name"] object_name = state["metadata"]["object_name"] import_statements = state["import_statements"] scenario_codes = state["scenario_codes"]
scenario_to_process = [] for scenario in test_scenarios_json["test_scenarios"]: if scenario_codes[scenario["scenario_name"]] == "": scenario_to_process.append(scenario) generated_scenario_codes = asyncio.run( generate_all_scenario_codes( scenario_to_process, object_definition, dependency_descriptions, clarifier_info, global_variables_and_custom_objects, fmc_code, file_name, object_name, language, ) ) combined_scenario_code = "\n\n".join(generated_scenario_codes.values()) for scenario_name in generated_scenario_codes: scenario_codes[scenario_name] = generated_scenario_codes[scenario_name] results_logger.save_to_file( path="codes/combined_scenario_functions.txt", data=combined_scenario_code ) context = { 'scenario_codes': scenario_codes, "test_scenarios_json": test_scenarios_json, "file_name": file_name, "object_name": object_name, "import_statements":import_statements } llm_response = compile_scenario(context) generated_text = process_code(llm_response, language) results_logger.save_to_file( path="codes/1_test_code_generator.py", data=generated_text ) return {"test_code": generated_text, "scenario_codes":scenario_codes}async def generate_all_scenario_codes( scenarios: List[Dict[str, str]], # Correctly specify the type of scenarios object_definition, dependency_descriptions, clarifier_info, global_variables_and_custom_objects, fmc_code, file_name, object_name, language, ) -> Dict[str, str]: """Generate test code for all scenarios in parallel.""" tasks = [] for scenario in scenarios: scenario_name = scenario['scenario_name'] context = { 'object_definition': object_definition, 'dependency_descriptions': dependency_descriptions, "test_scenario": scenario, "clarifier_info": clarifier_info, 'global_variables_and_custom_objects': global_variables_and_custom_objects, "fmc_code": fmc_code, "file_name": file_name, "object_name": object_name, }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.