How to Integrate the new DALL-E 3 API into Botpres...
# 📖tutorials
s
Youtube Link:

https://youtu.be/pdH8T3oWAy0

🚨 Note: Setting up your own Open API Key will mean you are paying for the Images that are generated. Generating images for Dall-E at time of this tutorial is .04 cents for the standard image. Execute Code: - See text file in thread Template - See Botpress file in thread https://www.buymeacoffee.com/simplygreatgames
j
Cool
c
Super cool ! Thanks for sharing this tutorial @straight-wolf-37371
t
Cool, But somehow the code didn't work...don't know which part went wrong...
c
this code appear to me plz help Error executing action "inline-card:Create an image using a prompt and API integration..js" in flow:Image generation:node:Standard [SyntaxError, Unexpected token 'const'] {"scope":"bot-action","cardId":"card:Create an image using a prompt and API integration.","nodeId":"node:Standard","workflowId":"flow:Image generation"}
s
See what error you are getting in the debugger. The most common ones I have seen is API key is wrong or you are hitting the content filter. It will automatically reject sensitive things or it looks like maybe even copywrite material. I can pinged for saying "Dungeons and Dragons" for example
IT doesn't look like an error in your code. It looks like an error in your card that you are trying to use to display the image. Make sure your card is set up right.
s
I get this error: Error executing action "inline-card:Generate an image using the OpenAI API..js" in flow:generate_cover:node:Standard [SyntaxError, Invalid or unexpected token] {"scope":"bot-action","cardId":"card:Generate an image using the OpenAI API.","nodeId":"node:Standard","workflowId":"flow:generate_cover"}
s
Looks liek your passing in a bad var. Either bad API key or prompt
s
I tested the API key in python - it works and should be correct set up
It may be the prompt then..
s
What does the full event debugger say? See my screenshot above for reference. Find the one its erroring on
s
It worked now, thanks a lot. The code provided above was formatted by discord so it's not correct
needs to be like this:
s
Ahh you are right!!! Thank you for alerting me. I will update. If i put in a code box it should format properly.
s
No problem, thank you for providing your code here, works perfectly fine now!
s
Execute Code
Great! Have fun 🙂
Here is a free downloadable template ❤️
c
Amazing @straight-wolf-37371 ! thanks 😉
w
This is amazing!!!!
hey can u tell after downloading this i have to go to my botpress and import only? or some process ?
s
Yes, you can import into a bot but beware that it will replace your bot right now. If you want to just add this functionality to your pre-existing bot you can use the execute code provided above. Take that script and place in an execute card similar to how its done in the template.
w
thank your so much
sir
async function createImage() { const prompt = workflow.prompt const apiKey = env.OPEN_API_KEY const apiUrl = 'https://api.openai.com/v1/images/generations' const headers = { 'Content-Type': 'application/json',
i have to just paste this code ?
s
Yes, here is the whole thing: `async function createImage() { const prompt = workflow.prompt const apiKey = API KEY HERE const apiUrl = 'https://api.openai.com/v1/images/generations' const headers = { 'Content-Type': 'application/json', Authorization:
Bearer ${apiKey}
} const data = { prompt: prompt, n: 1, size: '1024x1024', model: 'dall-e-3', quality: 'standard' } try { const response = await axios.post(apiUrl, data, { headers }) const imageURL = response.data.data[0].url return imageURL } catch (error) { console.error('Error creating image:', error) } } workflow.imageURL = await createImage()` You need to get an open API key of course. And create the imageURL var as a workflow var. That will be the url to the image. You can put in a card/image or whatever
w
ohhh
thankss!
open ai wants my card details for api key and im just 15 my mother wont allow me to enter can i get somebody else's api key?
f
It costs money every time you use DallE or any other model. What will you use it for and how many times?
4 Views