From 3d0e25431bd915fd9ecfd82ad640fb684f9b55b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20B=C3=B8g=20Andersen?= Date: Sun, 29 Dec 2024 07:38:53 +0100 Subject: [PATCH 1/6] Tool creation added --- Public/New-Agent.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Public/New-Agent.ps1 b/Public/New-Agent.ps1 index 4c88bc9..2510cac 100644 --- a/Public/New-Agent.ps1 +++ b/Public/New-Agent.ps1 @@ -154,13 +154,25 @@ function New-Agent { ) $script:messages = @() + + if ($null -ne $Tools) { + $ReadyTools = @() + foreach ($t in $Tools) { + if ($t.GetType().Name -eq "string") { + $ReadyTools += Register-Tool $t + } + else { + $ReadyTools += $t + } + } + } #Write-Verbose "[$((Get-Date).ToString("yyMMdd:hhmmss"))] New-Agent was called" Write-Verbose ("{0} New-Agent was called" -f (Get-LogDate)) Write-Verbose ("{0} Tools: {1}" -f (Get-LogDate), (ConvertTo-Json -Depth 10 -InputObject $Tools)) $agent = [PSCustomObject]@{ - Tools = $Tools + Tools = $ReadyTools ShowToolCalls = $ShowToolCalls LLM = $LLM } From d1a9359b5678f07ad1b08104a325160ff9ec17eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20B=C3=B8g=20Andersen?= Date: Sun, 29 Dec 2024 07:46:09 +0100 Subject: [PATCH 2/6] Added double to tool properties and updated test --- Private/Get-ToolProperty.ps1 | 2 +- __tests__/Get-ToolProperty.tests.ps1 | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Private/Get-ToolProperty.ps1 b/Private/Get-ToolProperty.ps1 index fffe690..c9499c1 100644 --- a/Private/Get-ToolProperty.ps1 +++ b/Private/Get-ToolProperty.ps1 @@ -39,7 +39,7 @@ function Get-ToolProperty { "System.Object" { $property.Add("type", "object") } "psobject[]" { $property.Add("type", "object"), $property.Add("items", @{type = "object" }) } "System.Object[]" { $property.Add("type", "object"), $property.Add("items", @{type = "object" }) } - { $_ -match 'decimal|float|single|int|long' } { $property.Add("type", "number") } + { $_ -match 'decimal|float|single|int|long|double' } { $property.Add("type", "number") } { $_ -match 'switch|bool|boolean' } { $property.Add("type", "boolean") } default { $property.Add("type", "object") ; Write-Verbose "Unknown type: $_ - added as object" } } diff --git a/__tests__/Get-ToolProperty.tests.ps1 b/__tests__/Get-ToolProperty.tests.ps1 index 609e19c..1400b30 100644 --- a/__tests__/Get-ToolProperty.tests.ps1 +++ b/__tests__/Get-ToolProperty.tests.ps1 @@ -24,7 +24,8 @@ Describe "Get-ToolProperty" -Tag Get-ToolProperty { [switch]$isHappy, [decimal]$money, [float]$float, - [single]$single, + [single]$single, + [double]$double, [bool]$bool, [string[]]$stringArray, [psobject]$targetObject, @@ -52,15 +53,16 @@ Describe "Get-ToolProperty" -Tag Get-ToolProperty { 3 { $properties.type | Should -Be 'number' } 4 { $properties.type | Should -Be 'number' } 5 { $properties.type | Should -Be 'number' } - 6 { $properties.type | Should -Be 'boolean' } - 7 { $properties.type | Should -Be 'array' } - 8 { $properties.type | Should -Be 'object' } + 6 { $properties.type | Should -Be 'number' } + 7 { $properties.type | Should -Be 'boolean' } + 8 { $properties.type | Should -Be 'array' } 9 { $properties.type | Should -Be 'object' } 10 { $properties.type | Should -Be 'object' } - 11 { $properties.type | Should -Be 'number' } - 12 { $properties.type | Should -Be 'string' } - 13 { $properties.type | Should -Be 'object' } + 11 { $properties.type | Should -Be 'object' } + 12 { $properties.type | Should -Be 'number' } + 13 { $properties.type | Should -Be 'string' } 14 { $properties.type | Should -Be 'object' } + 15 { $properties.type | Should -Be 'object' } } } } From dbd9976c120fb38339b818a0d8fa3118463ca2bf Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 29 Dec 2024 20:16:44 -0500 Subject: [PATCH 3/6] Add Invoke-QuickPrompt function and update module imports --- PSAI.psd1 | 2 + PSAI.psm1 | 2 + Public/Invoke-QuickPrompt.ps1 | 77 +++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 Public/Invoke-QuickPrompt.ps1 diff --git a/PSAI.psd1 b/PSAI.psd1 index 1069388..dbb0e4d 100644 --- a/PSAI.psd1 +++ b/PSAI.psd1 @@ -35,6 +35,7 @@ PSAI brings OpenAI ChatGPT to PowerShell, leveraging advanced AI capabilities in 'Get-YouTubeTop10' # Public + 'Invoke-QuickPrompt' 'New-Agent' 'Get-AgentResponse' 'Invoke-InteractiveCLI' @@ -153,6 +154,7 @@ PSAI brings OpenAI ChatGPT to PowerShell, leveraging advanced AI capabilities in 'noait' 'roaia' 'uoaia' + 'q' ) PrivateData = @{ diff --git a/PSAI.psm1 b/PSAI.psm1 index 4bc89c2..9cb7b9b 100644 --- a/PSAI.psm1 +++ b/PSAI.psm1 @@ -14,6 +14,7 @@ Import-Module $PSScriptRoot/Public/Tools/YouTubeTool.psm1 Import-Module $PSScriptRoot/Public/Tools/YouTubeAssistant.psm1 # Public Functions +. $PSScriptRoot/Public/Invoke-QuickPrompt.ps1 . $PSScriptRoot/Public/New-Agent.ps1 . $PSScriptRoot/Public/Get-AgentResponse.ps1 . $PSScriptRoot/Public/Invoke-InteractiveCLI.ps1 @@ -145,6 +146,7 @@ Set-Alias noaia New-OAIAssistant Set-Alias noait New-OAIThread Set-Alias uoaia Update-OAIAssistant Set-Alias ai Invoke-OAIChat +Set-Alias q Invoke-QuickPrompt $targetTypes = "System.String", "System.Array" diff --git a/Public/Invoke-QuickPrompt.ps1 b/Public/Invoke-QuickPrompt.ps1 new file mode 100644 index 0000000..3dcd992 --- /dev/null +++ b/Public/Invoke-QuickPrompt.ps1 @@ -0,0 +1,77 @@ +function Invoke-QuickPrompt { + [CmdletBinding()] + param( + [string]$targetPrompt, + [Parameter(ValueFromPipeline = $true)] + [object]$pipelineInput, + [switch]$OutputOnly + ) + + Begin { + $additionalInstructions = @() + + } + + Process { + $additionalInstructions += $pipelineInput + } + + End { + + $prompt = "work it" + if ($targetPrompt) { + $prompt = $targetPrompt + } + + $instructions += @" +$(Get-Date) +$($pwd) + +- You are a terminal assistant. You are a software and data science expert. Your preference is PowerShell, unless otherwise directed. + +for code answers: +- do not include fence blocks around the code `````` `````` +- do not include explanation +- do not include usage information +- just code + +"@ + + + if ($additionalInstructions) { + $prompt += @" +Here are the additional instructions Fthe user piped in: + +$($additionalInstructions -join "`n") + +"@ + } + + Write-Verbose @" +Instructions: $instructions +Prompt: $prompt +"@ + + $agent = New-Agent -Instructions $instructions + + if($OutputOnly) { + $agent | Get-AgentResponse -Prompt $prompt + return + } + + While ($true) { + $agentResponse = $agent | Get-AgentResponse $prompt + + Format-SpectrePanel -Data (Get-SpectreEscapedText -Text $agentResponse) -Title "Agent Response" -Border "Rounded" -Color "Blue" + Format-SpectrePanel -Data "Follow up, Enter to copy & quit, Ctrl+C to quit." -Title "Next Steps" -Border "Rounded" -Color "Cyan1" + + $prompt = Read-Host '> ' + if ([string]::IsNullOrEmpty($prompt)) { + Format-SpectrePanel -Data "Copied to clipboard." -Title "Information" -Border "Rounded" -Color "Green" + + $agentResponse | Set-Clipboard + break + } + } + } +} \ No newline at end of file From 15d06e694fbdaa41c2924a07511727efb0598ac0 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 29 Dec 2024 20:20:37 -0500 Subject: [PATCH 4/6] Add tests for Invoke-QuickPrompt and its alias --- __tests__/Invoke-QuickPrompt.tests.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 __tests__/Invoke-QuickPrompt.tests.ps1 diff --git a/__tests__/Invoke-QuickPrompt.tests.ps1 b/__tests__/Invoke-QuickPrompt.tests.ps1 new file mode 100644 index 0000000..62c9bb5 --- /dev/null +++ b/__tests__/Invoke-QuickPrompt.tests.ps1 @@ -0,0 +1,15 @@ +Describe 'Test Invoke-QuickPrompt' -Tag Invoke-QuickPrompt { + BeforeAll { + Import-Module "$PSScriptRoot/../PSAI.psd1" -Force + } + + It "Test if it Invoke-QuickPrompt exists" { + $actual = Get-Command Invoke-QuickPrompt -ErrorAction SilentlyContinue + $actual | Should -Not -BeNullOrEmpty + } + + It "Test if it q alias exists" { + $actual = Get-Command q -ErrorAction SilentlyContinue + $actual | Should -Not -BeNullOrEmpty + } +} \ No newline at end of file From e379b315328a9c37414a19d28f3412ffe4fc86dd Mon Sep 17 00:00:00 2001 From: dfinke Date: Tue, 31 Dec 2024 10:14:29 -0500 Subject: [PATCH 5/6] Bump module version to 0.4.0 --- PSAI.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSAI.psd1 b/PSAI.psd1 index dbb0e4d..14ecf5f 100644 --- a/PSAI.psd1 +++ b/PSAI.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSAI.psm1' - ModuleVersion = '0.3.0' + ModuleVersion = '0.4.0' GUID = '68662d19-a8f1-484f-b1b7-3bf0e8a436df' Author = 'Douglas Finke' CompanyName = 'Doug Finke' From c1acee903de0761f4c4fb726749e2bf5aaccb285 Mon Sep 17 00:00:00 2001 From: dfinke Date: Tue, 31 Dec 2024 10:14:35 -0500 Subject: [PATCH 6/6] Update changelog for v0.4.0: Acknowledge contributions and enhance Register-Tool function --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 4362197..0e4630b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,11 @@ +## v0.4.0 + +- Big thank you to [Axel Andersen](https://x.com/Agazoth) + +Axel dove into PSAI, understood the codebase and the direction, and then added a ton of value. This is one of many PRs to come from Axel. + +- Updated the `Register-Tool` function to support function-calling schemas and work with built-in PowerShell functions. + ## v0.3.0 - Fix multi line description transpiled to Json