@@ -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