Skip to content

Commit

Permalink
feat: enables overwriting of cache (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexsJones committed Mar 28, 2023
1 parent ff0b67b commit a270f7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
output string
filters []string
language string
nocache bool
)

// AnalyzeCmd represents the problems command
Expand Down Expand Up @@ -101,7 +102,7 @@ var AnalyzeCmd = &cobra.Command{
for _, analysis := range *analysisResults {

if explain {
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error)
parsedText, err := analyzer.ParseViaAI(ctx, aiClient, analysis.Error, nocache)
if err != nil {
color.Red("Error: %v", err)
continue
Expand Down Expand Up @@ -135,6 +136,7 @@ var AnalyzeCmd = &cobra.Command{

func init() {

AnalyzeCmd.Flags().BoolVarP(&nocache, "no-cache", "n", false, "Do not use cached data")
// array of strings flag
AnalyzeCmd.Flags().StringSliceVarP(&filters, "filter", "f", []string{}, "Filter for these analzyers (e.g. Pod,PersistentVolumeClaim,Service,ReplicaSet)")

Expand Down
8 changes: 5 additions & 3 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/spf13/viper"
)

func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {
func RunAnalysis(ctx context.Context, client *kubernetes.Client,
aiClient ai.IAI, explain bool, analysisResults *[]Analysis) error {

err := AnalyzePod(ctx, client, aiClient, explain, analysisResults)
if err != nil {
Expand All @@ -35,13 +36,14 @@ func RunAnalysis(ctx context.Context, client *kubernetes.Client, aiClient ai.IAI
return nil
}

func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string) (string, error) {
func ParseViaAI(ctx context.Context, aiClient ai.IAI, prompt []string,
nocache bool) (string, error) {
// parse the text with the AI backend
inputKey := strings.Join(prompt, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
// find in viper cache
if viper.IsSet(sEnc) {
if viper.IsSet(sEnc) && !nocache {
// retrieve data from cache
response := viper.GetString(sEnc)
if response == "" {
Expand Down

0 comments on commit a270f7c

Please sign in to comment.