Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ok for support claude-3-5-sonnet #30

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: clean build unit-test run docker-* tag release

NAME=trading-gpt
VERSION=0.23.3
VERSION=0.24.1

clean:
rm -rf build/*
Expand Down
6 changes: 3 additions & 3 deletions bbgo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ exchangeStrategies:
base_url: "https://api.deepseek.com"
model: "deepseek-coder"
anthropic:
model: "claude-3-sonnet-20240229"
model: "claude-3-5-sonnet-20240620"
ollama:
server_url: "http://localhost:11434"
model: "wizardlm2:7b" # Options:wizardlm2:7b, codegemma:7b, llama3:latest, and mistral:latest
primary: "ollama"
secondly: "anthropic"
primary: "anthropic"
secondly: "ollama"
env:
exchange:
kline_num: 50
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/joho/godotenv v1.5.1
github.com/kataras/go-events v0.0.3
github.com/larksuite/oapi-sdk-go/v3 v3.2.1
github.com/madebywelch/anthropic-go/v2 v2.1.8
github.com/madebywelch/anthropic-go/v2 v2.2.4
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/madebywelch/anthropic-go/v2 v2.1.8 h1:AcDFUaM0CVqE+TByn8zBcgMEgaIx4KHBz6Wp48anD0k=
github.com/madebywelch/anthropic-go/v2 v2.1.8/go.mod h1:sXtJg4XROodT00PuOhpl5mXW7xhxNjb93B3oZnk8Yus=
github.com/madebywelch/anthropic-go/v2 v2.2.4 h1:TXV6c3kpTMlsYeIiVmynQyJHKhnOOTAJiivIWPTP1rg=
github.com/madebywelch/anthropic-go/v2 v2.2.4/go.mod h1:sXtJg4XROodT00PuOhpl5mXW7xhxNjb93B3oZnk8Yus=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
Expand Down
18 changes: 9 additions & 9 deletions pkg/llms/anthropic/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,23 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten

chatMsgs := make([]anthropic.MessagePartRequest, 0)
var lastRole llms.ChatMessageType
var buffer string
var tmpContentBlocks []anthropic.ContentBlock

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

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

if buffer != "" {
if len(tmpContentBlocks) > 0 {
// Append the buffered message before starting a new one
chatMsgs = append(chatMsgs, anthropic.MessagePartRequest{
Content: buffer,
Content: tmpContentBlocks,
Role: "user",
})
buffer = ""
tmpContentBlocks = make([]anthropic.ContentBlock, 0)
}

switch mc.Role {
Expand All @@ -105,22 +105,22 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
continue
case llms.ChatMessageTypeAI:
msg := anthropic.MessagePartRequest{
Content: textMsg,
Content: []anthropic.ContentBlock{anthropic.NewTextContentBlock(textMsg)},
Role: "assistant",
}
chatMsgs = append(chatMsgs, msg)
case llms.ChatMessageTypeHuman:
buffer = textMsg // Start buffering user messages
tmpContentBlocks = append(tmpContentBlocks, anthropic.NewTextContentBlock(textMsg))
default:
return nil, fmt.Errorf("role %v not supported", mc.Role)
}

lastRole = mc.Role
}

if buffer != "" {
if len(tmpContentBlocks) > 0 {
chatMsgs = append(chatMsgs, anthropic.MessagePartRequest{
Content: buffer,
Content: tmpContentBlocks,
Role: "user",
})
}
Expand Down
Loading