@@ -1276,6 +1276,19 @@ async def _multi_turn_orchestrator(
12761276 else :
12771277 self .logger .debug ("No converters specified" )
12781278
1279+ # Initialize output path for memory labelling
1280+ base_path = str (uuid .uuid4 ())
1281+
1282+ # If scan output directory exists, place the file there
1283+ if hasattr (self , "scan_output_dir" ) and self .scan_output_dir :
1284+ # Ensure the directory exists
1285+ os .makedirs (self .scan_output_dir , exist_ok = True )
1286+ output_path = os .path .join (self .scan_output_dir , f"{ base_path } { DATA_EXT } " )
1287+ else :
1288+ output_path = f"{ base_path } { DATA_EXT } "
1289+
1290+ self .red_team_info [strategy_name ][risk_category_name ]["data_file" ] = output_path
1291+
12791292 for prompt_idx , prompt in enumerate (all_prompts ):
12801293 prompt_start_time = datetime .now ()
12811294 self .logger .debug (f"Processing prompt { prompt_idx + 1 } /{ len (all_prompts )} " )
@@ -1314,17 +1327,6 @@ async def _multi_turn_orchestrator(
13141327 # Debug log the first few characters of the current prompt
13151328 self .logger .debug (f"Current prompt (truncated): { prompt [:50 ]} ..." )
13161329
1317- # Initialize output path for memory labelling
1318- base_path = str (uuid .uuid4 ())
1319-
1320- # If scan output directory exists, place the file there
1321- if hasattr (self , "scan_output_dir" ) and self .scan_output_dir :
1322- output_path = os .path .join (self .scan_output_dir , f"{ base_path } { DATA_EXT } " )
1323- else :
1324- output_path = f"{ base_path } { DATA_EXT } "
1325-
1326- self .red_team_info [strategy_name ][risk_category_name ]["data_file" ] = output_path
1327-
13281330 try : # Create retry decorator for this specific call with enhanced retry strategy
13291331
13301332 @retry (** self ._create_retry_config ()["network_retry" ])
@@ -1361,6 +1363,12 @@ async def send_prompt_with_retry():
13611363 self .logger .debug (
13621364 f"Successfully processed prompt { prompt_idx + 1 } for { strategy_name } /{ risk_category_name } in { prompt_duration :.2f} seconds"
13631365 )
1366+ self ._write_pyrit_outputs_to_file (
1367+ orchestrator = orchestrator ,
1368+ strategy_name = strategy_name ,
1369+ risk_category = risk_category_name ,
1370+ batch_idx = prompt_idx + 1 ,
1371+ )
13641372
13651373 # Print progress to console
13661374 if prompt_idx < len (all_prompts ) - 1 : # Don't print for the last prompt
@@ -1385,7 +1393,7 @@ async def send_prompt_with_retry():
13851393 orchestrator = orchestrator ,
13861394 strategy_name = strategy_name ,
13871395 risk_category = risk_category_name ,
1388- batch_idx = 1 ,
1396+ batch_idx = prompt_idx + 1 ,
13891397 )
13901398 # Continue with partial results rather than failing completely
13911399 continue
@@ -1404,7 +1412,7 @@ async def send_prompt_with_retry():
14041412 orchestrator = orchestrator ,
14051413 strategy_name = strategy_name ,
14061414 risk_category = risk_category_name ,
1407- batch_idx = 1 ,
1415+ batch_idx = prompt_idx + 1 ,
14081416 )
14091417 # Continue with other batches even if one fails
14101418 continue
0 commit comments