From 9c8c544c0d65e3993e8e4216dfc23814a72c522f Mon Sep 17 00:00:00 2001 From: chenxizhang Date: Fri, 8 Aug 2025 10:31:07 +0800 Subject: [PATCH 1/2] fix the endpoint format for azure openai service to support the new format Fixes #283 --- .../Public/New-ChatCompletions.ps1 | 11 +++++++--- .../Public/New-ChatGPTConversation.ps1 | 22 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/code365scripts.openai/Public/New-ChatCompletions.ps1 b/code365scripts.openai/Public/New-ChatCompletions.ps1 index 6c85f39..f01473e 100644 --- a/code365scripts.openai/Public/New-ChatCompletions.ps1 +++ b/code365scripts.openai/Public/New-ChatCompletions.ps1 @@ -195,9 +195,14 @@ function New-ChatCompletions { if(-not $endpoint.EndsWith("/")) { $endpoint += "/" } - - if ($endpoint.EndsWith("openai.azure.com/")) { + + $azure = $endpoint.Contains("azure.com") + if ($azure) { $version = Get-AzureAPIVersion + + if (-not $endpoint.EndsWith("/")) { + $endpoint += "/" + } $endpoint += "openai/deployments/$model/chat/completions?api-version=$version" } else { @@ -205,7 +210,7 @@ function New-ChatCompletions { } # add databricks support, it will use the basic authorization method, not the bearer token - $azure = $endpoint.Contains("openai.azure.com") + $header = if ($azure) { # if the apikey is a jwt, then use the bearer token in authorization header diff --git a/code365scripts.openai/Public/New-ChatGPTConversation.ps1 b/code365scripts.openai/Public/New-ChatGPTConversation.ps1 index 5cea828..770490e 100644 --- a/code365scripts.openai/Public/New-ChatGPTConversation.ps1 +++ b/code365scripts.openai/Public/New-ChatGPTConversation.ps1 @@ -246,16 +246,20 @@ function New-ChatGPTConversation { $baseUrl = $baseUrl + "/" } # if endpoint contains ".openai.azure.com", then people wants to use azure openai service, try to concat the endpoint with the model - if ($baseUrl.EndsWith("openai.azure.com/")) { + $azure = $endpoint.Contains("azure.com") + if ($azure) { $version = Get-AzureAPIVersion - $chatEndpoint = "$($baseUrl)openai/deployments/$model/chat/completions?api-version=$version" + + if (-not $endpoint.EndsWith("/")) { + $endpoint += "/" + } + $endpoint += "openai/deployments/$model/chat/completions?api-version=$version" } - else{ - $chatEndpoint = $baseUrl + "chat/completions" + else { + $endpoint += "chat/completions" } - # add databricks support, it will use the basic authorization method, not the bearer token - $azure = $chatEndpoint.Contains("openai.azure.com") + Write-Verbose ($resources.verbose_chat_endpoint -f $endpoint) $header = if ($azure) { # if the apikey is a jwt, then use the bearer token in authorization header @@ -272,7 +276,7 @@ function New-ChatGPTConversation { } $type = switch ($endpoint) { - { $_ -match "openai.azure.com" } { "azure" } + { $_ -match "azure.com" } { "azure" } { $_ -match "localhost" } { "local" } { $_ -match "databricks-dbrx" } { "dbrx" } { $_ -match "api.openai.com" } { "openai" } @@ -512,7 +516,7 @@ function New-ChatGPTConversation { $body = @{model = "$model"; messages = $messages; stream = $stream } $params = @{ - Uri = $chatEndpoint + Uri = $endpoint Method = "POST" Headers = $header } @@ -706,7 +710,7 @@ function New-ChatGPTConversation { } } catch { - Write-Error ($_.Exception.Message) + Write-Error $.ErrorDetails } } } From 270614dc97c1df9d620e8a8f9079f33abfdd8741 Mon Sep 17 00:00:00 2001 From: chenxizhang Date: Fri, 8 Aug 2025 10:32:33 +0800 Subject: [PATCH 2/2] update module version to 4.0.0.7 in the module manifest --- CHANGELOG.md | 1 + code365scripts.openai/code365scripts.openai.psd1 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df51fc2..7c815ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ | Date | Version | Description | |------------|----------|-----------------------------------------------------------------------------| +| 2025-08-08 | v4.0.0.7 | Bug fixes! [#283](https://github.com/chenxizhang/openai-powershell/issues/283) | | 2025-01-05 | v4.0.0.6 | Bug fixes! [#279](https://github.com/chenxizhang/openai-powershell/issues/279) | | 2024-09-02 | v4.0.0.5 | Bug fixes! [#275](https://github.com/chenxizhang/openai-powershell/issues/275) | | 2024-09-01 | v4.0.0.4 | Bug fixes! [#271](https://github.com/chenxizhang/openai-powershell/issues/271) [#272](https://github.com/chenxizhang/openai-powershell/issues/272) | diff --git a/code365scripts.openai/code365scripts.openai.psd1 b/code365scripts.openai/code365scripts.openai.psd1 index 5b13d82..ec1d516 100644 --- a/code365scripts.openai/code365scripts.openai.psd1 +++ b/code365scripts.openai/code365scripts.openai.psd1 @@ -12,7 +12,7 @@ RootModule = '.\code365scripts.openai.psm1' # Version number of this module. - ModuleVersion = '4.0.0.6' + ModuleVersion = '4.0.0.7' # Supported PSEditions CompatiblePSEditions = @("Desktop", "Core")