Skip to content
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
75 changes: 69 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,73 @@ name: build
on: [push, pull_request]

jobs:
govulncheck:
runs-on: ubuntu-latest
env:
GH_PAT: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
GOTOOLCHAIN: local
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# The reusable charmbracelet/meta govulncheck job always reads go.mod.
# Keep the module baseline at Go 1.25.0, but run the scanner with Go 1.26.4
# so it uses a fixed standard library.
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.4"
cache: true
check-latest: true
- run: |
git config --global url."https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/charmbracelet".insteadOf "https://github.com/charmbracelet"
git config --global url."https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/charmcli".insteadOf "https://github.com/charmcli"
if: env.GH_PAT != ''
- run: go install golang.org/x/vuln/cmd/govulncheck@latest
- run: go mod tidy
- run: govulncheck ./...

build:
uses: charmbracelet/meta/.github/workflows/build.yml@main
with:
go-version: ""
go-version-file: ./go.mod
secrets:
gh_pat: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
GH_PAT: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- run: |
git config --global url."https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/charmbracelet".insteadOf "https://github.com/charmbracelet"
git config --global url."https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/charmcli".insteadOf "https://github.com/charmcli"
if: env.GH_PAT != ''
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Tidy Go modules
run: go mod tidy
- name: Check for changes
run: git diff --exit-code
- name: Build
run: go build ./...
- name: Test
run: go test ./...

dependabot:
needs: [build, govulncheck]
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
steps:
- id: metadata
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- run: |
gh pr review --approve "$PR_URL"
gh pr merge --squash --auto "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ require (
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/crypto v0.51.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
golang.org/x/time v0.14.0 // indirect
google.golang.org/api v0.264.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
Expand Down
68 changes: 67 additions & 1 deletion providers/anthropic/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"maps"
"math"
"strconv"
"strings"

"charm.land/fantasy"
Expand Down Expand Up @@ -38,6 +39,51 @@ func betaRequestOptions(flags []string) []option.RequestOption {
return opts
}

func thinkingDisplay(providerOptions *ProviderOptions, modelID string) (ThinkingDisplay, bool) {
if providerOptions != nil && providerOptions.ThinkingDisplay != nil && *providerOptions.ThinkingDisplay != "" {
return *providerOptions.ThinkingDisplay, true
}
if defaultsToOmittedThinkingDisplay(modelID) {
return ThinkingDisplaySummarized, true
Comment thread
ibetitsmike marked this conversation as resolved.
}
return "", false
}

func defaultsToAdaptiveThinking(model string) bool {
model = strings.ToLower(strings.TrimSpace(model))
return strings.Contains(model, "claude-mythos-preview")
}

func requiresAdaptiveThinking(model string) bool {
return defaultsToAdaptiveThinking(model) || defaultsToOmittedOpusThinkingDisplay(model)
}

func setThinkingDisplay(param interface{ SetExtraFields(map[string]any) }, display ThinkingDisplay) {
param.SetExtraFields(map[string]any{"display": string(display)})
}

func defaultsToOmittedThinkingDisplay(model string) bool {
model = strings.ToLower(strings.TrimSpace(model))
return defaultsToAdaptiveThinking(model) || defaultsToOmittedOpusThinkingDisplay(model)
}

func defaultsToOmittedOpusThinkingDisplay(model string) bool {
_, suffix, ok := strings.Cut(model, "claude-opus-4-")
if !ok {
return false
Comment thread
ibetitsmike marked this conversation as resolved.
}

versionEnd := 0
Comment thread
ibetitsmike marked this conversation as resolved.
for versionEnd < len(suffix) && suffix[versionEnd] >= '0' && suffix[versionEnd] <= '9' {
versionEnd++
}
if versionEnd == 0 || versionEnd > 2 {
return false
}
minor, err := strconv.Atoi(suffix[:versionEnd])
return err == nil && minor >= 7
}

// buildRequestOptions constructs the common request options shared
// by Generate and Stream: user-agent, raw tool injection, and any
// beta API flags.
Expand Down Expand Up @@ -335,12 +381,26 @@ func (a languageModel) prepareParams(call fantasy.Call) (
Effort: anthropic.OutputConfigEffort(effort),
}
adaptive := anthropic.NewThinkingConfigAdaptiveParam()
if display, ok := thinkingDisplay(providerOptions, a.modelID); ok {
setThinkingDisplay(&adaptive, display)
}
params.Thinking.OfAdaptive = &adaptive
case providerOptions.Thinking != nil:
if providerOptions.Thinking.BudgetTokens == 0 {
return nil, nil, nil, nil, &fantasy.Error{Title: "no budget", Message: "thinking requires budget"}
}
params.Thinking = anthropic.ThinkingConfigParamOfEnabled(providerOptions.Thinking.BudgetTokens)
if requiresAdaptiveThinking(a.modelID) {
adaptive := anthropic.NewThinkingConfigAdaptiveParam()
if display, ok := thinkingDisplay(providerOptions, a.modelID); ok {
setThinkingDisplay(&adaptive, display)
}
params.Thinking.OfAdaptive = &adaptive
} else {
params.Thinking = anthropic.ThinkingConfigParamOfEnabled(providerOptions.Thinking.BudgetTokens)
if display, ok := thinkingDisplay(providerOptions, a.modelID); ok {
setThinkingDisplay(params.Thinking.OfEnabled, display)
}
}
if call.Temperature != nil {
params.Temperature = param.Opt[float64]{}
warnings = append(warnings, fantasy.CallWarning{
Expand All @@ -365,6 +425,12 @@ func (a languageModel) prepareParams(call fantasy.Call) (
Details: "TopK is not supported when thinking is enabled",
})
}
case defaultsToAdaptiveThinking(a.modelID):
Comment thread
ibetitsmike marked this conversation as resolved.
adaptive := anthropic.NewThinkingConfigAdaptiveParam()
if display, ok := thinkingDisplay(providerOptions, a.modelID); ok {
setThinkingDisplay(&adaptive, display)
}
params.Thinking.OfAdaptive = &adaptive
}

if len(call.Tools) > 0 {
Expand Down
Loading
Loading