on main help sign in
fix(llm): set request timeout (#736)
0f403feCarlos Alexandro Becker
internal/llm/provider/anthropic.go+1−2
@@ -153,7 +153,6 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
153 }
153 }
154
154
155 if len(blocks) == 0 {
155 if len(blocks) == 0 {
156− slog.Warn("There is a message without content, investigate, this should not happen")
157 continue
156 continue
158 }
157 }
159 anthropicMessages = append(anthropicMessages, anthropic.NewAssistantMessage(blocks...))
158 anthropicMessages = append(anthropicMessages, anthropic.NewAssistantMessage(blocks...))
@@ -333,7 +332,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
333 // Prepare messages on each attempt in case max_tokens was adjusted
332 // Prepare messages on each attempt in case max_tokens was adjusted
334 preparedMessages := a.preparedMessages(a.convertMessages(messages), a.convertTools(tools))
333 preparedMessages := a.preparedMessages(a.convertMessages(messages), a.convertTools(tools))
335
334
336− var opts []option.RequestOption
335+ opts := []option.RequestOption{option.WithRequestTimeout(time.Minute)}
337 if a.isThinkingEnabled() {
336 if a.isThinkingEnabled() {
338 opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"))
337 opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"))
339 }
338 }
internal/llm/provider/openai.go+1−1
@@ -166,7 +166,6 @@ func (o *openaiClient) convertMessages(messages []message.Message) (openaiMessag
166 }
166 }
167 }
167 }
168 if !hasContent {
168 if !hasContent {
169− slog.Warn("There is a message without content, investigate, this should not happen")
170 continue
169 continue
171 }
170 }
172
171
@@ -338,6 +337,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
338 openaiStream := o.client.Chat.Completions.NewStreaming(
337 openaiStream := o.client.Chat.Completions.NewStreaming(
339 ctx,
338 ctx,
340 params,
339 params,
340+ option.WithRequestTimeout(time.Minute),
341 )
341 )
342
342
343 acc := openai.ChatCompletionAccumulator{}
343 acc := openai.ChatCompletionAccumulator{}