traintocode

Calling DALLE

To make the call to OpenAI you can use the OpenAI Node API Library which you can import and create a new instance of using:

import OpenAI from "openai";

const openai = new OpenAI({ apiKey: process.env['OPENAI_KEY'] });

To generate your image using DALL·E, call openai.images.generate() passing in a value for the model field of "dall-e-3". You can read more about image generation in the OpenAI docs.

Exercise
1. Create a new instance of the OpenAI class using the API key from process.env['OPENAI_KEY'].

2. Call the method openai.images.generate() passing in a prompt asking DALLE to generate a cartoon image of your subject. Set the response_format field to "url" to get the result as a hosted image url.

3. Read the response message from gptResponse.data[0].url and return it in the result's body field.
    You cannot do the coding exercises on this device, visit this page on a larger screen.
    handler.ts
    Loading...