Skip to content

Commit 6b0f26e

Browse files
authored
Chenxizhang/issue283 (#284)
2 parents 58dd2e0 + 270614d commit 6b0f26e

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
| Date | Version | Description |
55
|------------|----------|-----------------------------------------------------------------------------|
6+
| 2025-08-08 | v4.0.0.7 | Bug fixes! [#283](https://github.com/chenxizhang/openai-powershell/issues/283) |
67
| 2025-01-05 | v4.0.0.6 | Bug fixes! [#279](https://github.com/chenxizhang/openai-powershell/issues/279) |
78
| 2024-09-02 | v4.0.0.5 | Bug fixes! [#275](https://github.com/chenxizhang/openai-powershell/issues/275) |
89
| 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) |

code365scripts.openai/Public/New-ChatCompletions.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,22 @@ function New-ChatCompletions {
195195
if(-not $endpoint.EndsWith("/")) {
196196
$endpoint += "/"
197197
}
198-
199-
if ($endpoint.EndsWith("openai.azure.com/")) {
198+
199+
$azure = $endpoint.Contains("azure.com")
200+
if ($azure) {
200201
$version = Get-AzureAPIVersion
202+
203+
if (-not $endpoint.EndsWith("/")) {
204+
$endpoint += "/"
205+
}
201206
$endpoint += "openai/deployments/$model/chat/completions?api-version=$version"
202207
}
203208
else {
204209
$endpoint += "chat/completions"
205210
}
206211

207212
# add databricks support, it will use the basic authorization method, not the bearer token
208-
$azure = $endpoint.Contains("openai.azure.com")
213+
209214

210215
$header = if ($azure) {
211216
# if the apikey is a jwt, then use the bearer token in authorization header

code365scripts.openai/Public/New-ChatGPTConversation.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,20 @@ function New-ChatGPTConversation {
246246
$baseUrl = $baseUrl + "/"
247247
}
248248
# if endpoint contains ".openai.azure.com", then people wants to use azure openai service, try to concat the endpoint with the model
249-
if ($baseUrl.EndsWith("openai.azure.com/")) {
249+
$azure = $endpoint.Contains("azure.com")
250+
if ($azure) {
250251
$version = Get-AzureAPIVersion
251-
$chatEndpoint = "$($baseUrl)openai/deployments/$model/chat/completions?api-version=$version"
252+
253+
if (-not $endpoint.EndsWith("/")) {
254+
$endpoint += "/"
255+
}
256+
$endpoint += "openai/deployments/$model/chat/completions?api-version=$version"
252257
}
253-
else{
254-
$chatEndpoint = $baseUrl + "chat/completions"
258+
else {
259+
$endpoint += "chat/completions"
255260
}
256261

257-
# add databricks support, it will use the basic authorization method, not the bearer token
258-
$azure = $chatEndpoint.Contains("openai.azure.com")
262+
Write-Verbose ($resources.verbose_chat_endpoint -f $endpoint)
259263

260264
$header = if ($azure) {
261265
# if the apikey is a jwt, then use the bearer token in authorization header
@@ -272,7 +276,7 @@ function New-ChatGPTConversation {
272276
}
273277

274278
$type = switch ($endpoint) {
275-
{ $_ -match "openai.azure.com" } { "azure" }
279+
{ $_ -match "azure.com" } { "azure" }
276280
{ $_ -match "localhost" } { "local" }
277281
{ $_ -match "databricks-dbrx" } { "dbrx" }
278282
{ $_ -match "api.openai.com" } { "openai" }
@@ -512,7 +516,7 @@ function New-ChatGPTConversation {
512516

513517
$body = @{model = "$model"; messages = $messages; stream = $stream }
514518
$params = @{
515-
Uri = $chatEndpoint
519+
Uri = $endpoint
516520
Method = "POST"
517521
Headers = $header
518522
}
@@ -706,7 +710,7 @@ function New-ChatGPTConversation {
706710
}
707711
}
708712
catch {
709-
Write-Error ($_.Exception.Message)
713+
Write-Error $.ErrorDetails
710714
}
711715
}
712716
}

code365scripts.openai/code365scripts.openai.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '.\code365scripts.openai.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '4.0.0.6'
15+
ModuleVersion = '4.0.0.7'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @("Desktop", "Core")

0 commit comments

Comments
 (0)