diff --git a/internal/bot/actions.go b/internal/bot/actions.go index 96c417e..69d0c79 100644 --- a/internal/bot/actions.go +++ b/internal/bot/actions.go @@ -12,7 +12,6 @@ import ( "maunium.net/go/mautrix/format" "maunium.net/go/mautrix/id" "net/http" - "time" ) // completionResponse responds to a user message with a GPT-based completion. @@ -102,8 +101,7 @@ func (b *Bot) markRead(evt *event.Event) { // startTyping notifies the room that the bot is typing. func (b *Bot) startTyping(roomID id.RoomID) { - timeout := time.Duration(b.gptClient.GetTimeout()) * time.Second - _, _ = b.client.UserTyping(roomID, true, timeout) + _, _ = b.client.UserTyping(roomID, true, b.gptClient.GetTimeout()) } // stopTyping notifies the room that the bot has stopped typing. diff --git a/internal/bot/bot.go b/internal/bot/bot.go index 9430cbb..2cf5a4b 100644 --- a/internal/bot/bot.go +++ b/internal/bot/bot.go @@ -47,7 +47,7 @@ func NewBot(serverUrl, userID, password, sqlitePath string, historyExpire int, g log.Info(). Str("matrix-username", profile.DisplayName). Str("gpt-model", gpt.GetModel()). - Int("gpt-timeout", gpt.GetTimeout()). + Dur("gpt-timeout", gpt.GetTimeout()). Int("history-limit", gpt.GetHistoryLimit()). Int("history-expire", historyExpire). Msg("connected to matrix") diff --git a/internal/bot/handlers.go b/internal/bot/handlers.go index 153ccf1..d4e7401 100644 --- a/internal/bot/handlers.go +++ b/internal/bot/handlers.go @@ -38,7 +38,7 @@ func (b *Bot) messageHandler(source mautrix.EventSource, evt *event.Event) { l := log.With(). Str("component", "handler"). - Str("user_id", evt.Sender.String()). + Str("user-id", evt.Sender.String()). Logger() user, ok := b.gptClient.GetUser(evt.Sender.String()) diff --git a/internal/gpt/gpt.go b/internal/gpt/gpt.go index db6a71a..93e900a 100644 --- a/internal/gpt/gpt.go +++ b/internal/gpt/gpt.go @@ -3,6 +3,7 @@ package gpt import ( "context" "github.com/sashabaranov/go-openai" + "time" ) type Gpt struct { @@ -10,7 +11,7 @@ type Gpt struct { ctx context.Context model string historyLimit int - gptTimeout int + gptTimeout time.Duration maxAttempts int users map[string]*User } @@ -27,7 +28,7 @@ func New(token, gptModel string, historyLimit, gptTimeout, maxAttempts int, user ctx: context.Background(), model: gptModel, historyLimit: historyLimit, - gptTimeout: gptTimeout, + gptTimeout: time.Duration(gptTimeout) * time.Second, users: users, maxAttempts: maxAttempts, } @@ -45,7 +46,7 @@ func (g *Gpt) GetModel() string { } // GetTimeout returns the timeout value for the GPT client. -func (g *Gpt) GetTimeout() int { +func (g *Gpt) GetTimeout() time.Duration { return g.gptTimeout }