Skip to content

Commit b2215fd

Browse files
committed
Add Get, Enable, Disable ChatPersistence
1 parent 465c072 commit b2215fd

9 files changed

+95
-22
lines changed

PowerShellAI.psd1

+3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ The PowerShell AI module integrates with the OpenAI API and let's you easily acc
1919
'ConvertFrom-GPTMarkdownTable'
2020
'copilot'
2121
'Disable-AIShortCutKey'
22+
'Disable-ChatPersistence'
2223
'Enable-AIShortCutKey'
24+
'Enable-ChatPersistence'
2325
'Get-DalleImage'
2426
'Get-ChatCompletion'
27+
'Get-ChatPersistence'
2528
'Get-GPT3Completion'
2629
'Get-GPT4Completion'
2730
'Get-GPT4Response'

PowerShellAI.psm1

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1-
$Script:OpenAIKey = $null
1+
# Set the OpenAI key to null
2+
$Script:OpenAIKey = $null
23

4+
# Set the chat API provider to OpenAI
5+
$Script:ChatAPIProvider = 'OpenAI'
36

7+
# Set the chat in progress flag to false
8+
$Script:ChatInProgress = $false
9+
10+
# Create an array list to store chat messages
11+
[System.Collections.ArrayList]$Script:ChatMessages = @()
12+
13+
# Enable chat persistence
14+
$Script:ChatPersistence = $true
15+
16+
# Set the options for the chat session
17+
$Script:ChatSessionOptions = @{
18+
'model' = 'gpt-4'
19+
'temperature' = 0.0
20+
'max_tokens' = 256
21+
'top_p' = 1.0
22+
'frequency_penalty' = 0
23+
'presence_penalty' = 0
24+
'stop' = $null
25+
}
26+
27+
# Set the options for the Azure OpenAI API
28+
$Script:AzureOpenAIOptions = @{
29+
Endpoint = 'not set'
30+
DeploymentName = 'not set'
31+
ApiVersion = 'not set'
32+
}
33+
34+
# Load all PowerShell scripts in the Public and Private directories
435
foreach ($directory in @('Public', 'Private')) {
536
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object { . $_.FullName }
637
}

Public/Disable-ChatPersistence.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function Disable-ChatPersistence {
2+
$Script:ChatPersistence = $false
3+
}

Public/Enable-ChatPersistence.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function Enable-ChatPersistence {
2+
$Script:ChatPersistence = $true
3+
}

Public/Get-ChatPersistence.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function Get-ChatPersistence {
2+
$Script:ChatPersistence
3+
}

Public/Get-GPT4Completion.ps1

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
$Script:ChatSessionOptions = @{
2-
'model' = 'gpt-4'
3-
'temperature' = 0.0
4-
'max_tokens' = 256
5-
'top_p' = 1.0
6-
'frequency_penalty' = 0
7-
'presence_penalty' = 0
8-
'stop' = $null
9-
}
10-
11-
$Script:AzureOpenAIOptions = @{
12-
Endpoint = 'not set'
13-
DeploymentName = 'not set'
14-
ApiVersion = 'not set'
15-
}
16-
17-
$Script:ChatAPIProvider = 'OpenAI'
18-
$Script:ChatInProgress = $false
19-
20-
[System.Collections.ArrayList]$Script:ChatMessages = @()
21-
221
function Get-AzureOpenAIOptions {
232
[CmdletBinding()]
243
param()
@@ -197,6 +176,8 @@ function Reset-ChatSessionOptions {
197176
'presence_penalty' = 0
198177
'stop' = $null
199178
}
179+
180+
Enable-ChatPersistence
200181
}
201182

202183
function Clear-ChatMessages {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Describe 'Disable-ChatPersistence' -Tag ChatPersistence {
2+
3+
BeforeEach {
4+
Reset-ChatSessionOptions
5+
}
6+
7+
8+
It 'tests the function Disable-ChatPersistence exists' {
9+
$actual = Get-Command Disable-ChatPersistence -ErrorAction SilentlyContinue
10+
$actual | Should -Not -BeNullOrEmpty
11+
}
12+
13+
It 'tests that it disables chat persistence' {
14+
Disable-ChatPersistence
15+
$actual = Get-ChatPersistence
16+
17+
$actual | Should -Be $false
18+
}
19+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Describe 'Enable-ChatPersistence' -Tag ChatPersistence {
2+
3+
AfterEach {
4+
Reset-ChatSessionOptions
5+
}
6+
7+
It 'tests the function Enable-ChatPersistence exists' {
8+
$actual = Get-Command Enable-ChatPersistence -ErrorAction SilentlyContinue
9+
$actual | Should -Not -BeNullOrEmpty
10+
}
11+
12+
It 'tests that it enables chat persistence' {
13+
Enable-ChatPersistence
14+
$actual = Get-ChatPersistence
15+
16+
$actual | Should -Be $true
17+
}
18+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
Describe 'Get-ChatPersistence' -Tag ChatPersistence {
3+
It 'tests the function Get-ChatPersistence exists' {
4+
$actual = Get-Command Get-ChatPersistence -ErrorAction SilentlyContinue
5+
$actual | Should -Not -BeNullOrEmpty
6+
}
7+
8+
It 'tests the function Get-ChatPersistence returns a boolean' {
9+
$actual = Get-ChatPersistence
10+
$actual.GetType().Name | Should -Be 'Boolean'
11+
}
12+
}

0 commit comments

Comments
 (0)