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 skipAuth bool
12 anthropicOptions []anthropic.Option
13}
14
15const (
16 // Name is the name of the Bedrock provider.
17 Name = "bedrock"
18)
19
20// Option defines a function that configures Bedrock provider options.
21type Option = func(*options)
22
23// New creates a new Bedrock provider with the given options.
24func New(opts ...Option) fantasy.Provider {
25 var o options
26 for _, opt := range opts {
27 opt(&o)
28 }
29 return anthropic.New(
30 append(
31 o.anthropicOptions,
32 anthropic.WithName(Name),
33 anthropic.WithBedrock(),
34 anthropic.WithSkipAuth(o.skipAuth),
35 )...,
36 )
37}
38
39// WithHeaders sets the headers for the Bedrock provider.
40func WithHeaders(headers map[string]string) Option {
41 return func(o *options) {
42 o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHeaders(headers))
43 }
44}
45
46// WithHTTPClient sets the HTTP client for the Bedrock provider.
47func WithHTTPClient(client option.HTTPClient) Option {
48 return func(o *options) {
49 o.anthropicOptions = append(o.anthropicOptions, anthropic.WithHTTPClient(client))
50 }
51}
52
53// WithSkipAuth configures whether to skip authentication for the Bedrock provider.
54func WithSkipAuth(skipAuth bool) Option {
55 return func(o *options) {
56 o.skipAuth = skipAuth
57 }
58}