-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImages.ps1
55 lines (41 loc) · 1.22 KB
/
Images.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
function Get-AIImage
{
[CmdLetBinding()]
param (
[String]$apiKey = (Get-Secret -Name ChatGptAPI|convertfrom-Securestring -AsPlainText),
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[String]$question,
[Validaterange(1,10)]
[int]$number = 1,
[ValidateSet("256x256","512x512","1024x1024")]
[String]$size = "512x512",
[ValidateSet('url','b64_json')]
[string]$responseFormat = 'url'
)
begin {
$apiEndpoint = "https://api.openai.com/v1/images/generations"
}
process {
# Set the request headers
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $apiKey"
}
# Set the request body
$requestBody = @{
"prompt" = $question
"n" = $number
"size" = $size
"response_format" = $responseFormat
}
# Send the request
$response = Invoke-RestMethod -Method POST -Uri $apiEndpoint -Headers $headers -Body (ConvertTo-Json $requestBody)
# Print the response
$response.data.url
}
end {
}
}