From 3d9bee15126e391b1467d483edbdeea2e9d9d9b9 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:17:23 +0100 Subject: [PATCH] cleanup --- Makefile | 4 ++++ commands.go | 2 +- generate.go | 12 ++++++------ main.go | 30 ++++++++++++++++-------------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 52a24b0..9782a9c 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ build: run: ./Nourybot.out +jq: + ./Nourybot.out | jq + + up: docker compose down docker compose build diff --git a/commands.go b/commands.go index 7a93e46..85535bf 100644 --- a/commands.go +++ b/commands.go @@ -22,7 +22,7 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { if msgLen < 2 { reply = "Not enough arguments provided. Usage: ()gpt " } else { - switch app.config.ollamaContext { + switch app.cfg.ollamaContext { case "none": app.generateNoContext(message.Channel, message.Message[6:len(message.Message)]) return diff --git a/generate.go b/generate.go index cae15b8..9df0f17 100644 --- a/generate.go +++ b/generate.go @@ -41,8 +41,8 @@ func (app *application) chatUserContext(target, username, input string) { olm.Content = input app.userMsgStore[username] = append(app.userMsgStore[username], olm) - requestBody.Model = app.config.ollamaModel - requestBody.System = app.config.ollamaSystem + requestBody.Model = app.cfg.ollamaModel + requestBody.System = app.cfg.ollamaSystem requestBody.Messages = app.userMsgStore[username] requestBody.Prompt = input requestBody.Stream = false @@ -89,8 +89,8 @@ func (app *application) chatGeneralContext(target, input string) { olm.Content = input app.msgStore = append(app.msgStore, olm) - requestBody.Model = app.config.ollamaModel - requestBody.System = app.config.ollamaSystem + requestBody.Model = app.cfg.ollamaModel + requestBody.System = app.cfg.ollamaSystem requestBody.Messages = app.msgStore requestBody.Prompt = input requestBody.Stream = false @@ -131,8 +131,8 @@ func (app *application) chatGeneralContext(target, input string) { func (app *application) generateNoContext(target, input string) { var requestBody ollamaRequest - requestBody.Model = app.config.ollamaModel - requestBody.System = app.config.ollamaSystem + requestBody.Model = app.cfg.ollamaModel + requestBody.System = app.cfg.ollamaSystem requestBody.Prompt = input requestBody.Stream = false diff --git a/main.go b/main.go index ae4671e..e020eb2 100644 --- a/main.go +++ b/main.go @@ -20,14 +20,12 @@ type config struct { type application struct { twitchClient *twitch.Client log *zap.SugaredLogger - config config + cfg config userMsgStore map[string][]ollamaMessage msgStore []ollamaMessage } func main() { - var cfg config - logger := zap.NewExample() defer func() { if err := logger.Sync(); err != nil { @@ -43,22 +41,24 @@ func main() { sugar.Fatal("Error loading .env") } - cfg.twitchUsername = os.Getenv("TWITCH_USERNAME") - cfg.twitchOauth = os.Getenv("TWITCH_OAUTH") - cfg.ollamaModel = os.Getenv("OLLAMA_MODEL") - cfg.ollamaContext = os.Getenv("OLLAMA_CONTEXT") - cfg.ollamaSystem = os.Getenv("OLLAMA_SYSTEM") - tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth) + //tc := twitch.NewClient(config.twitchUsername, config.twitchOauth) userMsgStore := make(map[string][]ollamaMessage) app := &application{ - twitchClient: tc, log: sugar, - config: cfg, userMsgStore: userMsgStore, } + app.cfg.twitchUsername = os.Getenv("TWITCH_USERNAME") + app.cfg.twitchOauth = os.Getenv("TWITCH_OAUTH") + app.cfg.ollamaModel = os.Getenv("OLLAMA_MODEL") + app.cfg.ollamaContext = os.Getenv("OLLAMA_CONTEXT") + app.cfg.ollamaSystem = os.Getenv("OLLAMA_SYSTEM") + + tc := twitch.NewClient(app.cfg.twitchUsername, app.cfg.twitchOauth) + app.twitchClient = tc + // Received a PrivateMessage (normal chat message). app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) { // roomId is the Twitch UserID of the channel the message originated from. @@ -81,9 +81,11 @@ func main() { app.twitchClient.OnConnect(func() { app.log.Info("Successfully connected to Twitch Servers") - app.log.Info("Ollama Context: ", app.config.ollamaContext) - app.log.Info("Ollama System: ", app.config.ollamaSystem) - + app.log.Infow("Ollama", + "Context: ", app.cfg.ollamaContext, + "Model: ", app.cfg.ollamaModel, + "System: ", app.cfg.ollamaSystem, + ) }) channels := os.Getenv("TWITCH_CHANNELS")