From 017c7ee7a723d3bb5a4b536bb3b612fb2f9bb0aa Mon Sep 17 00:00:00 2001 From: mkht Date: Sun, 21 Apr 2024 20:52:43 +0900 Subject: [PATCH] Code format --- PSOpenAI.psm1 | 6 +-- Private/Azure/Get-AzureOpenAIAPIEndpoint.ps1 | 1 + Private/ChatCompletionFunction.ps1 | 12 +++-- Private/Get-CultureInfo.ps1 | 12 ++--- Private/Get-OpenAIAPIEndpoint.ps1 | 1 + Private/Invoke-OpenAIAPIRequest.ps1 | 18 +++---- Private/Invoke-OpenAIAPIRequestSSE.ps1 | 19 +++---- Private/Runs/ParseThreadRunStepObject.ps1 | 2 +- Private/Utils.ps1 | 34 ++++++------- Public/Enter-ChatGPT.ps1 | 4 +- Public/Request-AudioSpeech.ps1 | 2 +- Public/Request-ChatCompletion.ps1 | 52 ++++++++++---------- Public/Request-ImageEdit.ps1 | 2 +- Public/Request-TextCompletion.ps1 | 34 ++++++------- Public/Runs/Start-ThreadRun.ps1 | 52 ++++++++++---------- Public/Runs/Submit-ToolOutput.ps1 | 52 ++++++++++---------- Tests/Threads/Add-ThreadMessage.tests.ps1 | 6 +-- 17 files changed, 155 insertions(+), 154 deletions(-) diff --git a/PSOpenAI.psm1 b/PSOpenAI.psm1 index 2df3ada..7f6ac60 100644 --- a/PSOpenAI.psm1 +++ b/PSOpenAI.psm1 @@ -6,18 +6,18 @@ $PrivateFunctions = Get-ChildItem -LiteralPath $PrivateDirectory -Recurse -Filte $PublicFunctions = Get-ChildItem -LiteralPath $PublicDirectory -Recurse -Filter '*.ps1' -File # Include Private functions -$PrivateFunctions | % { +$PrivateFunctions | ForEach-Object { . $_.FullName } # Include Public functions -$PublicFunctions | % { +$PublicFunctions | ForEach-Object { . $_.FullName } # Export public functions $ExportFunctions = [string[]]@() -$PublicFunctions | % { +$PublicFunctions | ForEach-Object { if (Test-Path -LiteralPath "Function:/$($_.BaseName)") { $ExportFunctions += $_.BaseName } diff --git a/Private/Azure/Get-AzureOpenAIAPIEndpoint.ps1 b/Private/Azure/Get-AzureOpenAIAPIEndpoint.ps1 index 8b34226..b61dc3a 100644 --- a/Private/Azure/Get-AzureOpenAIAPIEndpoint.ps1 +++ b/Private/Azure/Get-AzureOpenAIAPIEndpoint.ps1 @@ -1,5 +1,6 @@ function Get-AzureOpenAIAPIEndpoint { [CmdletBinding()] + [OutputType([hashtable])] param ( [Parameter(Mandatory, Position = 0)] [string]$EndpointName, diff --git a/Private/ChatCompletionFunction.ps1 b/Private/ChatCompletionFunction.ps1 index c4664fb..8fe1cad 100644 --- a/Private/ChatCompletionFunction.ps1 +++ b/Private/ChatCompletionFunction.ps1 @@ -2,6 +2,7 @@ using namespace System.Management.Automation function New-ChatCompletionFunctionFromHashTable { [CmdletBinding()] + [OutputType([ordered])] param ( [Parameter(Mandatory, Position = 0)] [ValidatePattern('^[a-zA-Z0-9_-]{1,64}$')] @@ -37,6 +38,7 @@ function New-ChatCompletionFunctionFromHashTable { function New-ChatCompletionFunctionFromPSCommand { [CmdletBinding()] + [OutputType([ordered])] param ( [Parameter(Mandatory, Position = 0)] [ValidateScript({ (Get-Command $_ -ea Ignore) -is [CommandInfo] })] @@ -76,22 +78,22 @@ function New-ChatCompletionFunctionFromPSCommand { $CommandHelp = Get-Help $CommandInfo -ErrorAction Ignore if ($ParameterSetName) { - $TargetParameterSet = $CommandInfo.ParameterSets | ? { $_.Name -eq $ParameterSetName } + $TargetParameterSet = $CommandInfo.ParameterSets | Where-Object { $_.Name -eq $ParameterSetName } if (-not $TargetParameterSet) { Write-Error "$ParameterSetName does not exist." return } } else { - $TargetParameterSet = $CommandInfo.ParameterSets | ? { $_.IsDefault } + $TargetParameterSet = $CommandInfo.ParameterSets | Where-Object { $_.IsDefault } if (-not $TargetParameterSet) { $TargetParameterSet = $CommandInfo.ParameterSets[0] } } - $TargetParameters = $TargetParameterSet.Parameters | ? { $_.Name -notin $ExcludeParamNames } + $TargetParameters = $TargetParameterSet.Parameters | Where-Object { $_.Name -notin $ExcludeParamNames } if ($IncludeParameters.Count -gt 0) { - $TargetParameters = $TargetParameters | ? { $_.Name -in $IncludeParameters } + $TargetParameters = $TargetParameters | Where-Object { $_.Name -in $IncludeParameters } } $FunctionDefinition.Add('name', $CommandInfo.Name) @@ -116,7 +118,7 @@ function New-ChatCompletionFunctionFromPSCommand { $propHash = ParseParameterType($param.ParameterType) - $helpmsg = (($CommandHelp.parameters.parameter | ? { $_.name -eq $pName }).description.text -join "`n") -replace "`r", '' + $helpmsg = (($CommandHelp.parameters.parameter | Where-Object { $_.name -eq $pName }).description.text -join "`n") -replace "`r", '' if ([string]::IsNullOrWhiteSpace($helpmsg)) { $helpmsg = [string]$param.HelpMessage } diff --git a/Private/Get-CultureInfo.ps1 b/Private/Get-CultureInfo.ps1 index aa3a481..10cb0a7 100644 --- a/Private/Get-CultureInfo.ps1 +++ b/Private/Get-CultureInfo.ps1 @@ -9,12 +9,12 @@ function Get-CultureInfo { $LanguageName = $LanguageName.Trim() [cultureinfo]$CultureInfo = [cultureinfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures) |` Where-Object { - $_.Name -eq $LanguageName ` - -or $_.EnglishName -eq $LanguageName ` - -or $_.DisplayName -eq $LanguageName ` - -or $_.NativeName -eq $LanguageName ` - -or $_.TwoLetterISOLanguageName -eq $LanguageName ` - -or $_.ThreeLetterISOLanguageName -eq $LanguageName + $_.Name -eq $LanguageName -or + $_.EnglishName -eq $LanguageName -or + $_.DisplayName -eq $LanguageName -or + $_.NativeName -eq $LanguageName -or + $_.TwoLetterISOLanguageName -eq $LanguageName -or + $_.ThreeLetterISOLanguageName -eq $LanguageName } | Select-Object -First 1 if ($CultureInfo -is [cultureinfo]) { diff --git a/Private/Get-OpenAIAPIEndpoint.ps1 b/Private/Get-OpenAIAPIEndpoint.ps1 index 0423f30..934d741 100644 --- a/Private/Get-OpenAIAPIEndpoint.ps1 +++ b/Private/Get-OpenAIAPIEndpoint.ps1 @@ -1,5 +1,6 @@ function Get-OpenAIAPIEndpoint { [CmdletBinding()] + [OutputType([hashtable])] param ( [Parameter(Mandatory, Position = 0)] [string]$EndpointName, diff --git a/Private/Invoke-OpenAIAPIRequest.ps1 b/Private/Invoke-OpenAIAPIRequest.ps1 index e6e5605..6588765 100644 --- a/Private/Invoke-OpenAIAPIRequest.ps1 +++ b/Private/Invoke-OpenAIAPIRequest.ps1 @@ -310,15 +310,15 @@ function Invoke-OpenAIAPIRequest { # Verbose / Debug output $verboseMessage = "$ServiceName API response: " + ($Response | - Format-List StatusCode, - @{ - name = 'processing_ms' - expression = { $_.Headers['openai-processing-ms'] } - }, - @{ - name = 'request_id' - expression = { $_.Headers['X-Request-Id'] } - } | Out-String).TrimEnd() + Format-List StatusCode, + @{ + name = 'processing_ms' + expression = { $_.Headers['openai-processing-ms'] } + }, + @{ + name = 'request_id' + expression = { $_.Headers['X-Request-Id'] } + } | Out-String).TrimEnd() Write-Verbose -Message $verboseMessage # Don't read the whole stream for debug logging unless necessary. diff --git a/Private/Invoke-OpenAIAPIRequestSSE.ps1 b/Private/Invoke-OpenAIAPIRequestSSE.ps1 index cf4c093..285f22c 100644 --- a/Private/Invoke-OpenAIAPIRequestSSE.ps1 +++ b/Private/Invoke-OpenAIAPIRequestSSE.ps1 @@ -132,13 +132,11 @@ function Invoke-OpenAIAPIRequestSSE { if ($IsDebug) { $startIdx = $lastIdx = 2 if ($AuthType -eq 'openai') { $startIdx += 4 } # 'org-' - Write-Debug -Message (Get-MaskedString ` - ('Request parameters: ' + ($RequestMessage | fl ` - Method, ` - RequestUri, ` - @{name = 'Headers'; expression = { $_.Headers.ToString() } } ` - | Out-String)).TrimEnd() ` - -Target ($ApiKey, $Organization) -First $startIdx -Last $lastIdx -MaxNumberOfAsterisks 45) + $MaskedMessage = Get-MaskedString ` + ('Request parameters: ' + ($RequestMessage | Format-List Method, RequestUri, @{name = 'Headers'; expression = { $_.Headers.ToString() } } | Out-String)).TrimEnd() ` + -Target ($ApiKey, $Organization) -First $startIdx -Last $lastIdx -MaxNumberOfAsterisks 45 + Write-Debug -Message $MaskedMessage + $MaskedMessage = $null } # Send API Request @@ -182,17 +180,16 @@ function Invoke-OpenAIAPIRequestSSE { # Verbose / Debug output Write-Verbose -Message ('Received HTTP/{0} response of content type {1}' -f $HttpResponse.Version, $HttpResponse.Content.Headers.ContentType.MediaType) - Write-Verbose -Message ("$ServiceName API response: " + ($HttpResponse | fl ` + Write-Verbose -Message ("$ServiceName API response: " + ($HttpResponse | Format-List ` StatusCode, ` @{name = 'processing_ms'; expression = { $_.Headers.GetValues('openai-processing-ms')[0] } }, ` - @{name = 'request_id'; expression = { $_.Headers.GetValues('X-Request-Id')[0] } } ` - | Out-String)).TrimEnd() + @{name = 'request_id'; expression = { $_.Headers.GetValues('X-Request-Id')[0] } } | Out-String)).TrimEnd() # Don't read the whole stream for debug logging unless necessary. if ($IsDebug) { $startIdx = $lastIdx = 2 if ($AuthType -eq 'openai') { $startIdx += 4 } # 'org-' Write-Debug -Message (Get-MaskedString ` - ('API response header: ' + ($HttpResponse.Headers | ft -Hide | Out-String)).TrimEnd() ` + ('API response header: ' + ($HttpResponse.Headers | Format-Table -Hide | Out-String)).TrimEnd() ` -Target ($ApiKey, $Organization) -First $startIdx -Last $lastIdx -MaxNumberOfAsterisks 45) } diff --git a/Private/Runs/ParseThreadRunStepObject.ps1 b/Private/Runs/ParseThreadRunStepObject.ps1 index f0db2bf..3405777 100644 --- a/Private/Runs/ParseThreadRunStepObject.ps1 +++ b/Private/Runs/ParseThreadRunStepObject.ps1 @@ -12,7 +12,7 @@ function ParseThreadRunStepObject { ) $simplecontent = - if ($InputObject.type -eq 'message_creation') { + if ($InputObject.type -eq 'message_creation') { if ($msgid = $InputObject.step_details.message_creation.message_id) { $GetThreadMessageParams = $CommonParams $GetThreadMessageParams.InputObject = $InputObject diff --git a/Private/Utils.ps1 b/Private/Utils.ps1 index 934d1ac..ba8e1a7 100644 --- a/Private/Utils.ps1 +++ b/Private/Utils.ps1 @@ -27,34 +27,34 @@ function ObjectToContent { if ( $null -eq $InputObject -or - $InputObject -eq [System.Management.Automation.Internal.AutomationNull]::Value -or - $InputObject -eq [System.DBNull]::Value -or - $InputObject -eq [NullString]::Value + $InputObject -eq [System.Management.Automation.Internal.AutomationNull]::Value -or + $InputObject -eq [System.DBNull]::Value -or + $InputObject -eq [NullString]::Value ) { $null } elseif ( $InputObject -is [string] -or - $InputObject -is [System.Collections.IDictionary] -or - $InputObject -is [char] -or - $InputObject -is [bool] -or - $InputObject -is [datetime] -or - $InputObject -is [System.DateTimeOffset] -or - $InputObject -is [uri] -or - $InputObject -is [double] -or - $InputObject -is [float] -or - $InputObject -is [decimal] -or - $InputObject -is [double] + $InputObject -is [System.Collections.IDictionary] -or + $InputObject -is [char] -or + $InputObject -is [bool] -or + $InputObject -is [datetime] -or + $InputObject -is [System.DateTimeOffset] -or + $InputObject -is [uri] -or + $InputObject -is [double] -or + $InputObject -is [float] -or + $InputObject -is [decimal] -or + $InputObject -is [double] ) { $InputObject } elseif ( $InputObject -is [timespan] -or - $InputObject -is [guid] -or - $InputObject -is [regex] -or - $InputObject -is [ipaddress] -or - $InputObject -is [mailaddress] + $InputObject -is [guid] -or + $InputObject -is [regex] -or + $InputObject -is [ipaddress] -or + $InputObject -is [mailaddress] ) { $InputObject.ToString() } diff --git a/Public/Enter-ChatGPT.ps1 b/Public/Enter-ChatGPT.ps1 index c54af9b..b90d129 100644 --- a/Public/Enter-ChatGPT.ps1 +++ b/Public/Enter-ChatGPT.ps1 @@ -98,7 +98,7 @@ function Enter-ChatGPT { #region Display header $ConsoleWidth = [Math]::Min(46, ($Host.UI.RawUI.WindowSize.Width - 4)) if (-not $NoHeader) { - (1..$ConsoleWidth) | % { Write-Host '/' -NoNewline } + (1..$ConsoleWidth) | ForEach-Object { Write-Host '/' -NoNewline } Write-Host '' Write-Host @' ________ __ __________ ______ @@ -108,7 +108,7 @@ function Enter-ChatGPT { \____/_/ /_/\__,_/\__/\____/_/ /_/ '@ - (1..$ConsoleWidth) | % { Write-Host '/' -NoNewline } + (1..$ConsoleWidth) | ForEach-Object { Write-Host '/' -NoNewline } Write-Host '' Write-Host '' } diff --git a/Public/Request-AudioSpeech.ps1 b/Public/Request-AudioSpeech.ps1 index 9882ad7..20b5521 100644 --- a/Public/Request-AudioSpeech.ps1 +++ b/Public/Request-AudioSpeech.ps1 @@ -126,7 +126,7 @@ function Request-AudioSpeech { } else { $PostBody.response_format = - switch -Wildcard ($OutFile) { + switch -Wildcard ($OutFile) { '*.mp3' { 'mp3'; break } '*.opus' { 'opus'; break } '*.aac' { 'aac'; break } diff --git a/Public/Request-ChatCompletion.ps1 b/Public/Request-ChatCompletion.ps1 index 9f2c7c9..2f26a93 100644 --- a/Public/Request-ChatCompletion.ps1 +++ b/Public/Request-ChatCompletion.ps1 @@ -413,34 +413,34 @@ function Request-ChatCompletion { } Invoke-OpenAIAPIRequest @splat | Where-Object { - -not [string]::IsNullOrEmpty($_) - } | ForEach-Object { - if ($Format -eq 'raw_response') { - $_ - } - else { - try { - $_ | ConvertFrom-Json -ErrorAction Stop + -not [string]::IsNullOrEmpty($_) + } | ForEach-Object { + if ($Format -eq 'raw_response') { + $_ } - catch { - Write-Error -Exception $_.Exception + else { + try { + $_ | ConvertFrom-Json -ErrorAction Stop + } + catch { + Write-Error -Exception $_.Exception + } + } + } | Where-Object { + $Format -eq 'raw_response' -or ($null -ne $_.choices -and ($_.choices[0].delta.content -is [string])) + } | ForEach-Object -Process { + if ($Format -eq 'raw_response') { + Write-Output $_ + } + else { + # Writes content to both the Information stream(6>) and the Standard output stream(1>). + $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() + $InfoMsg.Message = $_.choices[0].delta.content + $InfoMsg.NoNewLine = $true + Write-Information $InfoMsg + Write-Output $InfoMsg.Message } } - } | Where-Object { - $Format -eq 'raw_response' -or ($null -ne $_.choices -and ($_.choices[0].delta.content -is [string])) - } | ForEach-Object -Process { - if ($Format -eq 'raw_response') { - Write-Output $_ - } - else { - # Writes content to both the Information stream(6>) and the Standard output stream(1>). - $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() - $InfoMsg.Message = $_.choices[0].delta.content - $InfoMsg.NoNewLine = $true - Write-Information $InfoMsg - Write-Output $InfoMsg.Message - } - } return } @@ -580,7 +580,7 @@ function Request-ChatCompletion { } $LastUserMessage = ($Messages.Where({ $_.role -eq 'user' })[-1].content) if ($LastUserMessage -isnot [string]) { - $LastUserMessage = [string]($LastUserMessage | ? { $_.type -eq 'text' } | select -Last 1).text + $LastUserMessage = [string]($LastUserMessage | Where-Object { $_.type -eq 'text' } | Select-Object -Last 1).text } $Response | Add-Member -MemberType NoteProperty -Name 'Message' -Value $LastUserMessage $Response | Add-Member -MemberType NoteProperty -Name 'Answer' -Value ([string[]]$Response.choices.message.content) diff --git a/Public/Request-ImageEdit.ps1 b/Public/Request-ImageEdit.ps1 index 96310ea..b96a99c 100644 --- a/Public/Request-ImageEdit.ps1 +++ b/Public/Request-ImageEdit.ps1 @@ -247,7 +247,7 @@ function Request-ImageEdit { Write-Output ($ResponseContent | Select-Object -ExpandProperty 'b64_json') } elseif ($Format -eq 'byte') { - [byte[]]$b = [Convert]::FromBase64String(($ResponseContent | Select-Object -ExpandProperty 'b64_json' | select -First 1)) + [byte[]]$b = [Convert]::FromBase64String(($ResponseContent | Select-Object -ExpandProperty 'b64_json' | Select-Object -First 1)) Write-Output (, $b) } #endregion diff --git a/Public/Request-TextCompletion.ps1 b/Public/Request-TextCompletion.ps1 index 5d8493e..5344be5 100644 --- a/Public/Request-TextCompletion.ps1 +++ b/Public/Request-TextCompletion.ps1 @@ -215,24 +215,24 @@ function Request-TextCompletion { } Invoke-OpenAIAPIRequest @params | Where-Object { - -not [string]::IsNullOrEmpty($_) - } | ForEach-Object { - try { - $_ | ConvertFrom-Json -ErrorAction Stop + -not [string]::IsNullOrEmpty($_) + } | ForEach-Object { + try { + $_ | ConvertFrom-Json -ErrorAction Stop + } + catch { + Write-Error -Exception $_.Exception + } + } | Where-Object { + $null -ne $_.choices -and $_.choices[0].text -is [string] + } | ForEach-Object { + # Writes content to both the Information stream(6>) and the Standard output stream(1>). + $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() + $InfoMsg.Message = $_.choices[0].text + $InfoMsg.NoNewLine = $true + Write-Information $InfoMsg + Write-Output $InfoMsg.Message } - catch { - Write-Error -Exception $_.Exception - } - } | Where-Object { - $null -ne $_.choices -and $_.choices[0].text -is [string] - } | ForEach-Object { - # Writes content to both the Information stream(6>) and the Standard output stream(1>). - $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() - $InfoMsg.Message = $_.choices[0].text - $InfoMsg.NoNewLine = $true - Write-Information $InfoMsg - Write-Output $InfoMsg.Message - } return } #endregion diff --git a/Public/Runs/Start-ThreadRun.ps1 b/Public/Runs/Start-ThreadRun.ps1 index e79fc2d..7232803 100644 --- a/Public/Runs/Start-ThreadRun.ps1 +++ b/Public/Runs/Start-ThreadRun.ps1 @@ -338,35 +338,35 @@ function Start-ThreadRun { } Invoke-OpenAIAPIRequest @params | Where-Object { - -not [string]::IsNullOrEmpty($_) - } | ForEach-Object { - if ($Format -eq 'raw_response') { - $_ - } - elseif ($_.Contains('"object":"thread.message.delta"', [StringComparison]::OrdinalIgnoreCase)) { - try { - $deltaObj = $_ | ConvertFrom-Json -ErrorAction Stop + -not [string]::IsNullOrEmpty($_) + } | ForEach-Object { + if ($Format -eq 'raw_response') { + $_ } - catch { - Write-Error -Exception $_.Exception + elseif ($_.Contains('"object":"thread.message.delta"', [StringComparison]::OrdinalIgnoreCase)) { + try { + $deltaObj = $_ | ConvertFrom-Json -ErrorAction Stop + } + catch { + Write-Error -Exception $_.Exception + } + @($deltaObj.delta.content.Where({ $_.type -eq 'text' }))[0] + } + } | Where-Object { + $Format -eq 'raw_response' -or ($null -ne $_.text) + } | ForEach-Object -Process { + if ($Format -eq 'raw_response') { + Write-Output $_ + } + else { + # Writes content to both the Information stream(6>) and the Standard output stream(1>). + $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() + $InfoMsg.Message = $_.text.value + $InfoMsg.NoNewLine = $true + Write-Information $InfoMsg + Write-Output $InfoMsg.Message } - @($deltaObj.delta.content.Where({ $_.type -eq 'text' }))[0] - } - } | Where-Object { - $Format -eq 'raw_response' -or ($null -ne $_.text) - } | ForEach-Object -Process { - if ($Format -eq 'raw_response') { - Write-Output $_ - } - else { - # Writes content to both the Information stream(6>) and the Standard output stream(1>). - $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() - $InfoMsg.Message = $_.text.value - $InfoMsg.NoNewLine = $true - Write-Information $InfoMsg - Write-Output $InfoMsg.Message } - } return } diff --git a/Public/Runs/Submit-ToolOutput.ps1 b/Public/Runs/Submit-ToolOutput.ps1 index 6fe9605..14d0f33 100644 --- a/Public/Runs/Submit-ToolOutput.ps1 +++ b/Public/Runs/Submit-ToolOutput.ps1 @@ -140,35 +140,35 @@ function Submit-ToolOutput { } Invoke-OpenAIAPIRequest @params | Where-Object { - -not [string]::IsNullOrEmpty($_) - } | ForEach-Object { - if ($Format -eq 'raw_response') { - $_ - } - elseif ($_.Contains('"object":"thread.message.delta"', [StringComparison]::OrdinalIgnoreCase)) { - try { - $deltaObj = $_ | ConvertFrom-Json -ErrorAction Stop + -not [string]::IsNullOrEmpty($_) + } | ForEach-Object { + if ($Format -eq 'raw_response') { + $_ } - catch { - Write-Error -Exception $_.Exception + elseif ($_.Contains('"object":"thread.message.delta"', [StringComparison]::OrdinalIgnoreCase)) { + try { + $deltaObj = $_ | ConvertFrom-Json -ErrorAction Stop + } + catch { + Write-Error -Exception $_.Exception + } + @($deltaObj.delta.content.Where({ $_.type -eq 'text' }))[0] + } + } | Where-Object { + $Format -eq 'raw_response' -or ($null -ne $_.text) + } | ForEach-Object -Process { + if ($Format -eq 'raw_response') { + Write-Output $_ + } + else { + # Writes content to both the Information stream(6>) and the Standard output stream(1>). + $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() + $InfoMsg.Message = $_.text.value + $InfoMsg.NoNewLine = $true + Write-Information $InfoMsg + Write-Output $InfoMsg.Message } - @($deltaObj.delta.content.Where({ $_.type -eq 'text' }))[0] - } - } | Where-Object { - $Format -eq 'raw_response' -or ($null -ne $_.text) - } | ForEach-Object -Process { - if ($Format -eq 'raw_response') { - Write-Output $_ - } - else { - # Writes content to both the Information stream(6>) and the Standard output stream(1>). - $InfoMsg = [System.Management.Automation.HostInformationMessage]::new() - $InfoMsg.Message = $_.text.value - $InfoMsg.NoNewLine = $true - Write-Information $InfoMsg - Write-Output $InfoMsg.Message } - } return } diff --git a/Tests/Threads/Add-ThreadMessage.tests.ps1 b/Tests/Threads/Add-ThreadMessage.tests.ps1 index fa241f1..da4af5b 100644 --- a/Tests/Threads/Add-ThreadMessage.tests.ps1 +++ b/Tests/Threads/Add-ThreadMessage.tests.ps1 @@ -125,9 +125,9 @@ Describe 'Set-Thread' { It 'Add 3 thread messages' { $thread = New-Thread { $script:Result = $thread |` - Add-ThreadMessage -Message 'Hello.' -PassThru -ea Stop | ` - Add-ThreadMessage -Message ' How' -PassThru -ea Stop | ` - Add-ThreadMessage -Message ' are you?' -PassThru -ea Stop + Add-ThreadMessage -Message 'Hello.' -PassThru -ea Stop | ` + Add-ThreadMessage -Message ' How' -PassThru -ea Stop | ` + Add-ThreadMessage -Message ' are you?' -PassThru -ea Stop } | Should -Not -Throw $Result.id | Should -BeLike 'thread_*' $Result.created_at | Should -BeOfType [datetime]