diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..27954d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +*.md +*.log +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dbee8e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:latest AS builder + +WORKDIR /app +COPY . . + +# Build static binary +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o discord-gpt-bot main.go + +FROM debian:bookworm-slim + +# ✅ Install CA certs +RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY --from=builder /app/discord-gpt-bot . + +CMD ["./discord-gpt-bot"] + diff --git a/bot/bot.go b/bot/bot.go index 7a8da5d..10a4cff 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -3,8 +3,8 @@ package bot import ( "strings" - "git.ewnix.net/phlux/discord-gpt-bot/bot/memory" - "git.ewnix.net/phlux/discord-gpt-bot/openai" + "discord-gpt-bot/openai" + "github.com/bwmarrin/discordgo" ) @@ -20,7 +20,7 @@ func Start(session *discordgo.Session) { userID := m.Author.ID content := strings.ReplaceAll(m.Content, "<@"+s.State.User.ID+">", "") - history := memory.GetHistory(userID) + history := GetHistory(userID) history = append(history, openai.Message{Role: "user", Content: strings.TrimSpace(content)}) resp, err := openai.Ask(history) @@ -30,7 +30,7 @@ func Start(session *discordgo.Session) { } history = append(history, openai.Message{Role: "assistant", Content: resp}) - memory.SetHistory(userID, history) + SetHistory(userID, history) s.ChannelMessageSend(m.ChannelID, resp) }) diff --git a/bot/memory.go b/bot/memory.go index 53fc2ae..175dbf1 100644 --- a/bot/memory.go +++ b/bot/memory.go @@ -1,7 +1,7 @@ -package memory +package bot import ( - "git.ewnix.net/phlux/discord-gpt-bot/openai" + "discord-gpt-bot/openai" ) var conversations = map[string][]openai.Message{} diff --git a/config/config.go b/config/config.go index 9639e23..92cee4d 100644 --- a/config/config.go +++ b/config/config.go @@ -1,3 +1,4 @@ +// @TODO: We really need to get more options in here such as ignore, message lengths, etc. package config var ( diff --git a/go.mod b/go.mod index dcc078d..897f460 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,14 @@ -module git.ewnix.net/phlux/discord-gpt-bot +module discord-gpt-bot go 1.24.2 require ( - github.com/bwmarrin/discordgo v0.28.1 // indirect + github.com/bwmarrin/discordgo v0.28.1 + github.com/sashabaranov/go-openai v1.38.2 +) + +require ( github.com/gorilla/websocket v1.4.2 // indirect - github.com/sashabaranov/go-openai v1.38.2 // indirect golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect ) diff --git a/main.go b/main.go index 0041d3e..e0df0bc 100755 --- a/main.go +++ b/main.go @@ -6,8 +6,9 @@ import ( "os/signal" "syscall" - "git.ewnix.net/phlux/discord-gpt-bot/bot" - "git.ewnix.net/phlux/discord-gpt-bot/config" + "discord-gpt-bot/bot" + "discord-gpt-bot/config" + "github.com/bwmarrin/discordgo" ) diff --git a/openai/client.go b/openai/client.go index 0c5dce9..91b157f 100644 --- a/openai/client.go +++ b/openai/client.go @@ -3,7 +3,8 @@ package openai import ( "context" - "git.ewnix.net/phlux/g/discord-gpt-bot/config" + "discord-gpt-bot/config" + "github.com/sashabaranov/go-openai" ) @@ -26,8 +27,9 @@ func Ask(messages []Message) (string, error) { resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ - Model: openai.GPT4, - Messages: chatHistory, + Model: "gpt-4.1", + Messages: chatHistory, + MaxTokens: 600, }, ) if err != nil {