Skip to content

Commit

Permalink
feat: addition of simple language support
Browse files Browse the repository at this point in the history
Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
  • Loading branch information
AlexsJones committed Mar 27, 2023
1 parent 9c5523f commit c3008c5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
14 changes: 8 additions & 6 deletions cmd/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
)

var (
explain bool
backend string
output string
filters []string
explain bool
backend string
output string
filters []string
language string
)

// AnalyzeCmd represents the problems command
Expand Down Expand Up @@ -53,7 +54,7 @@ var AnalyzeCmd = &cobra.Command{
switch backendType {
case "openai":
aiClient = &ai.OpenAIClient{}
if err := aiClient.Configure(token); err != nil {
if err := aiClient.Configure(token, language); err != nil {
color.Red("Error: %v", err)
os.Exit(1)
}
Expand Down Expand Up @@ -141,5 +142,6 @@ func init() {
AnalyzeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
// output as json
AnalyzeCmd.Flags().StringVarP(&output, "output", "o", "text", "Output format (text, json)")

// add language options for output
AnalyzeCmd.Flags().StringVarP(&language, "language", "l", "english", "Languages to use for AI (e.g. 'English', 'Spanish', 'French', 'German', 'Italian', 'Portuguese', 'Dutch', 'Russian', 'Chinese', 'Japanese', 'Korean')")
}
40 changes: 40 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("version called")
},
}

func init() {
rootCmd.AddCommand(versionCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
16 changes: 13 additions & 3 deletions pkg/ai/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ package ai
import (
"context"
"errors"
"fmt"

"github.com/sashabaranov/go-openai"
)

const (
default_prompt = "Simplify the following Kubernetes error message and provide a solution in %s: %s"
prompt_a = "Read the following input %s and provide possible scenarios for remediation in %s"
prompt_b = "Considering the following input from the Kubernetes resource %s and the error message %s, provide possible scenarios for remediation in %s"
prompt_c = "Reading the following %s error message and it's accompanying log message %s, how would you simplify this message?"
)

type OpenAIClient struct {
client *openai.Client
client *openai.Client
language string
}

func (c *OpenAIClient) Configure(token string) error {
func (c *OpenAIClient) Configure(token string, language string) error {
client := openai.NewClient(token)
if client == nil {
return errors.New("error creating OpenAI client")
}
c.language = language
c.client = client
return nil
}
Expand All @@ -27,7 +37,7 @@ func (c *OpenAIClient) GetCompletion(ctx context.Context, prompt string) (string
Messages: []openai.ChatCompletionMessage{
{
Role: "user",
Content: "Simplify the following Kubernetes error message and provide a solution: " + prompt,
Content: fmt.Sprintf(default_prompt, c.language, prompt),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/ai/iai.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package ai
import "context"

type IAI interface {
Configure(token string) error
Configure(token string, language string) error
GetCompletion(ctx context.Context, prompt string) (string, error)
}

0 comments on commit c3008c5

Please sign in to comment.