Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 05b0570

Browse files
ksylvankujtimiihoxha
authored andcommitted
refactor: upgrade Anthropic SDK to v1.4.0 and adapt provider code
### CHANGES - Upgrade Anthropic Go SDK dependency to version 1.4.0. - Adapt provider code to breaking changes in the SDK. - Update constructors for tool use and thinking parameters. - Use new `OfText` field for accessing message content. - Add Claude 4 Opus and Sonnet to documentation.
1 parent 18f020c commit 05b0570

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ OpenCode supports a variety of AI models from different providers:
203203

204204
### Anthropic
205205

206+
- Claude 4 Sonnet
207+
- Claude 4 Opus
206208
- Claude 3.5 Sonnet
207209
- Claude 3.5 Haiku
208210
- Claude 3.7 Sonnet

cmd/schema/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ Here's an example configuration that conforms to the schema:
6161
}
6262
}
6363
}
64-
```
64+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/JohannesKaufmann/html-to-markdown v1.6.0
88
github.com/PuerkitoBio/goquery v1.9.2
99
github.com/alecthomas/chroma/v2 v2.15.0
10-
github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2
10+
github.com/anthropics/anthropic-sdk-go v1.4.0
1111
github.com/aymanbagabas/go-udiff v0.2.0
1212
github.com/bmatcuk/doublestar/v4 v4.8.1
1313
github.com/catppuccin/go v0.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc
2626
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
2727
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
2828
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
29-
github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2 h1:h7qxtumNjKPWFv1QM/HJy60MteeW23iKeEtBoY7bYZk=
30-
github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2/go.mod h1:AapDW22irxK2PSumZiQXYUFvsdQgkwIWlpESweWZI/c=
29+
github.com/anthropics/anthropic-sdk-go v1.4.0 h1:fU1jKxYbQdQDiEXCxeW5XZRIOwKevn/PMg8Ay1nnUx0=
30+
github.com/anthropics/anthropic-sdk-go v1.4.0/go.mod h1:AapDW22irxK2PSumZiQXYUFvsdQgkwIWlpESweWZI/c=
3131
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
3232
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
3333
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=

internal/llm/provider/anthropic.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
6767
case message.User:
6868
content := anthropic.NewTextBlock(msg.Content().String())
6969
if cache && !a.options.disableCache {
70-
content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
70+
content.OfText.CacheControl = anthropic.CacheControlEphemeralParam{
7171
Type: "ephemeral",
7272
}
7373
}
@@ -85,7 +85,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
8585
if msg.Content().String() != "" {
8686
content := anthropic.NewTextBlock(msg.Content().String())
8787
if cache && !a.options.disableCache {
88-
content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
88+
content.OfText.CacheControl = anthropic.CacheControlEphemeralParam{
8989
Type: "ephemeral",
9090
}
9191
}
@@ -98,7 +98,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
9898
if err != nil {
9999
continue
100100
}
101-
blocks = append(blocks, anthropic.ContentBlockParamOfRequestToolUseBlock(toolCall.ID, inputMap, toolCall.Name))
101+
blocks = append(blocks, anthropic.NewToolUseBlock(toolCall.ID, inputMap, toolCall.Name))
102102
}
103103

104104
if len(blocks) == 0 {
@@ -167,17 +167,12 @@ func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, to
167167
temperature := anthropic.Float(0)
168168
if isUser {
169169
for _, m := range lastMessage.Content {
170-
if m.OfRequestTextBlock != nil && m.OfRequestTextBlock.Text != "" {
171-
messageContent = m.OfRequestTextBlock.Text
170+
if m.OfText != nil && m.OfText.Text != "" {
171+
messageContent = m.OfText.Text
172172
}
173173
}
174174
if messageContent != "" && a.options.shouldThink != nil && a.options.shouldThink(messageContent) {
175-
thinkingParam = anthropic.ThinkingConfigParamUnion{
176-
OfThinkingConfigEnabled: &anthropic.ThinkingConfigEnabledParam{
177-
BudgetTokens: int64(float64(a.providerOptions.maxTokens) * 0.8),
178-
Type: "enabled",
179-
},
180-
}
175+
thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(a.providerOptions.maxTokens) * 0.8))
181176
temperature = anthropic.Float(1)
182177
}
183178
}

0 commit comments

Comments
 (0)