Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ptrckbp
Created February 21, 2023 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptrckbp/ef03197c8b609a0ce310fa987d8b58b1 to your computer and use it in GitHub Desktop.
Save ptrckbp/ef03197c8b609a0ce310fa987d8b58b1 to your computer and use it in GitHub Desktop.
how to add image generation to your chatbot

You should have four flow variables :

peopleAmount (string type) peopleAction (string type) imageStyle (string type) outputUrls (array type)

After creating your prompt (which saves the answers to the first three variables), add this code to the next node to get the urls of the images. They will be stored to outputUrls.

Make sure to replace YOUR_OPENAPI_KEY with your openai api key.

const endpoint = 'https://api.openai.com/v1/images/generations'

const inputData = JSON.stringify({
  prompt: `There are ${workflow.peopleAmount} people. They are ${workflow.peopleAction}. ${workflow.imageStyle}`,
  n: 2,
  size: '1024x1024'
})

const config = {
  method: 'post',
  url: 'https://api.openai.com/v1/images/generations',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer YOUR_OPENAPI_KEY'
  },
  data: inputData,
  withCredentials: false
}

const result = await axios(config)
const { data } = result

workflow.outputUrls = data.data

after the code block, you can add a content element, selecting carousel as the type.

Your carousel should have two cards, with the "Image" fields set to : {{workflow.outputUrls[0].url}} (for the first) {{workflow.outputUrls[1].url}} (for the second)

That's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment