1// Package bedrock provides an implementation of the fantasy AI SDK for AWS Bedrock's language models.
2package bedrock
3
4import (
5 "charm.land/fantasy"
6 "charm.land/fantasy/providers/anthropic"
7 "github.com/anthropics/anthropic-sdk-go/option"
8)
9
10type options struct {
11 anthropicOptions []anthropic.Option
12}
13
14const (
15 // Name is the name of the Bedrock provider.
16 Name = "bedrock"
17)
18
19// Option defines a function that configures Bedrock provider options.
20type Option = func(*options)
21
22// New creates a new Bedrock provider with the given options.
23func New(opts ...Option) (fantasy.Provider, error) {
24 var o options
25 for _, opt := range opts {
26 opt(&o)
27 }
28 return anthropic.New(
29 append(
30 o.anthropicOptions,
31 anthropic.WithName(Name),
32 anthropic.WithBedrock(),
33 )...,
34 )
35}
36
37// WithAPIKey sets the access token for the Bedrock provider.
38func WithAPIKey(apiKey string) Option {
39 return func(o *options) {
40 o.anthropicOptions = append(o.anthropicOptions, anthropic.WithAPIKey(apiKey))
41 }
42}
43
44// WithHeaders sets the headers for the Bedrock provider.
45func WithHeaders(headers map[string]string) Option {
46 return func(o *options) {
47 o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHeaders(headers))
48 }
49}
50
51// WithHTTPClient sets the HTTP client for the Bedrock provider.
52func WithHTTPClient(client option.HTTPClient) Option {
53 return func(o *options) {
54 o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHTTPClient(client))
55 }
56}