-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfig.go
119 lines (105 loc) · 5.17 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Package gollm provides a high-level interface for interacting with various Language Learning Models (LLMs).
// This file re-exports configuration types and functions from the config package to provide
// a clean, centralized API for configuring LLM interactions.
package gollm
import (
"github.com/teilomillet/gollm/config"
"github.com/teilomillet/gollm/utils"
)
// Re-export core configuration types for easier access
type (
// Config represents the complete configuration for LLM interactions.
// It includes settings for model selection, API endpoints, generation parameters,
// and runtime behavior. See config.Config for detailed field documentation.
//
// Example usage:
// cfg := NewConfig()
// cfg = ApplyOptions(cfg, SetProvider("openai"), SetModel("gpt-3.5-turbo"))
Config = config.Config
// ConfigOption is a function type that modifies a Config instance.
// It enables a builder pattern for configuration, allowing for clean
// and flexible configuration updates.
//
// Example usage:
// cfg := NewConfig()
// cfg = ApplyOptions(cfg, SetTemperature(0.7), SetMaxTokens(2048))
ConfigOption = config.ConfigOption
// LogLevel defines the verbosity of logging output.
// Available levels are defined as constants: LogLevelOff through LogLevelDebug.
//
// Example usage:
// cfg := NewConfig()
// cfg = ApplyOptions(cfg, SetLogLevel(LogLevelInfo))
LogLevel = utils.LogLevel
// MemoryOption configures the memory settings for conversation history.
// It controls how much context is retained between interactions.
//
// Example usage:
// cfg := NewConfig()
// cfg = ApplyOptions(cfg, SetMemory(MemoryOption{MaxHistory: 10}))
MemoryOption = config.MemoryOption
)
// Re-export core configuration functions
var (
// LoadConfig loads configuration from environment variables and returns a new Config instance.
// It automatically detects and loads API keys from environment variables matching the pattern
// *_API_KEY (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY).
//
// Example usage:
// cfg, err := LoadConfig()
// if err != nil {
// log.Fatal(err)
// }
LoadConfig = config.LoadConfig
// ApplyOptions applies a series of ConfigOption functions to a Config instance.
// This enables fluent configuration updates using the builder pattern.
//
// Example usage:
// cfg := NewConfig()
// cfg = ApplyOptions(cfg, SetProvider("openai"), SetModel("gpt-3.5-turbo"))
ApplyOptions = config.ApplyOptions
)
// Re-export ConfigOption functions for configuration modification.
// Each function returns a ConfigOption that can be used with ApplyOptions
// to modify configuration settings.
var (
// Provider configuration
SetProvider = config.SetProvider // Sets the LLM provider (e.g., "openai", "anthropic")
SetModel = config.SetModel // Sets the model name for the selected provider
SetOllamaEndpoint = config.SetOllamaEndpoint // Sets the endpoint URL for Ollama local deployment
SetAPIKey = config.SetAPIKey // Sets the API key for the current provider
// Generation parameters
SetTemperature = config.SetTemperature // Controls randomness in generation (0.0-1.0)
SetMaxTokens = config.SetMaxTokens // Sets maximum tokens to generate
SetTopP = config.SetTopP // Controls nucleus sampling
SetFrequencyPenalty = config.SetFrequencyPenalty // Penalizes frequent token usage
SetPresencePenalty = config.SetPresencePenalty // Penalizes repeated tokens
SetSeed = config.SetSeed // Sets random seed for reproducible generation
// Advanced generation parameters
SetMinP = config.SetMinP // Sets minimum probability threshold
SetRepeatPenalty = config.SetRepeatPenalty // Controls repetition penalty
SetRepeatLastN = config.SetRepeatLastN // Sets context window for repetition
SetMirostat = config.SetMirostat // Enables Mirostat sampling
SetMirostatEta = config.SetMirostatEta // Sets Mirostat learning rate
SetMirostatTau = config.SetMirostatTau // Sets Mirostat target entropy
SetTfsZ = config.SetTfsZ // Sets tail-free sampling parameter
// Runtime configuration
SetTimeout = config.SetTimeout // Sets request timeout duration
SetMaxRetries = config.SetMaxRetries // Sets maximum retry attempts
SetRetryDelay = config.SetRetryDelay // Sets delay between retries
SetLogLevel = config.SetLogLevel // Sets logging verbosity
SetExtraHeaders = config.SetExtraHeaders // Sets additional HTTP headers
// Feature toggles
SetEnableCaching = config.SetEnableCaching // Enables/disables response caching
SetMemory = config.SetMemory // Configures conversation memory
// Configuration creation
NewConfig = config.NewConfig // Creates a new Config with default values
)
// LogLevel constants define available logging verbosity levels
const (
LogLevelOff = utils.LogLevelOff // Disables all logging
LogLevelError = utils.LogLevelError // Logs only errors
LogLevelWarn = utils.LogLevelWarn // Logs warnings and errors
LogLevelInfo = utils.LogLevelInfo // Logs info, warnings, and errors
LogLevelDebug = utils.LogLevelDebug // Logs all messages including debug
)