Skip to content

Commit 915e541

Browse files
committed
fix: update API endpoint handling and improve error reporting in ChatGPT functions
1 parent 3232583 commit 915e541

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

code365scripts.openai/Public/New-ChatCompletions.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,16 @@ function New-ChatCompletions {
156156
$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/" }
159+
"ollama" { "http://localhost:11434/v1/" }
160+
"foundry" {"http://localhost:5273/v1/"}
161+
"docker" {"http://localhost:12434/v1/"}
160162
"kimi" { "https://api.moonshot.cn/v1/" }
161163
"zhipu" { "https://open.bigmodel.cn/api/paas/v4/" }
162164
default { $endpoint }
163165
}
164166

165167
# if use local model, and api_key is not specify, then generate a random key
166-
if ($endpoint -eq "http://localhost:11434/v1/" -and !$api_key) {
168+
if (($endpoint -match "localhost") -and !$api_key) {
167169
$api_key = "local"
168170
}
169171

code365scripts.openai/Public/New-ChatGPTConversation.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,16 @@ function New-ChatGPTConversation {
208208
$endpoint = ($endpoint, [System.Environment]::GetEnvironmentVariable("OPENAI_API_ENDPOINT"), "https://api.openai.com/v1/" | Where-Object { $_.Length -gt 0 } | Select-Object -First 1)
209209

210210
$endpoint = switch ($endpoint) {
211-
{ $_ -in ("ollama", "local") } { "http://localhost:11434/v1/" }
211+
"ollama" { "http://localhost:11434/v1/" }
212+
"foundry" {"http://localhost:5273/v1/"}
213+
"docker" {"http://localhost:12434/v1/"}
212214
"kimi" { "https://api.moonshot.cn/v1/" }
213215
"zhipu" { "https://open.bigmodel.cn/api/paas/v4/" }
214216
default { $endpoint }
215217
}
216218

217219
# if use local model, and api_key is not specify, then generate a random key
218-
if ($endpoint -eq "http://localhost:11434/v1/" -and !$api_key) {
220+
if (($endpoint -match "localhost") -and !$api_key) {
219221
$api_key = "local"
220222
}
221223

@@ -710,7 +712,7 @@ function New-ChatGPTConversation {
710712
}
711713
}
712714
catch {
713-
Write-Error $.ErrorDetails
715+
Write-Error $_.Exception.Message
714716
}
715717
}
716718
}

code365scripts.openai/code365scripts.openai.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '.\code365scripts.openai.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '4.0.0.9'
15+
ModuleVersion = '4.0.0.10'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @("Desktop", "Core")

0 commit comments

Comments
 (0)