Generate Image

Script openai Verified

by adam186 ยท 12/12/2022

The script

Submitted by hugo989 Bun
Verified 6 days ago
1
import { Configuration, OpenAIApi } from "[email protected]";
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
  • Submitted by no silver bullet133 Deno
    Created 1114 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
        return x
    5
    }
  • Submitted by mauro.mericogm498 Deno
    Created 1111 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
        return x
    5
    }
  • Submitted by kvr.dfy724 Python3
    Created 1092 days ago
    1
    #import wmill
    2
    
    
    3
    def main(x: str):
    4
        return x
  • Submitted by himanshu568 Python3
    Created 1051 days ago
    1
    #import wmill
    2
    
    
    3
    def main(x: str):
    4
        return x
  • Submitted by hquestion325 Deno
    Created 1026 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
        return x
    5
    }
  • Submitted by adam186 Deno
    Created 398 days ago
    1
    import { Configuration, OpenAIApi } from "npm:[email protected]";
    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