diff options
| author | adamdottv <[email protected]> | 2025-05-15 12:04:15 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-15 12:04:15 -0500 |
| commit | ddbb217d0d9f707f22610433664e15362cf98202 (patch) | |
| tree | a41b1e3a4c855692890ec9778a0a594568341345 /internal/llm | |
| parent | ab150be7c393a91d9fb2347b7012ad2f7d77700b (diff) | |
| download | opencode-ddbb217d0d9f707f22610433664e15362cf98202.tar.gz opencode-ddbb217d0d9f707f22610433664e15362cf98202.zip | |
feat: better status bar
Diffstat (limited to 'internal/llm')
| -rw-r--r-- | internal/llm/provider/anthropic.go | 10 | ||||
| -rw-r--r-- | internal/llm/provider/gemini.go | 10 | ||||
| -rw-r--r-- | internal/llm/provider/openai.go | 10 |
3 files changed, 18 insertions, 12 deletions
diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go index 2df2bf0fd..24bcb48fb 100644 --- a/internal/llm/provider/anthropic.go +++ b/internal/llm/provider/anthropic.go @@ -224,15 +224,16 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message, if err != nil { slog.Error("Error in Anthropic API call", "error", err) retry, after, retryErr := a.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { return nil, retryErr } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): continue } } @@ -360,13 +361,14 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message } // If there is an error we are going to see if we can retry the call retry, after, retryErr := a.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { eventChan <- ProviderEvent{Type: EventError, Error: retryErr} close(eventChan) return } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): // context cancelled @@ -375,7 +377,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message } close(eventChan) return - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): continue } } diff --git a/internal/llm/provider/gemini.go b/internal/llm/provider/gemini.go index 1b2ac9999..cc97463d4 100644 --- a/internal/llm/provider/gemini.go +++ b/internal/llm/provider/gemini.go @@ -197,15 +197,16 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too // If there is an error we are going to see if we can retry the call if err != nil { retry, after, retryErr := g.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { return nil, retryErr } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): continue } } @@ -292,12 +293,13 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t for resp, err := range chat.SendMessageStream(ctx, lastMsgParts...) { if err != nil { retry, after, retryErr := g.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { eventChan <- ProviderEvent{Type: EventError, Error: retryErr} return } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): if ctx.Err() != nil { @@ -305,7 +307,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t } return - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): break } } else { diff --git a/internal/llm/provider/openai.go b/internal/llm/provider/openai.go index 754b9d254..3e79edde8 100644 --- a/internal/llm/provider/openai.go +++ b/internal/llm/provider/openai.go @@ -211,15 +211,16 @@ func (o *openaiClient) send(ctx context.Context, messages []message.Message, too // If there is an error we are going to see if we can retry the call if err != nil { retry, after, retryErr := o.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { return nil, retryErr } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): continue } } @@ -315,13 +316,14 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t // If there is an error we are going to see if we can retry the call retry, after, retryErr := o.shouldRetry(attempts, err) + duration := time.Duration(after) * time.Millisecond if retryErr != nil { eventChan <- ProviderEvent{Type: EventError, Error: retryErr} close(eventChan) return } if retry { - status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries)) + status.Warn(fmt.Sprintf("Retrying due to rate limit... attempt %d of %d", attempts, maxRetries), status.WithDuration(duration)) select { case <-ctx.Done(): // context cancelled @@ -330,7 +332,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t } close(eventChan) return - case <-time.After(time.Duration(after) * time.Millisecond): + case <-time.After(duration): continue } } |
