Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Jun 27, 2024
1 parent f221e88 commit 2a74a9e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion PSHelp.Copilot.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'PSHelp.Copilot.psm1'

# Version number of this module.
ModuleVersion = '1.0.2'
ModuleVersion = '1.0.4'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down
6 changes: 5 additions & 1 deletion PSHelp.Copilot.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ if (Test-Path -Path $configFile) {
}

$PSDefaultParameterValues['Import-Module:Verbose'] = $false
$PSDefaultParameterValues['Add-Type:Verbose'] = $false
$PSDefaultParameterValues['Add-Type:Verbose'] = $false

if (-not (Get-OpenAIProvider).ApiKey) {
Write-Warning "No API key found. Use Set-OpenAIProvider or `$env:OPENAI_API_KEY to set the API key."
}
2 changes: 2 additions & 0 deletions private/Get-APIKey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function Get-APIKey {
elseif ($null -ne $env:OPENAI_API_KEY -and $env:OPENAI_API_KEY -is [string]) {
$key = [string]$env:OPENAI_API_KEY
Write-Verbose -Message 'API Key found in environment variable "OPENAI_API_KEY".'
} else {
Write-Verbose "API Key not found."
}

if ($key -is [securestring]) {
Expand Down
6 changes: 6 additions & 0 deletions public/Clear-OpenAIProvider.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function Clear-OpenAIProvider {
Write-Verbose "Removing default ApiKey from PSDefaultParameterValues."
$null = $defaults.Remove("*:ApiKey")
}
if ($PSDefaultParameterValues["*:Deployment"]) {
Write-Verbose "Removing default Deployment from PSDefaultParameterValues."
$null = $PSDefaultParameterValues.Remove("*:Deployment")
$null = $PSDefaultParameterValues.Remove("*:Model")
}

Write-Verbose "OpenAI provider configuration reset to default."
Get-OpenAIProvider
}
2 changes: 1 addition & 1 deletion public/Get-OpenAIProvider.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Get-OpenAIProvider {
ApiKey = $maskedkey
AuthType = $auth
ApiType = $auth
Deployment = $null
Deployment = $PSDefaultParameterValues['*:Deployment']
ApiBase = $null
ApiVersion = $null
Organization = $null
Expand Down
1 change: 1 addition & 0 deletions public/Invoke-HelpChat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function Invoke-HelpChat {
## User Question
$msg"
} elseif (-not $NoYell) {
$msg = $msg + "`r`nOutput in plain-text. NOT markdown."
# lol look, i'm desperate
$msg = $msg + "`r`nUSE YOUR RETRIEVAL DOCUMENTS!!!"
}
Expand Down
20 changes: 16 additions & 4 deletions public/Set-OpenAIProvider.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ function Set-OpenAIProvider {
$AuthType = if ($ApiType -eq 'Azure') { 'Azure' } else { 'OpenAI' }
}

if ($PSBoundParameters.Count -eq 1 -and $Deployment) {
Set-Variable -Scope 1 -Name PSDefaultParameterValues -Force -ErrorAction SilentlyContinue -Value @{
'*:Deployment' = $Deployment
'*:Model' = $Deployment
}

Get-OpenAIProvider
return
}

if (-not $ApiKey) {
$ApiKey = Get-ApiKey -PlainText
}
$null = Clear-OpenAIProvider

if ($ApiType -eq 'Azure') {
# Set context for Azure
Expand All @@ -104,9 +113,12 @@ function Set-OpenAIProvider {
} else {
# Set context for OpenAI
$splat = @{
ApiType = 'OpenAI'
AuthType = 'OpenAI'
ApiKey = $ApiKey
ApiType = 'OpenAI'
AuthType = 'OpenAI'
ApiKey = $ApiKey
ApiBase = $null
ApiVersion = $null
Organization = $null
}
}
$null = Set-OpenAIContext @splat
Expand Down

0 comments on commit 2a74a9e

Please sign in to comment.