You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Check if it's an API key error - if so, propagate immediately
637
+
let error_str = e.to_string();
638
+
if error_str.contains("invalid_api_key") || error_str.contains("Incorrect API key") || error_str.contains("Invalid API key"){
639
+
returnErr(e);
640
+
}
641
+
log::warn!("Failed to analyze file {}: {}", parsed_files[i].path, e);
642
+
// Continue with other files
643
+
}
644
+
}
645
+
}
646
+
647
+
if successful_analyses.is_empty(){
648
+
anyhow::bail!("Failed to analyze any files in parallel");
649
+
}
650
+
651
+
// Phase 2: Synthesize final commit message from all analyses
652
+
log::debug!("Synthesizing final commit message from {} analyses", successful_analyses.len());
653
+
654
+
let synthesis_result = synthesize_commit_message(
655
+
client,
656
+
model,
657
+
&successful_analyses,
658
+
max_length.unwrap_or(72),
659
+
).await?;
660
+
661
+
Ok(synthesis_result)
662
+
}
663
+
664
+
/// Analyzes a single file using simplified text completion (no function calling)
665
+
asyncfnanalyze_single_file_simple(
666
+
client:&Client<OpenAIConfig>,
667
+
model:&str,
668
+
file_path:&str,
669
+
operation:&str,
670
+
diff_content:&str,
671
+
) -> Result<String>{
672
+
let system_prompt = "You are a git diff analyzer. Analyze the provided file change and provide a concise summary in 1-2 sentences describing what changed and why it matters.";
673
+
674
+
let user_prompt = format!(
675
+
"File: {}\nOperation: {}\nDiff:\n{}\n\nProvide a concise summary (1-2 sentences) of what changed and why it matters:",
676
+
file_path, operation, diff_content
677
+
);
678
+
679
+
let request = CreateChatCompletionRequestArgs::default()
680
+
.model(model)
681
+
.messages(vec![
682
+
ChatCompletionRequestSystemMessageArgs::default()
683
+
.content(system_prompt)
684
+
.build()?
685
+
.into(),
686
+
ChatCompletionRequestUserMessageArgs::default()
687
+
.content(user_prompt)
688
+
.build()?
689
+
.into(),
690
+
])
691
+
.max_tokens(150u32)// Keep responses concise
692
+
.build()?;
693
+
694
+
let response = client.chat().create(request).await?;
695
+
696
+
let content = response.choices[0]
697
+
.message
698
+
.content
699
+
.as_ref()
700
+
.ok_or_else(|| anyhow::anyhow!("No content in response"))?;
701
+
702
+
Ok(content.trim().to_string())
703
+
}
704
+
705
+
/// Synthesizes a final commit message from multiple file analyses
"You are a git commit message expert. Based on the file change summaries provided, generate a concise, descriptive commit message that captures the essential nature of the changes. The message should be {} characters or less and follow conventional commit format when appropriate. Focus on WHAT changed and WHY, not just listing files.",
721
+
max_length
722
+
);
723
+
724
+
let user_prompt = format!(
725
+
"{}\n\nGenerate a commit message (max {} characters) that captures the essential nature of these changes:",
726
+
context, max_length
727
+
);
728
+
729
+
let request = CreateChatCompletionRequestArgs::default()
730
+
.model(model)
731
+
.messages(vec![
732
+
ChatCompletionRequestSystemMessageArgs::default()
733
+
.content(system_prompt)
734
+
.build()?
735
+
.into(),
736
+
ChatCompletionRequestUserMessageArgs::default()
737
+
.content(user_prompt)
738
+
.build()?
739
+
.into(),
740
+
])
741
+
.max_tokens(100u32)// Commit messages should be short
742
+
.build()?;
743
+
744
+
let response = client.chat().create(request).await?;
745
+
746
+
let content = response.choices[0]
747
+
.message
748
+
.content
749
+
.as_ref()
750
+
.ok_or_else(|| anyhow::anyhow!("No content in response"))?;
0 commit comments