1package provider
2
3import (
4 "github.com/charmbracelet/crush/internal/log"
5 "github.com/openai/openai-go"
6 "github.com/openai/openai-go/azure"
7 "github.com/openai/openai-go/option"
8)
9
10type azureClient struct {
11 *openaiClient
12}
13
14type AzureClient ProviderClient
15
16func newAzureClient(opts providerClientOptions) AzureClient {
17 apiVersion := opts.extraParams["apiVersion"]
18 if apiVersion == "" {
19 apiVersion = "2025-01-01-preview"
20 }
21
22 reqOpts := []option.RequestOption{
23 azure.WithEndpoint(opts.baseURL, apiVersion),
24 }
25
26 if opts.cfg.Options.Debug {
27 httpClient := log.NewHTTPClient()
28 reqOpts = append(reqOpts, option.WithHTTPClient(httpClient))
29 }
30
31 reqOpts = append(reqOpts, azure.WithAPIKey(opts.apiKey))
32 base := &openaiClient{
33 providerOptions: opts,
34 client: openai.NewClient(reqOpts...),
35 }
36
37 return &azureClient{openaiClient: base}
38}