@@ -6,15 +6,15 @@ use async_openai::Client;
66/// This example shows how the parallel algorithm processes multiple files concurrently
77#[ tokio:: main]
88async fn main ( ) -> Result < ( ) > {
9- // Initialize logging to see the parallel processing in action
10- env_logger:: init ( ) ;
9+ // Initialize logging to see the parallel processing in action
10+ env_logger:: init ( ) ;
1111
12- println ! ( "Parallel Commit Message Generation Demo" ) ;
13- println ! ( "======================================" ) ;
14- println ! ( ) ;
12+ println ! ( "Parallel Commit Message Generation Demo" ) ;
13+ println ! ( "======================================" ) ;
14+ println ! ( ) ;
1515
16- // Example multi-file diff to demonstrate parallel processing
17- let multi_file_diff = r#"diff --git a/src/auth.rs b/src/auth.rs
16+ // Example multi-file diff to demonstrate parallel processing
17+ let multi_file_diff = r#"diff --git a/src/auth.rs b/src/auth.rs
1818index 1234567..abcdefg 100644
1919--- a/src/auth.rs
2020+++ b/src/auth.rs
@@ -70,53 +70,53 @@ index 9876543..1111111 100644
7070+sqlx = "0.7"
7171"# ;
7272
73- println ! ( "1. Parsing diff to identify files for parallel processing..." ) ;
74- let parsed_files = parse_diff ( multi_file_diff) ?;
75- println ! ( " Found {} files to analyze:" , parsed_files. len( ) ) ;
76- for ( i, file) in parsed_files. iter ( ) . enumerate ( ) {
77- println ! ( " {}. {} ({})" , i + 1 , file. path, file. operation) ;
78- }
79- println ! ( ) ;
73+ println ! ( "1. Parsing diff to identify files for parallel processing..." ) ;
74+ let parsed_files = parse_diff ( multi_file_diff) ?;
75+ println ! ( " Found {} files to analyze:" , parsed_files. len( ) ) ;
76+ for ( i, file) in parsed_files. iter ( ) . enumerate ( ) {
77+ println ! ( " {}. {} ({})" , i + 1 , file. path, file. operation) ;
78+ }
79+ println ! ( ) ;
80+
81+ println ! ( "2. Demonstrating the parallel analysis approach:" ) ;
82+ println ! ( " - Each file will be analyzed concurrently (not sequentially)" ) ;
83+ println ! ( " - Uses simple text completion (not complex function calling)" ) ;
84+ println ! ( " - Single synthesis step replaces 3 sequential API calls" ) ;
85+ println ! ( ) ;
86+
87+ // Note: This would require a valid OpenAI API key to actually run
88+ // For the demo, we just show the structure
89+ if std:: env:: var ( "OPENAI_API_KEY" ) . is_ok ( ) {
90+ println ! ( "3. Running parallel analysis (requires OpenAI API key)..." ) ;
8091
81- println ! ( "2. Demonstrating the parallel analysis approach:" ) ;
82- println ! ( " - Each file will be analyzed concurrently (not sequentially)" ) ;
83- println ! ( " - Uses simple text completion (not complex function calling)" ) ;
84- println ! ( " - Single synthesis step replaces 3 sequential API calls" ) ;
85- println ! ( ) ;
92+ let client = Client :: new ( ) ;
93+ let model = "gpt-4o-mini" ;
8694
87- // Note: This would require a valid OpenAI API key to actually run
88- // For the demo, we just show the structure
89- if std:: env:: var ( "OPENAI_API_KEY" ) . is_ok ( ) {
90- println ! ( "3. Running parallel analysis (requires OpenAI API key)..." ) ;
91-
92- let client = Client :: new ( ) ;
93- let model = "gpt-4o-mini" ;
94-
95- match generate_commit_message_parallel ( & client, model, multi_file_diff, Some ( 72 ) ) . await {
96- Ok ( message) => {
97- println ! ( " ✓ Generated commit message: '{}'" , message) ;
98- println ! ( " ✓ Message length: {} characters" , message. len( ) ) ;
99- }
100- Err ( e) => {
101- println ! ( " ⚠ API call failed (expected without valid key): {}" , e) ;
102- }
103- }
104- } else {
105- println ! ( "3. Skipping API call (no OPENAI_API_KEY found)" ) ;
106- println ! ( " Set OPENAI_API_KEY environment variable to test with real API" ) ;
95+ match generate_commit_message_parallel ( & client, model, multi_file_diff, Some ( 72 ) ) . await {
96+ Ok ( message) => {
97+ println ! ( " ✓ Generated commit message: '{}'" , message) ;
98+ println ! ( " ✓ Message length: {} characters" , message. len( ) ) ;
99+ }
100+ Err ( e) => {
101+ println ! ( " ⚠ API call failed (expected without valid key): {}" , e) ;
102+ }
107103 }
108-
109- println ! ( ) ;
110- println ! ( "Performance Benefits:" ) ;
111- println ! ( "• Single file: ~6.6s → ~4s (eliminate 2 sequential round-trips)" ) ;
112- println ! ( "• Multiple files: Linear scaling vs sequential (5 files: ~4.3s vs ~16s)" ) ;
113- println ! ( "• Better error resilience: Continue if some files fail to analyze" ) ;
114- println ! ( ) ;
115-
116- println ! ( "Architecture Improvements:" ) ;
117- println ! ( "• Two-phase design: Parallel analysis → Unified synthesis" ) ;
118- println ! ( "• Simplified API: Plain text responses vs function calling schemas" ) ;
119- println ! ( "• Graceful fallback: Falls back to original multi-step if parallel fails" ) ;
104+ } else {
105+ println ! ( "3. Skipping API call (no OPENAI_API_KEY found)" ) ;
106+ println ! ( " Set OPENAI_API_KEY environment variable to test with real API" ) ;
107+ }
108+
109+ println ! ( ) ;
110+ println ! ( "Performance Benefits:" ) ;
111+ println ! ( "• Single file: ~6.6s → ~4s (eliminate 2 sequential round-trips)" ) ;
112+ println ! ( "• Multiple files: Linear scaling vs sequential (5 files: ~4.3s vs ~16s)" ) ;
113+ println ! ( "• Better error resilience: Continue if some files fail to analyze" ) ;
114+ println ! ( ) ;
115+
116+ println ! ( "Architecture Improvements:" ) ;
117+ println ! ( "• Two-phase design: Parallel analysis → Unified synthesis" ) ;
118+ println ! ( "• Simplified API: Plain text responses vs function calling schemas" ) ;
119+ println ! ( "• Graceful fallback: Falls back to original multi-step if parallel fails" ) ;
120120
121- Ok ( ( ) )
122- }
121+ Ok ( ( ) )
122+ }
0 commit comments