@@ -132,7 +132,7 @@ function New-ChatCompletions {
132132 Confirm-DependencyModule - ModuleName " MSAL.ps"
133133
134134 $aad = $parsed_env_config.auth.aad
135- if ($aad.clientsecret ){
135+ if ($aad.clientsecret ) {
136136 $aad.clientsecret = ConvertTo-SecureString $aad.clientsecret - AsPlainText - Force
137137 }
138138 $accesstoken = (Get-MsalToken @aad ).AccessToken
@@ -153,17 +153,17 @@ function New-ChatCompletions {
153153
154154 $api_key = ($api_key , [System.Environment ]::GetEnvironmentVariable(" OPENAI_API_KEY" ) | Where-Object { $_.Length -gt 0 } | Select-Object - First 1 )
155155 $model = ($model , [System.Environment ]::GetEnvironmentVariable(" OPENAI_API_MODEL" ), " gpt-3.5-turbo" | Where-Object { $_.Length -gt 0 } | Select-Object - First 1 )
156- $endpoint = ($endpoint , [System.Environment ]::GetEnvironmentVariable(" OPENAI_API_ENDPOINT" ), " https://api.openai.com/v1/chat/completions " | Where-Object { $_.Length -gt 0 } | Select-Object - First 1 )
156+ $endpoint = ($endpoint , [System.Environment ]::GetEnvironmentVariable(" OPENAI_API_ENDPOINT" ), " https://api.openai.com/v1/" | Where-Object { $_.Length -gt 0 } | Select-Object - First 1 )
157157
158158 $endpoint = switch ($endpoint ) {
159- { $_ -in (" ollama" , " local" ) } { " http://localhost:11434/v1/chat/completions " }
160- " kimi" { " https://api.moonshot.cn/v1/chat/completions " }
161- " zhipu" { " https://open.bigmodel.cn/api/paas/v4/chat/completions " }
159+ { $_ -in (" ollama" , " local" ) } { " http://localhost:11434/v1/" }
160+ " kimi" { " https://api.moonshot.cn/v1/" }
161+ " zhipu" { " https://open.bigmodel.cn/api/paas/v4/" }
162162 default { $endpoint }
163163 }
164164
165165 # if use local model, and api_key is not specify, then generate a random key
166- if ($endpoint -eq " http://localhost:11434/v1/chat/completions " -and ! $api_key ) {
166+ if ($endpoint -eq " http://localhost:11434/v1/" -and ! $api_key ) {
167167 $api_key = " local"
168168 }
169169
@@ -191,10 +191,18 @@ function New-ChatCompletions {
191191 }
192192
193193 # if endpoint contains ".openai.azure.com", then people wants to use azure openai service, try to concat the endpoint with the model
194+
195+ if (-not $endpoint.EndsWith (" /" )) {
196+ $endpoint += " /"
197+ }
198+
194199 if ($endpoint.EndsWith (" openai.azure.com/" )) {
195200 $version = Get-AzureAPIVersion
196201 $endpoint += " openai/deployments/$model /chat/completions?api-version=$version "
197202 }
203+ else {
204+ $endpoint += " chat/completions"
205+ }
198206
199207 # add databricks support, it will use the basic authorization method, not the bearer token
200208 $azure = $endpoint.Contains (" openai.azure.com" )
@@ -348,11 +356,11 @@ function New-ChatCompletions {
348356 Write-Verbose ($resources.verbose_outfile_specified -f $outFile )
349357 $result | Out-File - FilePath $outFile - Encoding utf8
350358
351- if ($passthru ){
359+ if ($passthru ) {
352360 Write-Output $result
353361 }
354362 }
355- else {
363+ else {
356364 # support passthru, even though user specify the outfile, we still return the result to the pipeline
357365 Write-Output $result
358366 }
0 commit comments