-
Notifications
You must be signed in to change notification settings - Fork 11
/
PSOpenAI.psm1
68 lines (58 loc) · 2.13 KB
/
PSOpenAI.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$PrivateDirectory = Join-Path $PSScriptRoot 'Private'
$PublicDirectory = Join-Path $PSScriptRoot 'Public'
$PrivateFunctions = Get-ChildItem -LiteralPath $PrivateDirectory -Recurse -Filter '*.ps1' -File
$PublicFunctions = Get-ChildItem -LiteralPath $PublicDirectory -Recurse -Filter '*.ps1' -File
# Exclude on specific platfotm.
$Exclude = @()
if (-not $IsWindows -or $PSVersionTable.PSVersion -lt 7.4) {
$Exclude = @(
'Start-RealtimeSessionAudioOutput.ps1'
'Stop-RealtimeSessionAudioOutput.ps1'
'Stop-RealtimeSessionAudioInput.ps1'
'Stop-RealtimeSessionAudioInput.ps1'
)
}
# Include Private functions
$PrivateFunctions | Where-Object { $_.Name -notin $Exclude } | ForEach-Object {
. $_.FullName
}
# Include Public functions
$PublicFunctions | Where-Object { $_.Name -notin $Exclude } | ForEach-Object {
. $_.FullName
}
# Export public functions
$ExportFunctions = [string[]]@()
$PublicFunctions | ForEach-Object {
if (Test-Path -LiteralPath "Function:/$($_.BaseName)") {
$ExportFunctions += $_.BaseName
}
}
if ($ExportFunctions.Count -ge 1) {
Export-ModuleMember -Function $ExportFunctions -Alias *
}
# Initialize context dictionary
Clear-OpenAIContext
# Export classes
$ExportableTypes = @(
[APIRequestException]
[BadRequestException]
[ContentFilteredException]
[UnauthorizedException]
[NotFoundException]
[RateLimitExceededException]
[QuotaLimitExceededException]
)
# Get the internal TypeAccelerators class to use its static methods.
$TypeAcceleratorsClass = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
# Add type accelerators for every exportable type.
foreach ($Type in $ExportableTypes) {
if ($Type.FullName -notin $ExistingTypeAccelerators.Keys) {
$null = $TypeAcceleratorsClass::Add($Type.FullName, $Type)
}
}
# Remove type accelerators when the module is removed.
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
foreach ($Type in $ExportableTypes) {
$null = $TypeAcceleratorsClass::Remove($Type.FullName)
}
}.GetNewClosure()