Skip to content

Commit

Permalink
bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
xnth97 committed Mar 8, 2024
1 parent 8ebe574 commit f2303b4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 44 deletions.
20 changes: 9 additions & 11 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
mapset "github.com/deckarep/golang-set/v2"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
Expand Down Expand Up @@ -37,11 +38,7 @@ type Config struct {
}

func NewBot(c Config) *Bot {
keyCredential, err := azopenai.NewKeyCredential(c.ApiKey)
if err != nil {
panic(err)
}

keyCredential := azcore.NewKeyCredential(c.ApiKey)
client, err := azopenai.NewClientWithKeyCredential(c.BaseUrl, keyCredential, nil)
if err != nil {
panic(err)
Expand Down Expand Up @@ -138,10 +135,10 @@ func (b *Bot) Respond(chatId int64, query string) error {
conv := b.conversationManager.AddUserMessage(chatId, query)

req := azopenai.ChatCompletionsOptions{
MaxTokens: &b.config.MaxTokens,
Messages: conv.Messages,
Temperature: &b.config.Temperature,
DeploymentID: b.config.DeploymentId,
MaxTokens: &b.config.MaxTokens,
Messages: conv.Messages,
Temperature: &b.config.Temperature,
DeploymentName: &b.config.DeploymentId,
}

resp, err := b.client.GetChatCompletionsStream(b.ctx, req, nil)
Expand Down Expand Up @@ -207,12 +204,13 @@ func (b *Bot) Respond(chatId int64, query string) error {
func (b *Bot) DrawImage(chatId int64, prompt string) {
req := azopenai.ImageGenerationOptions{
Prompt: &prompt,
Size: to.Ptr(azopenai.ImageSize256x256),
Size: to.Ptr(azopenai.ImageSizeSize1024X1024),
ResponseFormat: to.Ptr(azopenai.ImageGenerationResponseFormatURL),
N: to.Ptr(int32(1)),
DeploymentName: to.Ptr("dall-e-3"),
}

resp, err := b.client.CreateImage(b.ctx, req, nil)
resp, err := b.client.GetImageGenerations(b.ctx, req, nil)
if err != nil {
b.processError(chatId, err)
}
Expand Down
23 changes: 11 additions & 12 deletions conversation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Conversation struct {
Messages []azopenai.ChatMessage
Messages []azopenai.ChatRequestMessageClassification
SystemMessage string
}

Expand Down Expand Up @@ -58,9 +58,8 @@ func (c *ConversationManager) getSystemMessage(id int64) string {

func startConversation(systemMessage string) Conversation {
return Conversation{
Messages: []azopenai.ChatMessage{
{
Role: to.Ptr(azopenai.ChatRoleSystem),
Messages: []azopenai.ChatRequestMessageClassification{
&azopenai.ChatRequestSystemMessage{
Content: to.Ptr(systemMessage),
},
},
Expand All @@ -72,24 +71,24 @@ func (c *ConversationManager) AddUserMessage(id int64, userInput string) *Conver
conv := c.GetConversation(id)
conv.Messages = append(
conv.Messages,
azopenai.ChatMessage{
Role: to.Ptr(azopenai.ChatRoleUser),
Content: to.Ptr(userInput),
})
&azopenai.ChatRequestUserMessage{
Content: azopenai.NewChatRequestUserMessageContent(userInput),
},
)
return conv
}

func (c *ConversationManager) AddResponse(id int64, response string) {
conv := c.GetConversation(id)
conv.Messages = append(
conv.Messages,
azopenai.ChatMessage{
Role: to.Ptr(azopenai.ChatRoleAssistant),
&azopenai.ChatRequestAssistantMessage{
Content: to.Ptr(response),
})
},
)

if len(conv.Messages) > c.pastMessagesIncluded && len(conv.Messages) > 3 {
// keep the system message, remove 2nd (user message) and 3rd (assistant response)
conv.Messages = append([]azopenai.ChatMessage{conv.Messages[0]}, conv.Messages[3:]...)
conv.Messages = append([]azopenai.ChatRequestMessageClassification{conv.Messages[0]}, conv.Messages[3:]...)
}
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/xnth97/magic-conch
go 1.20

require (
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.1.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1
github.com/deckarep/golang-set/v2 v2.3.1
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.5.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0
github.com/deckarep/golang-set/v2 v2.6.0
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
)

require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/text v0.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
30 changes: 15 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.1.1 h1:CZwHAPNp2pS80XfUr4xlC1n2M1xsGZ1UfnDW4EzHZGA=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.1.1/go.mod h1:zPJgGMjMheJJrYgrQ4W8NrNCWtWXAkjI3KWYFnTtwdA=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1 h1:SEy2xmstIphdPwNBUi7uhvjyjhVKISfwjfOJmuy7kg4=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.5.0 h1:jQ5K0LChwOu8Kx2pkBeUCskXT/UCL7dKNMIm0QUHI+0=
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.5.0/go.mod h1:pzGC8ZUnOtOCnyXHTBkj0+BjgFUsnWcqyI3FjvpnQU8=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 h1:n1DH8TPV4qqPTje2RcUBYwtrTWlabVp4n46+74X2pn4=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0/go.mod h1:HDcZnuGbiyppErN6lB+idp4CKhjbc8gwjto6OPpyggM=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 h1:LqbJ/WzJUwBf8UiaSzgX7aMclParm9/5Vgp+TY51uBQ=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2/go.mod h1:yInRyqWXAuaPrgI7p70+lDDgh3mlBohis29jGMISnmc=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A=
github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
Expand All @@ -18,12 +18,12 @@ github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 comments on commit f2303b4

Please sign in to comment.