Hi,
I recently installed the npm package “node-dalle2” on my wix site. I am having issues using it though. Can you spot any errors in the code below?
This is the serviceModule.jsw:
import { Dalle } from ‘node-dalle2’ ;
//const getDalle2Images = async (caption) => {
export async function getDalle2Images ( caption ) {
//export async function getDalle2Images(caption) {
// Add Session key
const dalle = new Dalle ({ apiKey : “sess-xxxxxxxxxxxxxxxxxxxxxxxxx” });
// Call the Dall-e 2 API
const response = await dalle . generate ( caption );
// If Dall-e 2 couldn’t generate images from the given caption
if (! response ) {
console . error (
“The AI couldn’t generate images based upon the given caption.”
);
return null ;
}
// Get the image array from the response object
const { data } = response ;
// Return the image array
return data ;
}
This is the page with the button that should call the function when the button is selected:
import { getDalle2Images } from ‘backend/serviceModule’
export function button8_click ( event ) {
getDalle2Images ( “Coolest abstract tattoo in the style of Ivan Bilibin” )
. then (( data ) => {
// If the image array is empty for some reason
**if** (! data ) {
console . error ( "Something has gone horribly wrong..." );
**return null** ;
}
// Log the image array
console . log ( data );
}
);
}