Skip to content

Commit

Permalink
handler error, add steps to another
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Nov 27, 2024
1 parent 16b215e commit ebba245
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ var AnalyzeCmd = &cobra.Command{
return fmt.Errorf(red+"Error fetching pod events: %w\n"+reset, err)
}

// debug for empty results
if result == nil {
fmt.Println(yellow + "No results found in DuckDB." + reset)
return nil
}

s.Suffix = " Analyzing events with LLM..."
s.Start()

Expand All @@ -139,6 +145,10 @@ var AnalyzeCmd = &cobra.Command{
if llmProvider == "openai" {
// Use OpenAI's AnalyzeEventsWithGPT function
gptResponse, err = openai.AnalyzeEventsWithGPT(pod, namespace, result)

fmt.Println(
gptResponse,
)
} else if llmProvider == "anthropic" {
// Use Anthropic's AnalyzeEventsWithAnthropic function
gptResponse, err = anthropic.AnalyzeEventsWithAnthropic(pod, namespace, result)
Expand Down Expand Up @@ -299,7 +309,7 @@ func parseAndSelectAnalysis(response string) bool {
var analysis AnalysisResponse
err := json.Unmarshal([]byte(response), &analysis)
if err != nil {
log.Fatalf("Failed to parse LLM response: %v", err)
log.Println("Failed to parse LLM response: %v", err)

Check failure on line 312 in cmd/analyze.go

View workflow job for this annotation

GitHub Actions / Build and Test the Go code

log.Println call has possible Printf formatting directive %v
}

// Display the summary by default
Expand All @@ -308,7 +318,7 @@ func parseAndSelectAnalysis(response string) bool {
// Prompt the user to choose between "Root Cause Analysis" and "Mitigation Steps"
initialPrompt := promptui.Select{
Label: "Select Analysis to View",
Items: []string{"Root Cause Analysis", "Mitigation Steps"},
Items: []string{"Root Cause Analysis", "Mitigation Steps", "Analyze another pod in namespace (yes/no)"},
Size: 3,
}

Expand All @@ -325,7 +335,7 @@ func parseAndSelectAnalysis(response string) bool {
// Now prompt the user to choose between "Mitigation" or "Pods"
secondPrompt := promptui.Select{
Label: "What would you like to do next?",
Items: []string{"Mitigation"},
Items: []string{"Mitigation", "Analyze another pod in namespace (yes/no)"},
Size: 3,
}

Expand All @@ -351,7 +361,15 @@ func parseAndSelectAnalysis(response string) bool {
if strings.ToLower(choice) != "yes" {
return false // Exit the loop if "no"
}

case "Analyze another pod in namespace (yes/no)":
prompt := promptui.Prompt{
Label: "Analyze another namespace/pod (yes/no)",
Default: "no",
}
choice, _ := prompt.Run()
if strings.ToLower(choice) != "yes" {
return false // Exit the loop if "no"
}
}

case "Mitigation Steps":
Expand Down

0 comments on commit ebba245

Please sign in to comment.