From e4e0c903195a73f14009c99d8a63db798922bfb4 Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Wed, 17 Sep 2025 10:59:07 -0500 Subject: [PATCH] feat: Allow Azure AD API version to be configured --- config.go | 2 +- internal/openai/openai.go | 11 ++++++++++- mods.go | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 9f0abfe2..f69c6967 100644 --- a/config.go +++ b/config.go @@ -93,7 +93,7 @@ type API struct { APIKey string `yaml:"api-key"` APIKeyEnv string `yaml:"api-key-env"` APIKeyCmd string `yaml:"api-key-cmd"` - Version string `yaml:"version"` // XXX: not used anywhere + Version string `yaml:"version"` // Used by azure-ad BaseURL string `yaml:"base-url"` Models map[string]Model `yaml:"models"` User string `yaml:"user"` diff --git a/internal/openai/openai.go b/internal/openai/openai.go index 47c498af..0fbfdfbe 100644 --- a/internal/openai/openai.go +++ b/internal/openai/openai.go @@ -30,6 +30,15 @@ type Config struct { Do(*http.Request) (*http.Response, error) } APIType string + Version string +} + +// getVersion returns the API version to be used for azure-ad. +func (c Config) getVersion() string { + if c.Version != "" { + return c.Version + } + return "v1" } // DefaultConfig returns the default configuration for the OpenAI API client. @@ -50,7 +59,7 @@ func New(config Config) *Client { if config.APIType == "azure-ad" { opts = append(opts, azure.WithAPIKey(config.AuthToken)) if config.BaseURL != "" { - opts = append(opts, azure.WithEndpoint(config.BaseURL, "v1")) + opts = append(opts, azure.WithEndpoint(config.BaseURL, config.getVersion())) } } else { opts = append(opts, option.WithAPIKey(config.AuthToken)) diff --git a/mods.go b/mods.go index d43f4597..39f665e0 100644 --- a/mods.go +++ b/mods.go @@ -353,6 +353,7 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd { } if mod.API == "azure-ad" { ccfg.APIType = "azure-ad" + ccfg.Version = api.Version } if api.User != "" { cfg.User = api.User