Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzz1y committed Aug 11, 2023
1 parent db52a99 commit 162d7a8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions internal/bot/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions internal/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package gpt
import (
"context"
"github.com/sashabaranov/go-openai"
"time"
)

type Gpt struct {
client *openai.Client
ctx context.Context
model string
historyLimit int
gptTimeout int
gptTimeout time.Duration
maxAttempts int
users map[string]*User
}
Expand All @@ -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,
}
Expand All @@ -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
}

Expand Down

0 comments on commit 162d7a8

Please sign in to comment.