-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
90 lines (79 loc) · 2.3 KB
/
client.go
File metadata and controls
90 lines (79 loc) · 2.3 KB
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
package augur
import "log/slog"
const (
defaultMaxRetries = 2
defaultMaxTokens = 8192
)
// Client is the main entry point for Augur queries. It holds a provider and
// client-level configuration applied to every query unless overridden via
// QueryOptions.
type Client struct {
provider Provider
maxRetries int
maxTokens int
model string
logger *slog.Logger
sourceConfig SourceConfig
webSearchEnabled bool
}
// Option configures a Client via the functional options pattern.
type Option func(*Client)
// WithMaxRetries sets the maximum number of retry attempts for required fields
// that fail validation. Default: 2.
func WithMaxRetries(n int) Option {
return func(c *Client) {
c.maxRetries = n
}
}
// WithModel sets the model identifier for this client, overriding the provider's default.
// Can be further overridden per-query via QueryOptions.Model.
func WithModel(model string) Option {
return func(c *Client) {
c.model = model
}
}
// WithMaxTokens sets the maximum number of output tokens for LLM responses.
// Default: 8192.
func WithMaxTokens(n int) Option {
return func(c *Client) {
c.maxTokens = n
}
}
// WithLogger enables structured debug logging for internal operations (prompt
// construction, coercion decisions, retry attempts). Silent by default.
func WithLogger(logger *slog.Logger) Option {
return func(c *Client) {
c.logger = logger
}
}
// WithoutWebSearch disables web search globally for this client. Per-query
// SourceConfig overrides still take effect. By default, web search is enabled.
func WithoutWebSearch() Option {
return func(c *Client) {
c.webSearchEnabled = false
}
}
// WithSourceConfig sets the default SourceConfig for all queries made by this
// client. Per-query SourceConfig overrides take precedence.
func WithSourceConfig(cfg SourceConfig) Option {
return func(c *Client) {
c.sourceConfig = cfg
}
}
// New creates a new Augur client with the given provider and options.
// Panics if provider is nil.
func New(provider Provider, opts ...Option) *Client {
if provider == nil {
panic("augur: provider must not be nil")
}
c := &Client{
provider: provider,
maxRetries: defaultMaxRetries,
maxTokens: defaultMaxTokens,
webSearchEnabled: true,
}
for _, opt := range opts {
opt(c)
}
return c
}