Merge pull request #296 from matthisholleville/fix/language-toggle-bug

fix: resolve language toggle bug (issue #294)
This commit is contained in:
Aris Boutselis 2023-04-18 10:17:10 +01:00 committed by GitHub
commit a962d13654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -4,10 +4,11 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/util" "github.com/k8sgpt-ai/k8sgpt/pkg/util"
"github.com/spf13/viper" "github.com/spf13/viper"
"strings"
) )
type NoOpAIClient struct { type NoOpAIClient struct {
@ -34,7 +35,7 @@ func (a *NoOpAIClient) Parse(ctx context.Context, prompt []string, nocache bool)
inputKey := strings.Join(prompt, " ") inputKey := strings.Join(prompt, " ")
// Check for cached data // Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey)) 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) response, err := a.GetCompletion(ctx, inputKey)
if err != nil { if err != nil {

View File

@ -5,9 +5,10 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
"strings" "strings"
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -59,7 +60,7 @@ func (a *OpenAIClient) Parse(ctx context.Context, prompt []string, nocache bool)
inputKey := strings.Join(prompt, " ") inputKey := strings.Join(prompt, " ")
// Check for cached data // Check for cached data
sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey)) sEnc := base64.StdEncoding.EncodeToString([]byte(inputKey))
cacheKey := util.GetCacheKey(a.GetName(), sEnc) cacheKey := util.GetCacheKey(a.GetName(), a.language, sEnc)
// find in viper cache // find in viper cache
if viper.IsSet(cacheKey) && !nocache { if viper.IsSet(cacheKey) && !nocache {
// retrieve data from cache // retrieve data from cache

View File

@ -134,8 +134,8 @@ func ReplaceIfMatch(text string, pattern string, replacement string) string {
return text return text
} }
func GetCacheKey(provider string, sEnc string) string { func GetCacheKey(provider string, language string, sEnc string) string {
return fmt.Sprintf("%s-%s", provider, sEnc) return fmt.Sprintf("%s-%s-%s", provider, language, sEnc)
} }
func GetPodListByLabels(client k.Interface, func GetPodListByLabels(client k.Interface,