Skip to content

Commit

Permalink
fix: resolve language toggle bug (issue #294)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthis <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed Apr 18, 2023
1 parent 3d684a2 commit 0313627
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/ai/noopai.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"encoding/base64"
"fmt"
"strings"

"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
"github.com/spf13/viper"
"strings"
)

type NoOpAIClient struct {
Expand All @@ -34,7 +35,7 @@ func (a *NoOpAIClient) Parse(ctx context.Context, prompt []string, nocache bool)
inputKey := strings.Join(prompt, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
cacheKey := util.GetCacheKey(a.GetName(), sEnc)
cacheKey := util.GetCacheKey(a.GetName(), a.language, sEnc)

response, err := a.GetCompletion(ctx, inputKey)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
"strings"

"github.com/k8sgpt-ai/k8sgpt/pkg/util"

"github.com/fatih/color"
"github.com/spf13/viper"

Expand Down Expand Up @@ -59,7 +60,7 @@ func (a *OpenAIClient) Parse(ctx context.Context, prompt []string, nocache bool)
inputKey := strings.Join(prompt, " ")
// Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
cacheKey := util.GetCacheKey(a.GetName(), sEnc)
cacheKey := util.GetCacheKey(a.GetName(), a.language, sEnc)
// find in viper cache
if viper.IsSet(cacheKey) && !nocache {
// retrieve data from cache
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func ReplaceIfMatch(text string, pattern string, replacement string) string {
return text
}

func GetCacheKey(provider string, sEnc string) string {
return fmt.Sprintf("%s-%s", provider, sEnc)
func GetCacheKey(provider string, language string, sEnc string) string {
return fmt.Sprintf("%s-%s-%s", provider, language, sEnc)
}

func GetPodListByLabels(client k.Interface,
Expand Down

0 comments on commit 0313627

Please sign in to comment.