bedrock.go

 1package bedrock
 2
 3import (
 4	"charm.land/fantasy"
 5	"charm.land/fantasy/anthropic"
 6	"github.com/anthropics/anthropic-sdk-go/option"
 7)
 8
 9type options struct {
10	skipAuth         bool
11	anthropicOptions []anthropic.Option
12}
13
14const (
15	Name = "bedrock"
16)
17
18type Option = func(*options)
19
20func New(opts ...Option) fantasy.Provider {
21	var o options
22	for _, opt := range opts {
23		opt(&o)
24	}
25	return anthropic.New(
26		append(
27			o.anthropicOptions,
28			anthropic.WithName(Name),
29			anthropic.WithBedrock(),
30			anthropic.WithSkipAuth(o.skipAuth),
31		)...,
32	)
33}
34
35func WithHeaders(headers map[string]string) Option {
36	return func(o *options) {
37		o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHeaders(headers))
38	}
39}
40
41func WithHTTPClient(client option.HTTPClient) Option {
42	return func(o *options) {
43		o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHTTPClient(client))
44	}
45}
46
47func WithSkipAuth(skipAuth bool) Option {
48	return func(o *options) {
49		o.skipAuth = skipAuth
50	}
51}