diff options
Diffstat (limited to 'internal/llm/provider')
| -rw-r--r-- | internal/llm/provider/anthropic.go | 12 | ||||
| -rw-r--r-- | internal/llm/provider/gemini.go | 8 | ||||
| -rw-r--r-- | internal/llm/provider/openai.go | 8 | ||||
| -rw-r--r-- | internal/llm/provider/provider.go | 20 |
4 files changed, 24 insertions, 24 deletions
diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go index edd1c1d70..9c599df5b 100644 --- a/internal/llm/provider/anthropic.go +++ b/internal/llm/provider/anthropic.go @@ -15,9 +15,9 @@ import ( "github.com/opencode-ai/opencode/internal/config" "github.com/opencode-ai/opencode/internal/llm/models" "github.com/opencode-ai/opencode/internal/llm/tools" - "github.com/opencode-ai/opencode/internal/logging" "github.com/opencode-ai/opencode/internal/message" "github.com/opencode-ai/opencode/internal/status" + "log/slog" ) type anthropicOptions struct { @@ -107,7 +107,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic } if len(blocks) == 0 { - logging.Warn("There is a message without content, investigate, this should not happen") + slog.Warn("There is a message without content, investigate, this should not happen") continue } anthropicMessages = append(anthropicMessages, anthropic.NewAssistantMessage(blocks...)) @@ -210,7 +210,7 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message, cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(preparedMessages) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 @@ -222,7 +222,7 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message, ) // If there is an error we are going to see if we can retry the call if err != nil { - logging.Error("Error in Anthropic API call", "error", err) + slog.Error("Error in Anthropic API call", "error", err) retry, after, retryErr := a.shouldRetry(attempts, err) if retryErr != nil { return nil, retryErr @@ -259,7 +259,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(preparedMessages) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 eventChan := make(chan ProviderEvent) @@ -277,7 +277,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message event := anthropicStream.Current() err := accumulatedMessage.Accumulate(event) if err != nil { - logging.Warn("Error accumulating message", "error", err) + slog.Warn("Error accumulating message", "error", err) continue } diff --git a/internal/llm/provider/gemini.go b/internal/llm/provider/gemini.go index 2986c715e..c37aee4b6 100644 --- a/internal/llm/provider/gemini.go +++ b/internal/llm/provider/gemini.go @@ -13,11 +13,11 @@ import ( "github.com/google/uuid" "github.com/opencode-ai/opencode/internal/config" "github.com/opencode-ai/opencode/internal/llm/tools" - "github.com/opencode-ai/opencode/internal/logging" "github.com/opencode-ai/opencode/internal/message" "github.com/opencode-ai/opencode/internal/status" "google.golang.org/api/iterator" "google.golang.org/api/option" + "log/slog" ) type geminiOptions struct { @@ -42,7 +42,7 @@ func newGeminiClient(opts providerClientOptions) GeminiClient { client, err := genai.NewClient(context.Background(), option.WithAPIKey(opts.apiKey)) if err != nil { - logging.Error("Failed to create Gemini client", "error", err) + slog.Error("Failed to create Gemini client", "error", err) return nil } @@ -176,7 +176,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(geminiMessages) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 @@ -263,7 +263,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(geminiMessages) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 diff --git a/internal/llm/provider/openai.go b/internal/llm/provider/openai.go index 3bf8a6d42..777d9d8cc 100644 --- a/internal/llm/provider/openai.go +++ b/internal/llm/provider/openai.go @@ -14,9 +14,9 @@ import ( "github.com/opencode-ai/opencode/internal/config" "github.com/opencode-ai/opencode/internal/llm/models" "github.com/opencode-ai/opencode/internal/llm/tools" - "github.com/opencode-ai/opencode/internal/logging" "github.com/opencode-ai/opencode/internal/message" "github.com/opencode-ai/opencode/internal/status" + "log/slog" ) type openaiOptions struct { @@ -199,7 +199,7 @@ func (o *openaiClient) send(ctx context.Context, messages []message.Message, too cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(params) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 for { @@ -256,7 +256,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t cfg := config.Get() if cfg.Debug { jsonData, _ := json.Marshal(params) - logging.Debug("Prepared messages", "messages", string(jsonData)) + slog.Debug("Prepared messages", "messages", string(jsonData)) } attempts := 0 @@ -427,7 +427,7 @@ func WithReasoningEffort(effort string) OpenAIOption { case "low", "medium", "high": defaultReasoningEffort = effort default: - logging.Warn("Invalid reasoning effort, using default: medium") + slog.Warn("Invalid reasoning effort, using default: medium") } options.reasoningEffort = defaultReasoningEffort } diff --git a/internal/llm/provider/provider.go b/internal/llm/provider/provider.go index 6aaf9ff09..45c63acac 100644 --- a/internal/llm/provider/provider.go +++ b/internal/llm/provider/provider.go @@ -6,8 +6,8 @@ import ( "github.com/opencode-ai/opencode/internal/llm/models" "github.com/opencode-ai/opencode/internal/llm/tools" - "github.com/opencode-ai/opencode/internal/logging" "github.com/opencode-ai/opencode/internal/message" + "log/slog" ) type EventType string @@ -166,13 +166,13 @@ func (p *baseProvider[C]) SendMessages(ctx context.Context, messages []message.M messages = p.cleanMessages(messages) response, err := p.client.send(ctx, messages, tools) if err == nil && response != nil { - logging.Debug("API request token usage", + slog.Debug("API request token usage", "model", p.options.model.Name, "input_tokens", response.Usage.InputTokens, "output_tokens", response.Usage.OutputTokens, "cache_creation_tokens", response.Usage.CacheCreationTokens, "cache_read_tokens", response.Usage.CacheReadTokens, - "total_tokens", response.Usage.InputTokens + response.Usage.OutputTokens) + "total_tokens", response.Usage.InputTokens+response.Usage.OutputTokens) } return response, err } @@ -188,30 +188,30 @@ func (p *baseProvider[C]) MaxTokens() int64 { func (p *baseProvider[C]) StreamResponse(ctx context.Context, messages []message.Message, tools []tools.BaseTool) <-chan ProviderEvent { messages = p.cleanMessages(messages) eventChan := p.client.stream(ctx, messages, tools) - + // Create a new channel to intercept events wrappedChan := make(chan ProviderEvent) - + go func() { defer close(wrappedChan) - + for event := range eventChan { // Pass the event through wrappedChan <- event - + // Log token usage when we get the complete event if event.Type == EventComplete && event.Response != nil { - logging.Debug("API streaming request token usage", + slog.Debug("API streaming request token usage", "model", p.options.model.Name, "input_tokens", event.Response.Usage.InputTokens, "output_tokens", event.Response.Usage.OutputTokens, "cache_creation_tokens", event.Response.Usage.CacheCreationTokens, "cache_read_tokens", event.Response.Usage.CacheReadTokens, - "total_tokens", event.Response.Usage.InputTokens + event.Response.Usage.OutputTokens) + "total_tokens", event.Response.Usage.InputTokens+event.Response.Usage.OutputTokens) } } }() - + return wrappedChan } |
