Skip to content

Commit

Permalink
Fix: dfinke#50 API Key reset after Invoke-Pester
Browse files Browse the repository at this point in the history
  • Loading branch information
Agazoth committed Dec 2, 2024
1 parent 2100f09 commit 13bf1dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions __tests__/IntegrationTests/Integration-OpenAI.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ BeforeDiscovery {
$info = $null
} else{
$info = Get-SecretInfo -Name OpenAI
$env:TempOpenAIKey = $env:OpenAIKey
$env:OpenAIKey = Get-Secret OpenAI -asPlainText # replace with clear text password if Get-Secret is not setup on your system
}
}
Expand Down Expand Up @@ -45,7 +46,7 @@ Describe "Test chat endpoints with Environment Variable" -Skip:($null -eq $env:O
}

Context "Invoke-OAIChatCompletion with Environment Variable" {
It "Invoke-OAIChatCompletion generates an answer" -Skip:($null -eq $envSecret) {
It "Invoke-OAIChatCompletion generates an answer" -Skip:($null -eq $env:OpenAIKey) {
$Prompt = "What is the capitol of France"
$Message = New-OAIChatMessage -Role user -Content $Prompt
$Answer = Invoke-OAIChatCompletion -Message $Message
Expand All @@ -55,4 +56,6 @@ Describe "Test chat endpoints with Environment Variable" -Skip:($null -eq $env:O
}

}
}
}

AfterAll {$env:OpenAIKey = $env:TempOpenAIKey}
8 changes: 8 additions & 0 deletions __tests__/Invoke-OAIBeta-InvokeRestMethod-OpenAI.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
BeforeAll {
$env:TempOpenAIKey = $env:OpenAIKey
}

Describe 'Test Invoke-OAIBeta InvokeRestMethod OpenAI Params' -Tag Invoke-OAIBetaParams-OpenAI {
BeforeAll {
Import-Module "$PSScriptRoot/../PSAI.psd1" -Force
Expand Down Expand Up @@ -209,4 +213,8 @@ Describe 'Test Invoke-OAIBeta InvokeRestMethod OpenAI Params' -Tag Invoke-OAIBet

Test-UnitTestingData $UnitTestingData $ExpectedUnitTestingData
}
}

AfterAll {
$env:OpenAIKey = $env:TempOpenAIKey
}

0 comments on commit 13bf1dd

Please sign in to comment.