scrimba
AI Apps
Build a movie idea generator with ChatGPT and Dall-E
fetchSynopsis
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

fetchSynopsis
Expand for more info
index.js
run
preview
console
import { process } from '/env'
import { Configuration, OpenAIApi } from 'openai'

const setupTextarea = document.getElementById('setup-textarea')
const setupInputContainer = document.getElementById('setup-input-container')
const movieBossText = document.getElementById('movie-boss-text')

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY
})

const openai = new OpenAIApi(configuration)

document.getElementById("send-btn").addEventListener("click", () => {
if (setupTextarea.value) {
const userInput = setupTextarea.value
setupInputContainer.innerHTML = `<img src="images/loading.svg" class="loading" id="loading">`
movieBossText.innerText = `Ok, just wait a second while my digital brain digests that...`
fetchBotReply(userInput)
}
})

async function fetchBotReply(outline) {
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Generate a short message to enthusiastically say "${outline}" sounds interesting and that you need some minutes to think about it. Mention one aspect of the sentence."`,
max_tokens: 60 // defaults to 16
})
movieBossText.innerText = response.data.choices[0].text.trim()
console.log(response)
}

Console
/index.html
-6:32