summaryrefslogtreecommitdiff
path: root/internal/llm/provider.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/llm/provider.go')
-rw-r--r--internal/llm/provider.go36
1 files changed, 25 insertions, 11 deletions
diff --git a/internal/llm/provider.go b/internal/llm/provider.go
index fd9d4d3..a80b1c1 100644
--- a/internal/llm/provider.go
+++ b/internal/llm/provider.go
@@ -1,10 +1,10 @@
package llm
import (
- "context"
- "errors"
- "log"
- "os"
+ "context"
+ "errors"
+ "log"
+ "os"
)
// Message represents a chat-style prompt message.
@@ -16,8 +16,8 @@ type Message struct {
// Client is a minimal LLM provider interface.
// Future providers (Ollama, etc.) should implement this.
type Client interface {
- // Chat sends chat messages and returns the assistant text.
- Chat(ctx context.Context, messages []Message, opts ...RequestOption) (string, error)
+ // Chat sends chat messages and returns the assistant text.
+ Chat(ctx context.Context, messages []Message, opts ...RequestOption) (string, error)
}
// Options for a request. Providers may ignore unsupported fields.
@@ -41,9 +41,23 @@ func WithStop(stop ...string) RequestOption {
// NewDefault returns the default provider using environment configuration.
// Currently this is the OpenAI provider using OPENAI_API_KEY.
func NewDefault(logger *log.Logger) (Client, error) {
- apiKey := os.Getenv("OPENAI_API_KEY")
- if apiKey == "" {
- return nil, errors.New("OPENAI_API_KEY is not set")
- }
- return newOpenAIFromEnv(apiKey, logger), nil
+ apiKey := os.Getenv("OPENAI_API_KEY")
+ if apiKey == "" {
+ return nil, errors.New("OPENAI_API_KEY is not set")
+ }
+ return newOpenAIFromEnv(apiKey, logger), nil
+}
+
+// Logging configuration for previews
+var logPreviewLimit int // 0 means unlimited
+
+// SetLogPreviewLimit sets the maximum number of characters to log for
+// request/response previews. Set to 0 for unlimited.
+func SetLogPreviewLimit(n int) { logPreviewLimit = n }
+
+func previewForLog(s string) string {
+ if logPreviewLimit > 0 {
+ return trimPreview(s, logPreviewLimit)
+ }
+ return s
}