1
Generate Image
One script reply has been approved by the moderators Verified
Created by adam186 731 days ago Viewed 10045 times
0
Submitted by adam186 Deno
Verified 731 days ago
1
import { Configuration, OpenAIApi } from "npm:openai@3.1.0";
2

3
/**
4
 * @param prompt The maximum length is 1000 characters.
5
 */
6
type Openai = {
7
  api_key: string;
8
  organization_id: string;
9
};
10
export async function main(
11
  auth: Openai,
12
  prompt: string,
13
  number_of_images:
14
    | "1"
15
    | "2"
16
    | "3"
17
    | "4"
18
    | "5"
19
    | "6"
20
    | "7"
21
    | "8"
22
    | "9"
23
    | "10" = "1",
24
  size: "256x256" | "512x512" | "1024x1024" = "1024x1024",
25
  response_format: "url" | "b64_json" = "url"
26
) {
27
  const configuration = new Configuration({
28
    apiKey: auth.api_key,
29
    organization: auth.organization_id,
30
  });
31
  const openai = new OpenAIApi(configuration);
32

33
  const response = await openai.createImage({
34
    prompt,
35
    n: +number_of_images,
36
    size,
37
    response_format,
38
  });
39
  return response.data.data;
40
}
41

Other submissions