Create captivating stories with AI-generated prompts. This code snippet uses OpenAI's GPT-3 to generate incomplete story prompts, giving users the chance to complete the story in their own unique way. Use this snippet to inspire your creative writing or to generate new story ideas.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
try {
// removing the prefix
let b = context.params.event.content.slice(
7,
context.params.event.content.length - 1
);
let a = await lib.openai.playground['@0.0.4'].completions.create({
model: `text-davinci-003`,
prompt: [`Create a story based on : ${b} but keep it incomplete`],
max_tokens: 52,
temperature: 0.7,
top_p: 1,
n: 1,
echo: false,
presence_penalty: 0,
frequency_penalty: 0,
});
// sending it to discord
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `${a.choices[0].text}`,
});
} catch (e) {
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `${e}`,
});
}
/*
A example is :
!story a man was walking alone on the road.
*/