options.go

 1package kronk
 2
 3import (
 4	"context"
 5	"fmt"
 6
 7	"charm.land/fantasy"
 8	"github.com/ardanlabs/kronk/sdk/kronk/model"
 9)
10
11// Option defines a function that configures Kronk provider options.
12type Option func(*options)
13
14// Logger is the function signature for logging download progress.
15type Logger func(ctx context.Context, msg string, args ...any)
16
17type options struct {
18	name                 string
19	modelConfig          model.Config
20	logger               Logger
21	objectMode           fantasy.ObjectMode
22	languageModelOptions []LanguageModelOption
23}
24
25// WithName sets the name for the Kronk provider.
26func WithName(name string) Option {
27	return func(o *options) {
28		o.name = name
29	}
30}
31
32// WithModelConfig sets additional model configuration options.
33func WithModelConfig(cfg model.Config) Option {
34	return func(o *options) {
35		o.modelConfig = cfg
36	}
37}
38
39// WithLogger sets the logger function for download progress.
40func WithLogger(logger Logger) Option {
41	return func(o *options) {
42		o.logger = logger
43	}
44}
45
46// WithLanguageModelOptions sets the language model options for the Kronk provider.
47func WithLanguageModelOptions(opts ...LanguageModelOption) Option {
48	return func(o *options) {
49		o.languageModelOptions = append(o.languageModelOptions, opts...)
50	}
51}
52
53// WithObjectMode sets the object generation mode.
54func WithObjectMode(om fantasy.ObjectMode) Option {
55	return func(o *options) {
56		o.objectMode = om
57	}
58}
59
60// FmtLogger is a simple logger that prints to stdout using fmt.Printf.
61func FmtLogger(_ context.Context, msg string, args ...any) {
62	fmt.Printf("%s:", msg)
63
64	for i := 0; i < len(args); i += 2 {
65		if i+1 < len(args) {
66			fmt.Printf(" %v[%v]", args[i], args[i+1])
67		}
68	}
69
70	fmt.Println()
71}