1package azure
2
3import (
4 "charm.land/fantasy"
5 "charm.land/fantasy/openaicompat"
6 "github.com/openai/openai-go/v2/azure"
7 "github.com/openai/openai-go/v2/option"
8)
9
10type options struct {
11 baseURL string
12 apiKey string
13 apiVersion string
14
15 openaiOptions []openaicompat.Option
16}
17
18const (
19 Name = "azure"
20 defaultAPIVersion = "2025-01-01-preview"
21)
22
23type Option = func(*options)
24
25func New(opts ...Option) fantasy.Provider {
26 o := options{
27 apiVersion: defaultAPIVersion,
28 }
29 for _, opt := range opts {
30 opt(&o)
31 }
32 return openaicompat.New(
33 append(
34 o.openaiOptions,
35 openaicompat.WithName(Name),
36 openaicompat.WithSDKOptions(
37 azure.WithEndpoint(o.baseURL, o.apiVersion),
38 azure.WithAPIKey(o.apiKey),
39 ),
40 )...,
41 )
42}
43
44func WithBaseURL(baseURL string) Option {
45 return func(o *options) {
46 o.baseURL = baseURL
47 }
48}
49
50func WithAPIKey(apiKey string) Option {
51 return func(o *options) {
52 o.apiKey = apiKey
53 }
54}
55
56func WithHeaders(headers map[string]string) Option {
57 return func(o *options) {
58 o.openaiOptions = append(o.openaiOptions, openaicompat.WithHeaders(headers))
59 }
60}
61
62func WithAPIVersion(version string) Option {
63 return func(o *options) {
64 o.apiVersion = version
65 }
66}
67
68func WithHTTPClient(client option.HTTPClient) Option {
69 return func(o *options) {
70 o.openaiOptions = append(o.openaiOptions, openaicompat.WithHTTPClient(client))
71 }
72}