on main help sign in
fix(anthropic): increase max retries
50d8fbbadamdottv
internal/llm/provider/anthropic.go+33−25
@@ -68,21 +68,25 @@ func (a *anthropicProvider) SendMessages(ctx context.Context, messages []message
68 anthropicMessages := a.convertToAnthropicMessages(messages)
68 anthropicMessages := a.convertToAnthropicMessages(messages)
69 anthropicTools := a.convertToAnthropicTools(tools)
69 anthropicTools := a.convertToAnthropicTools(tools)
70
70
71− response, err := a.client.Messages.New(ctx, anthropic.MessageNewParams{
71+ response, err := a.client.Messages.New(
72+ ctx,
73+ anthropic.MessageNewParams{
72− Model: anthropic.Model(a.model.APIModel),
74+ Model: anthropic.Model(a.model.APIModel),
73− MaxTokens: a.maxTokens,
75+ MaxTokens: a.maxTokens,
74− Temperature: anthropic.Float(0),
76+ Temperature: anthropic.Float(0),
75− Messages: anthropicMessages,
77+ Messages: anthropicMessages,
76− Tools: anthropicTools,
78+ Tools: anthropicTools,
77− System: []anthropic.TextBlockParam{
79+ System: []anthropic.TextBlockParam{
78− {
80+ {
79− Text: a.systemMessage,
81+ Text: a.systemMessage,
80− CacheControl: anthropic.CacheControlEphemeralParam{
82+ CacheControl: anthropic.CacheControlEphemeralParam{
81− Type: "ephemeral",
83+ Type: "ephemeral",
84+ },
82 },
85 },
83 },
86 },
84 },
87 },
88+ option.WithMaxRetries(8),
85− })
89+ )
86 if err != nil {
90 if err != nil {
87 return nil, err
91 return nil, err
88 }
92 }
@@ -121,22 +125,26 @@ func (a *anthropicProvider) StreamResponse(ctx context.Context, messages []messa
121 temperature = anthropic.Float(1)
125 temperature = anthropic.Float(1)
122 }
126 }
123
127
124− stream := a.client.Messages.NewStreaming(ctx, anthropic.MessageNewParams{
128+ stream := a.client.Messages.NewStreaming(
129+ ctx,
130+ anthropic.MessageNewParams{
125− Model: anthropic.Model(a.model.APIModel),
131+ Model: anthropic.Model(a.model.APIModel),
126− MaxTokens: a.maxTokens,
132+ MaxTokens: a.maxTokens,
127− Temperature: temperature,
133+ Temperature: temperature,
128− Messages: anthropicMessages,
134+ Messages: anthropicMessages,
129− Tools: anthropicTools,
135+ Tools: anthropicTools,
130− Thinking: thinkingParam,
136+ Thinking: thinkingParam,
131− System: []anthropic.TextBlockParam{
137+ System: []anthropic.TextBlockParam{
132− {
138+ {
133− Text: a.systemMessage,
139+ Text: a.systemMessage,
134− CacheControl: anthropic.CacheControlEphemeralParam{
140+ CacheControl: anthropic.CacheControlEphemeralParam{
135− Type: "ephemeral",
141+ Type: "ephemeral",
142+ },
136 },
143 },
137 },
144 },
138 },
145 },
146+ option.WithMaxRetries(8),
139− })
147+ )
140
148
141 eventChan := make(chan ProviderEvent)
149 eventChan := make(chan ProviderEvent)
142
150