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-08-08 | v4.0.0.7 | Bug fixes! [#283](https://github.com/chenxizhang/openai-powershell/issues/283) |
| 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) |
Expand Down
11 changes: 8 additions & 3 deletions code365scripts.openai/Public/New-ChatCompletions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,22 @@ function New-ChatCompletions {
if(-not $endpoint.EndsWith("/")) {
$endpoint += "/"
}

if ($endpoint.EndsWith("openai.azure.com/")) {

$azure = $endpoint.Contains("azure.com")
if ($azure) {
$version = Get-AzureAPIVersion

if (-not $endpoint.EndsWith("/")) {
$endpoint += "/"
}
$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")


$header = if ($azure) {
# if the apikey is a jwt, then use the bearer token in authorization header
Expand Down
22 changes: 13 additions & 9 deletions code365scripts.openai/Public/New-ChatGPTConversation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,20 @@ function New-ChatGPTConversation {
$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/")) {
$azure = $endpoint.Contains("azure.com")
if ($azure) {
$version = Get-AzureAPIVersion
$chatEndpoint = "$($baseUrl)openai/deployments/$model/chat/completions?api-version=$version"

if (-not $endpoint.EndsWith("/")) {
$endpoint += "/"
}
$endpoint += "openai/deployments/$model/chat/completions?api-version=$version"
}
else{
$chatEndpoint = $baseUrl + "chat/completions"
else {
$endpoint += "chat/completions"
}

# add databricks support, it will use the basic authorization method, not the bearer token
$azure = $chatEndpoint.Contains("openai.azure.com")
Write-Verbose ($resources.verbose_chat_endpoint -f $endpoint)

$header = if ($azure) {
# if the apikey is a jwt, then use the bearer token in authorization header
Expand All @@ -272,7 +276,7 @@ function New-ChatGPTConversation {
}

$type = switch ($endpoint) {
{ $_ -match "openai.azure.com" } { "azure" }
{ $_ -match "azure.com" } { "azure" }
{ $_ -match "localhost" } { "local" }
{ $_ -match "databricks-dbrx" } { "dbrx" }
{ $_ -match "api.openai.com" } { "openai" }
Expand Down Expand Up @@ -512,7 +516,7 @@ function New-ChatGPTConversation {

$body = @{model = "$model"; messages = $messages; stream = $stream }
$params = @{
Uri = $chatEndpoint
Uri = $endpoint
Method = "POST"
Headers = $header
}
Expand Down Expand Up @@ -706,7 +710,7 @@ function New-ChatGPTConversation {
}
}
catch {
Write-Error ($_.Exception.Message)
Write-Error $.ErrorDetails
}
}
}
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.6'
ModuleVersion = '4.0.0.7'

# Supported PSEditions
CompatiblePSEditions = @("Desktop", "Core")
Expand Down