Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/ai/iai.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func NewClient(provider string) IAI {
}

type AIConfiguration struct {
Providers []AIProvider `mapstructure:"providers"`
DefaultProvider string `mapstructure:"defaultprovider"`
Providers []AIProvider `mapstructure:"providers"`
DefaultProvider string `mapstructure:"defaultprovider"`
PromptMap map[string]string `mapstructure:"promptmap"`
}

type AIProvider struct {
Expand Down
16 changes: 14 additions & 2 deletions pkg/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Client *kubernetes.Client
Language string
AIClient ai.IAI
PromptMap map[string]string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this bit do? We pass the prompt map into result, err := a.getAIResultForSanitizedFailures(texts, promptTemplate)

Results []common.Result
Errors []string
Namespace string
Expand Down Expand Up @@ -209,11 +210,22 @@
if err := aiClient.Configure(&aiProvider); err != nil {
return nil, err
}
// Initialize prompt map with default prompts
promptMap := make(map[string]string)
for promptType, promptTemplate := range ai.PromptMap {
promptMap[promptType] = promptTemplate
}
for promptType, customPrompt := range configAI.PromptMap {
if promptType != "raw" {
promptMap[promptType] = customPrompt
}

Check warning on line 221 in pkg/analysis/analysis.go

View check run for this annotation

Codecov / codecov/patch

pkg/analysis/analysis.go#L219-L221

Added lines #L219 - L221 were not covered by tests
}
if verbose {
fmt.Println("Debug: AI client initialized.")
}
a.AIClient = aiClient
a.AnalysisAIProvider = aiProvider.Name
a.PromptMap = promptMap
return a, nil
}

Expand Down Expand Up @@ -464,10 +476,10 @@
texts = append(texts, failure.Text)
}

promptTemplate := ai.PromptMap["default"]
promptTemplate := a.PromptMap["default"]
// If the resource `Kind` comes from an "integration plugin",
// maybe a customized prompt template will be involved.
if prompt, ok := ai.PromptMap[analysis.Kind]; ok {
if prompt, ok := a.PromptMap[analysis.Kind]; ok {
promptTemplate = prompt
}
result, err := a.getAIResultForSanitizedFailures(texts, promptTemplate)
Expand Down
Loading