Skip to content

Commit 3e88c79

Browse files
authored
Merge pull request #30 from yubing744/owen/support-claude-3-5-sonnet
feat: ok for support claude-3-5-sonnet
2 parents 321a338 + f90cbfc commit 3e88c79

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: clean build unit-test run docker-* tag release
22

33
NAME=trading-gpt
4-
VERSION=0.23.3
4+
VERSION=0.24.1
55

66
clean:
77
rm -rf build/*

bbgo.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ exchangeStrategies:
3333
base_url: "https://api.deepseek.com"
3434
model: "deepseek-coder"
3535
anthropic:
36-
model: "claude-3-sonnet-20240229"
36+
model: "claude-3-5-sonnet-20240620"
3737
ollama:
3838
server_url: "http://localhost:11434"
3939
model: "wizardlm2:7b" # Options:wizardlm2:7b, codegemma:7b, llama3:latest, and mistral:latest
40-
primary: "ollama"
41-
secondly: "anthropic"
40+
primary: "anthropic"
41+
secondly: "ollama"
4242
env:
4343
exchange:
4444
kline_num: 50

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/joho/godotenv v1.5.1
1111
github.com/kataras/go-events v0.0.3
1212
github.com/larksuite/oapi-sdk-go/v3 v3.2.1
13-
github.com/madebywelch/anthropic-go/v2 v2.1.8
13+
github.com/madebywelch/anthropic-go/v2 v2.2.4
1414
github.com/pkg/errors v0.9.1
1515
github.com/sirupsen/logrus v1.9.3
1616
github.com/stretchr/testify v1.9.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
482482
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
483483
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
484484
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
485-
github.com/madebywelch/anthropic-go/v2 v2.1.8 h1:AcDFUaM0CVqE+TByn8zBcgMEgaIx4KHBz6Wp48anD0k=
486-
github.com/madebywelch/anthropic-go/v2 v2.1.8/go.mod h1:sXtJg4XROodT00PuOhpl5mXW7xhxNjb93B3oZnk8Yus=
485+
github.com/madebywelch/anthropic-go/v2 v2.2.4 h1:TXV6c3kpTMlsYeIiVmynQyJHKhnOOTAJiivIWPTP1rg=
486+
github.com/madebywelch/anthropic-go/v2 v2.2.4/go.mod h1:sXtJg4XROodT00PuOhpl5mXW7xhxNjb93B3oZnk8Yus=
487487
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
488488
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
489489
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=

pkg/llms/anthropic/anthropic.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
8080

8181
chatMsgs := make([]anthropic.MessagePartRequest, 0)
8282
var lastRole llms.ChatMessageType
83-
var buffer string
83+
var tmpContentBlocks []anthropic.ContentBlock
8484

8585
for _, mc := range messages {
8686
textMsg := joinTextParts(mc.Parts)
8787

8888
if mc.Role == lastRole && mc.Role == llms.ChatMessageTypeHuman {
89-
buffer += "\r\n" + textMsg // Concatenate messages with a space
89+
tmpContentBlocks = append(tmpContentBlocks, anthropic.NewTextContentBlock(textMsg))
9090
continue
9191
}
9292

93-
if buffer != "" {
93+
if len(tmpContentBlocks) > 0 {
9494
// Append the buffered message before starting a new one
9595
chatMsgs = append(chatMsgs, anthropic.MessagePartRequest{
96-
Content: buffer,
96+
Content: tmpContentBlocks,
9797
Role: "user",
9898
})
99-
buffer = ""
99+
tmpContentBlocks = make([]anthropic.ContentBlock, 0)
100100
}
101101

102102
switch mc.Role {
@@ -105,22 +105,22 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
105105
continue
106106
case llms.ChatMessageTypeAI:
107107
msg := anthropic.MessagePartRequest{
108-
Content: textMsg,
108+
Content: []anthropic.ContentBlock{anthropic.NewTextContentBlock(textMsg)},
109109
Role: "assistant",
110110
}
111111
chatMsgs = append(chatMsgs, msg)
112112
case llms.ChatMessageTypeHuman:
113-
buffer = textMsg // Start buffering user messages
113+
tmpContentBlocks = append(tmpContentBlocks, anthropic.NewTextContentBlock(textMsg))
114114
default:
115115
return nil, fmt.Errorf("role %v not supported", mc.Role)
116116
}
117117

118118
lastRole = mc.Role
119119
}
120120

121-
if buffer != "" {
121+
if len(tmpContentBlocks) > 0 {
122122
chatMsgs = append(chatMsgs, anthropic.MessagePartRequest{
123-
Content: buffer,
123+
Content: tmpContentBlocks,
124124
Role: "user",
125125
})
126126
}

0 commit comments

Comments
 (0)