forked from StartAutomating/PowerShellAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-DalleImage.ps1
59 lines (49 loc) · 1.61 KB
/
Get-DalleImage.ps1
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
function Get-DalleImage {
<#
.SYNOPSIS
Get a DALL-E image from the OpenAI API
.DESCRIPTION
Given a description, the model will return an image
.PARAMETER Description
The description to generate an image for
.PARAMETER Size
The size of the image to generate. Defaults to 256
.PARAMETER Raw
If set, the raw response will be returned. Otherwise, the image will be saved to a temporary file and the path to that file will be returned
.PARAMETER NoProgress
The option to hide write-progress if you want, you could also set $ProgressPreference to SilentlyContinue
.EXAMPLE
Get-DalleImage -Description "A cat sitting on a table"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
$Description,
[ValidateSet('256', '512', '1024')]
$Size = 256,
[Switch]$Raw,
[Switch]$NoProgress
)
$targetSize = switch ($Size) {
256 { '256x256' }
512 { '512x512' }
1024 { '1024x1024' }
}
$body = [ordered]@{
prompt = $Description
size = $targetSize
} | ConvertTo-Json
$result = Invoke-OpenAIAPI -Uri (Get-OpenAIImagesGenerationsURI) -Body $body -Method Post
if ($Raw) {
return $result
}
else {
$DestinationPath = [IO.Path]::GetTempFileName() -replace ".tmp", ".png"
$params = @{
Uri = $result.data.url
OutFile = $DestinationPath
}
Invoke-RestMethodWithProgress -Params $params -NoProgress:$NoProgress
$DestinationPath
}
}