on main help sign in
chore: improve thinking
2885e71Kujtim Hoxha
internal/llm/provider/anthropic.go+4−1
@@ -9,6 +9,7 @@ import (
9 "log/slog"
9 "log/slog"
10 "regexp"
10 "regexp"
11 "strconv"
11 "strconv"
12+ "strings"
12 "time"
13 "time"
13
14
14 "github.com/anthropics/anthropic-sdk-go"
15 "github.com/anthropics/anthropic-sdk-go"
@@ -270,6 +271,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
270 anthropicStream := a.client.Messages.NewStreaming(
271 anthropicStream := a.client.Messages.NewStreaming(
271 ctx,
272 ctx,
272 preparedMessages,
273 preparedMessages,
274+ option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"),
273 )
275 )
274 accumulatedMessage := anthropic.Message{}
276 accumulatedMessage := anthropic.Message{}
275
277
@@ -426,7 +428,8 @@ func (a *anthropicClient) shouldRetry(attempts int, err error) (bool, int64, err
426 }
428 }
427 }
429 }
428
430
431+ isOverloaded := strings.Contains(apiErr.Error(), "overloaded") || strings.Contains(apiErr.Error(), "rate limit exceeded")
429− if apiErr.StatusCode != 429 && apiErr.StatusCode != 529 {
432+ if apiErr.StatusCode != 429 && apiErr.StatusCode != 529 && !isOverloaded {
430 return false, 0, err
433 return false, 0, err
431 }
434 }
432
435