From 9b57c3322c6c9c360acb46da62213b6df9cc2cbb Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 11 Aug 2024 10:46:59 -0400 Subject: [PATCH] fixes https://github.com/dfinke/PSAI/issues/23 --- PSAI.psd1 | 2 +- Public/New-OAIThread.ps1 | 21 ++++++++++++++----- changelog.md | 5 +++++ .../06-ChatWithDocs/PSChatDocs.ps1 | 14 +++++++++++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/PSAI.psd1 b/PSAI.psd1 index ee0ea5a..36cde38 100644 --- a/PSAI.psd1 +++ b/PSAI.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSAI.psm1' - ModuleVersion = '0.2.7' + ModuleVersion = '0.2.8' GUID = '68662d19-a8f1-484f-b1b7-3bf0e8a436df' Author = 'Douglas Finke' CompanyName = 'Doug Finke' diff --git a/Public/New-OAIThread.ps1 b/Public/New-OAIThread.ps1 index c016fd8..1410a1f 100644 --- a/Public/New-OAIThread.ps1 +++ b/Public/New-OAIThread.ps1 @@ -49,11 +49,22 @@ function New-OAIThread { $url = $baseUrl + '/threads' $Method = 'Post' - $body = (Get-OAIProvider) -eq 'OpenAI' ? @{ - messages = $Messages - tool_resources = $ToolResources - metadata = $Metadata - } : '' + # $body = (Get-OAIProvider) -eq 'OpenAI' ? @{ + # messages = $Messages + # tool_resources = $ToolResources + # metadata = $Metadata + # } : '' + + if ((Get-OAIProvider) -eq 'OpenAI') { + $body = @{ + messages = $Messages + tool_resources = $ToolResources + metadata = $Metadata + } + } + else { + $body = '' + } Invoke-OAIBeta -Uri $url -Method $Method -Body $body } diff --git a/changelog.md b/changelog.md index e549f17..021411c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +## v0.2.8 + +- For users on an older version of PowerShell + - Don't use ternary the operator or parallel processing + ## v0.2.7 - Added new OpenAI model diff --git a/examples/quickstarts/06-ChatWithDocs/PSChatDocs.ps1 b/examples/quickstarts/06-ChatWithDocs/PSChatDocs.ps1 index 1c0dbf5..d1b95d9 100644 --- a/examples/quickstarts/06-ChatWithDocs/PSChatDocs.ps1 +++ b/examples/quickstarts/06-ChatWithDocs/PSChatDocs.ps1 @@ -7,10 +7,20 @@ function PSChatDocs { ) Write-Host "Uploading files..." -ForegroundColor Cyan - $files = Get-ChildItem $Path | ForEach-Object -Parallel { - Invoke-OAIUploadFile -Path $_.FullName + + if ($PSVersionTable.PSVersion.Major -lt 7) { + # slower sequential upload + # use a newer version of PowerShell for parallel processing + $files = Get-ChildItem $Path | ForEach-Object { + Invoke-OAIUploadFile -Path $_.FullName + } + } else { + $files = Get-ChildItem $Path | ForEach-Object -Parallel { + Invoke-OAIUploadFile -Path $_.FullName + } } + Write-Host "Creating Assistant..." -ForegroundColor Cyan $ToolResources = @{ file_search = @{