diff --git a/CHANGELOG.md b/CHANGELOG.md index 748b3eb..df51fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ | Date | Version | Description | |------------|----------|-----------------------------------------------------------------------------| +| 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) | | 2024-08-07 | v4.0.0.3 | Bug fixes! [#265](https://github.com/chenxizhang/openai-powershell/issues/265) | diff --git a/code365scripts.openai/Public/New-ChatCompletions.ps1 b/code365scripts.openai/Public/New-ChatCompletions.ps1 index 97e0a35..6c85f39 100644 --- a/code365scripts.openai/Public/New-ChatCompletions.ps1 +++ b/code365scripts.openai/Public/New-ChatCompletions.ps1 @@ -132,7 +132,7 @@ function New-ChatCompletions { Confirm-DependencyModule -ModuleName "MSAL.ps" $aad = $parsed_env_config.auth.aad - if($aad.clientsecret){ + if ($aad.clientsecret) { $aad.clientsecret = ConvertTo-SecureString $aad.clientsecret -AsPlainText -Force } $accesstoken = (Get-MsalToken @aad).AccessToken @@ -153,17 +153,17 @@ function New-ChatCompletions { $api_key = ($api_key, [System.Environment]::GetEnvironmentVariable("OPENAI_API_KEY") | Where-Object { $_.Length -gt 0 } | Select-Object -First 1) $model = ($model, [System.Environment]::GetEnvironmentVariable("OPENAI_API_MODEL"), "gpt-3.5-turbo" | Where-Object { $_.Length -gt 0 } | Select-Object -First 1) - $endpoint = ($endpoint, [System.Environment]::GetEnvironmentVariable("OPENAI_API_ENDPOINT"), "https://api.openai.com/v1/chat/completions" | Where-Object { $_.Length -gt 0 } | Select-Object -First 1) + $endpoint = ($endpoint, [System.Environment]::GetEnvironmentVariable("OPENAI_API_ENDPOINT"), "https://api.openai.com/v1/" | Where-Object { $_.Length -gt 0 } | Select-Object -First 1) $endpoint = switch ($endpoint) { - { $_ -in ("ollama", "local") } { "http://localhost:11434/v1/chat/completions" } - "kimi" { "https://api.moonshot.cn/v1/chat/completions" } - "zhipu" { "https://open.bigmodel.cn/api/paas/v4/chat/completions" } + { $_ -in ("ollama", "local") } { "http://localhost:11434/v1/" } + "kimi" { "https://api.moonshot.cn/v1/" } + "zhipu" { "https://open.bigmodel.cn/api/paas/v4/" } default { $endpoint } } # if use local model, and api_key is not specify, then generate a random key - if ($endpoint -eq "http://localhost:11434/v1/chat/completions" -and !$api_key) { + if ($endpoint -eq "http://localhost:11434/v1/" -and !$api_key) { $api_key = "local" } @@ -191,10 +191,18 @@ function New-ChatCompletions { } # if endpoint contains ".openai.azure.com", then people wants to use azure openai service, try to concat the endpoint with the model + + if(-not $endpoint.EndsWith("/")) { + $endpoint += "/" + } + if ($endpoint.EndsWith("openai.azure.com/")) { $version = Get-AzureAPIVersion $endpoint += "openai/deployments/$model/chat/completions?api-version=$version" } + else { + $endpoint += "chat/completions" + } # add databricks support, it will use the basic authorization method, not the bearer token $azure = $endpoint.Contains("openai.azure.com") @@ -348,11 +356,11 @@ function New-ChatCompletions { Write-Verbose ($resources.verbose_outfile_specified -f $outFile) $result | Out-File -FilePath $outFile -Encoding utf8 - if($passthru){ + if ($passthru) { Write-Output $result } } - else{ + else { # support passthru, even though user specify the outfile, we still return the result to the pipeline Write-Output $result } diff --git a/code365scripts.openai/Public/New-ChatGPTConversation.ps1 b/code365scripts.openai/Public/New-ChatGPTConversation.ps1 index 1a85657..5cea828 100644 --- a/code365scripts.openai/Public/New-ChatGPTConversation.ps1 +++ b/code365scripts.openai/Public/New-ChatGPTConversation.ps1 @@ -242,13 +242,17 @@ function New-ChatGPTConversation { } $baseUrl = $endpoint - $chatEndpoint = $baseUrl + "chat/completions" - + if(-not $baseUrl.EndsWith("/")) { + $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/")) { $version = Get-AzureAPIVersion $chatEndpoint = "$($baseUrl)openai/deployments/$model/chat/completions?api-version=$version" } + else{ + $chatEndpoint = $baseUrl + "chat/completions" + } # add databricks support, it will use the basic authorization method, not the bearer token $azure = $chatEndpoint.Contains("openai.azure.com") diff --git a/code365scripts.openai/code365scripts.openai.psd1 b/code365scripts.openai/code365scripts.openai.psd1 index 668f0c2..5b13d82 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.5' + ModuleVersion = '4.0.0.6' # Supported PSEditions CompatiblePSEditions = @("Desktop", "Core")