Skip to content

Commit 9c8c544

Browse files
committed
fix the endpoint format for azure openai service to support the new format
Fixes #283
1 parent 58dd2e0 commit 9c8c544

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

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
}

0 commit comments

Comments
 (0)