diff --git a/util.go b/util.go index d634868..05cee9a 100644 --- a/util.go +++ b/util.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/cli/go-gh/v2/pkg/api" "github.com/joho/godotenv" @@ -118,7 +119,12 @@ func getChatCompletionResponse(messages []azopenai.ChatMessage) (string, error) var client *azopenai.Client if strings.Contains(url, "azure") { - client, err = azopenai.NewClientWithKeyCredential(url, keyCredential, nil) + clientOptions := &azopenai.ClientOptions{ + ClientOptions: policy.ClientOptions{ + APIVersion: "2024-12-01-preview", + }, + } + client, err = azopenai.NewClientWithKeyCredential(url, keyCredential, clientOptions) if err != nil { return "", fmt.Errorf("error creating Azure OpenAI client: %v", err) } diff --git a/util_test.go b/util_test.go index ad38973..df2ecc8 100644 --- a/util_test.go +++ b/util_test.go @@ -4,6 +4,7 @@ import ( "reflect" "testing" "github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" ) func Test_getGitDiff(t *testing.T) { @@ -188,3 +189,18 @@ func Test_formatResponse(t *testing.T) { }) } } + +func Test_azureClientOptionsSetAPIVersion(t *testing.T) { + // Test that Azure client creation includes proper API version + // This test verifies the fix for o4-mini model compatibility + clientOptions := &azopenai.ClientOptions{ + ClientOptions: policy.ClientOptions{ + APIVersion: "2024-12-01-preview", + }, + } + + // Verify the API version is set correctly + if clientOptions.ClientOptions.APIVersion != "2024-12-01-preview" { + t.Errorf("Expected API version to be '2024-12-01-preview', got '%s'", clientOptions.ClientOptions.APIVersion) + } +}