on main help sign in
fix(llm): set request timeout (#736)

* fix(llm): set request timeout If the server is down, address don't resolve, or another myriad of reasons, currently, it'll get stuck. This makes it so it times out after 1 minute. Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: remove log Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commit0f403feafcd57045802ce0e24b4eff01d409cef5 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateThu 14 Aug 2025, 10:58 (1 year ago) parent16f5400
2 files changed+2−3
internal/llm/provider/anthropic.go+1−2 internal/llm/provider/openai.go+1−1
internal/llm/provider/anthropic.go+1−2
@@ -153,7 +153,6 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
153153 }
154154
155155 if len(blocks) == 0 {
156− slog.Warn("There is a message without content, investigate, this should not happen")
157156 continue
158157 }
159158 anthropicMessages = append(anthropicMessages, anthropic.NewAssistantMessage(blocks...))
@@ -333,7 +332,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
333332 // Prepare messages on each attempt in case max_tokens was adjusted
334333 preparedMessages := a.preparedMessages(a.convertMessages(messages), a.convertTools(tools))
335334
336− var opts []option.RequestOption
335+ opts := []option.RequestOption{option.WithRequestTimeout(time.Minute)}
337336 if a.isThinkingEnabled() {
338337 opts = append(opts, option.WithHeaderAdd("anthropic-beta", "interleaved-thinking-2025-05-14"))
339338 }
internal/llm/provider/openai.go+1−1
@@ -166,7 +166,6 @@ func (o *openaiClient) convertMessages(messages []message.Message) (openaiMessag
166166 }
167167 }
168168 if !hasContent {
169− slog.Warn("There is a message without content, investigate, this should not happen")
170169 continue
171170 }
172171
@@ -338,6 +337,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
338337 openaiStream := o.client.Chat.Completions.NewStreaming(
339338 ctx,
340339 params,
340+ option.WithRequestTimeout(time.Minute),
341341 )
342342
343343 acc := openai.ChatCompletionAccumulator{}