Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
24 changes: 16 additions & 8 deletions code365scripts.openai/Public/New-ChatCompletions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions code365scripts.openai/Public/New-ChatGPTConversation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion code365scripts.openai/code365scripts.openai.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down