From 200ec57f2997ec6f329fb457925a3a8a41fed615 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sat, 4 Nov 2023 22:56:22 +0000 Subject: [PATCH] Run gofmt/goimports on go sources --- pkg/cli/cmd.go | 13 +++++++------ pkg/cli/config.go | 1 - pkg/cli/openai.go | 13 +++++++------ pkg/cli/store.go | 26 +++++++++++++------------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/pkg/cli/cmd.go b/pkg/cli/cmd.go index e1c1044..7a61a56 100644 --- a/pkg/cli/cmd.go +++ b/pkg/cli/cmd.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strings" + "github.com/spf13/cobra" ) @@ -66,7 +67,7 @@ var replyCmd = &cobra.Command{ var newCmd = &cobra.Command{ Use: "new", Short: "Start a new conversation", - Long: `Start a new conversation with the Large Language Model.`, + Long: `Start a new conversation with the Large Language Model.`, Run: func(cmd *cobra.Command, args []string) { messageContents, err := InputFromEditor("# What would you like to say?\n", "message.*.md") if err != nil { @@ -83,8 +84,8 @@ var newCmd = &cobra.Command{ messages := []Message{ { + Role: "user", OriginalContent: messageContents, - Role: "user", }, } @@ -99,9 +100,9 @@ var newCmd = &cobra.Command{ } var promptCmd = &cobra.Command{ - Use: "prompt", + Use: "prompt", Short: "Do a one-shot prompt", - Long: `Prompt the Large Language Model and get a response.`, + Long: `Prompt the Large Language Model and get a response.`, Run: func(cmd *cobra.Command, args []string) { message := strings.Join(args, " ") if len(strings.Trim(message, " \t\n")) == 0 { @@ -111,8 +112,8 @@ var promptCmd = &cobra.Command{ messages := []Message{ { + Role: "user", OriginalContent: message, - Role: "user", }, } @@ -128,5 +129,5 @@ var promptCmd = &cobra.Command{ func NewRootCmd() *cobra.Command { rootCmd.AddCommand(newCmd, promptCmd) - return rootCmd; + return rootCmd } diff --git a/pkg/cli/config.go b/pkg/cli/config.go index fb9e5b8..367242c 100644 --- a/pkg/cli/config.go +++ b/pkg/cli/config.go @@ -37,7 +37,6 @@ func InitializeConfig() *Config { defaultConfig := &Config{} defaultConfig.OpenAI.APIKey = "your_key_here" - file, err := os.Create(configFile) if err != nil { Fatal("Could not open config file for writing: %v", err) diff --git a/pkg/cli/openai.go b/pkg/cli/openai.go index 7853b23..c54e479 100644 --- a/pkg/cli/openai.go +++ b/pkg/cli/openai.go @@ -5,20 +5,21 @@ import ( "errors" "fmt" "io" + openai "github.com/sashabaranov/go-openai" ) -func CreateChatCompletionRequest(system string, messages []Message) (*openai.ChatCompletionRequest) { +func CreateChatCompletionRequest(system string, messages []Message) *openai.ChatCompletionRequest { chatCompletionMessages := []openai.ChatCompletionMessage{ { - Role: "system", + Role: "system", Content: system, }, } - for _, m := range(messages) { + for _, m := range messages { chatCompletionMessages = append(chatCompletionMessages, openai.ChatCompletionMessage{ - Role: m.Role, + Role: m.Role, Content: m.OriginalContent, }) } @@ -26,8 +27,8 @@ func CreateChatCompletionRequest(system string, messages []Message) (*openai.Cha return &openai.ChatCompletionRequest{ Model: openai.GPT4, MaxTokens: 256, - Messages: chatCompletionMessages, - Stream: true, + Messages: chatCompletionMessages, + Stream: true, } } diff --git a/pkg/cli/store.go b/pkg/cli/store.go index 038c2e6..9776fd9 100644 --- a/pkg/cli/store.go +++ b/pkg/cli/store.go @@ -4,33 +4,33 @@ import ( "database/sql" "os" "path/filepath" - "gorm.io/gorm" - "gorm.io/driver/sqlite" + sqids "github.com/sqids/sqids-go" + "gorm.io/driver/sqlite" + "gorm.io/gorm" ) type Store struct { - db *gorm.DB + db *gorm.DB sqids *sqids.Sqids } type Message struct { - ID uint `gorm:"primaryKey"` - ConversationID uint `gorm:"foreignKey:ConversationID"` - Conversation Conversation + ID uint `gorm:"primaryKey"` + ConversationID uint `gorm:"foreignKey:ConversationID"` + Conversation Conversation OriginalContent string - Role string // 'user' or 'assistant' + Role string // 'user' or 'assistant' } type Conversation struct { - ID uint `gorm:"primaryKey"` + ID uint `gorm:"primaryKey"` ShortName sql.NullString - Title string + Title string } - func getDataDir() string { - var dataDir string; + var dataDir string xdgDataHome := os.Getenv("XDG_DATA_HOME") if xdgDataHome != "" { @@ -57,7 +57,7 @@ func InitializeStore() *Store { &Message{}, } - for _, x := range(models) { + for _, x := range models { err := db.AutoMigrate(x) if err != nil { Fatal("Could not perform database migrations: %v\n", err) @@ -76,7 +76,7 @@ func (s *Store) SaveConversation(conversation *Conversation) error { } if !conversation.ShortName.Valid { - shortName, _ := s.sqids.Encode([]uint64{ uint64(conversation.ID) }) + shortName, _ := s.sqids.Encode([]uint64{uint64(conversation.ID)}) conversation.ShortName = sql.NullString{String: shortName, Valid: true} err = s.db.Save(&conversation).Error }