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