Skip to content

Commit

Permalink
tell a story
Browse files Browse the repository at this point in the history
  • Loading branch information
genekogan committed Jul 19, 2023
1 parent 2138ec5 commit 22db647
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 26 deletions.
139 changes: 120 additions & 19 deletions config_generators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import openai from 'openai';
import { Configuration, OpenAIApi } from 'openai';
import dotenv from 'dotenv';

dotenv.config()
Expand All @@ -12,7 +12,7 @@ function getRandomSample(arr, sampleSize) {
}


const promptIntro = `I am generating text prompts for AI generators. These are descriptions of artworks which are highly detailed and aesthetically imaginative, and diverse. They should start with a description of the content and then a long list of modifiers which elaborate on the style, genre, and medium. They should be creative, bold, evocative, edgy, diverse, and eclectic.
const promptIntro = `I am generating text prompts for AI art generators. These are descriptions of original artworks which are . They should start with a description of the content and then a long list of modifiers which elaborate on the style, genre, and medium. They should be creative, bold, evocative, edgy, diverse, and eclectic.
Here are some examples.`;

Expand Down Expand Up @@ -61,30 +61,131 @@ export async function combinePrompt() {
return prompt;
}




export async function generatePrompts() {
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const configuration = new openai.Configuration({
apiKey: OPENAI_API_KEY,
const messages_topic = [{
"role": "system",
"content": `You help with writer's block for journalists, artists, and other creative intellectuals.`
},{
"role": "user",
"content": `Give me some kind of artistic or intellectual task, like to explain a scientific concept, write a poem, tell a story, or
For example:
Write a Lord of the Rings style epic novel about a Hobbit-like creature who grows up to become a dark overlord, and is eventually redeemed by his daughter
Explain the grabby theory of aliens.
Write out the sequence of significant evolutionary steps which led from the first life on Earth to modern technological human beings.
Write the Lord's Prayer in English in every other century since the 10th century.
Give me another one. Be concise, just state the task.`
}]

const response_subject = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: messages_topic,
temperature: 1,
max_tokens: 500,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
const openai_api = new openai.OpenAIApi(configuration);

const promptPrompt = generatePromptPrompt();

const nextTask = response_subject.data.choices[0].message.content;


let completion = await openai_api.createCompletion({
model: "text-davinci-003",
prompt: promptPrompt,
temperature: 0.99,
max_tokens: 400,
const messages = [
{
"role": "system",
"content": `You are a world-renowned artist who produces original digital artworks. You are immensely creative, original, and eclectic. Humans ask you to make artworks according to some specific, story, or context. You respond with the following:
1) a genre and set of detailed visual characteristics which define the overall story. prefix it with "Genre"
2) an ordered set of artwork titles which respond to the prompt and tell a story or otherwise respond to it in a novel way. Prefix this with "Chapters"`},
{
"role": "user",
"content": "Write a Lord of the Rings style epic novel about a Hobbit-like creature who grows up to become a dark overlord, and is eventually redeemed by his daughter.",
},
{
"role": "assistant",
"content": `1) Genre: Dark fantasy, monochromatic, deep dark blues, 35mm, 2.2 gamma, sony a7r7, tamron 10-24mm f/3.5-4.5
2) Chapters:
Innocence Awakens
A Journey Begins
Secrets of the Shadows
The Lure of Power
Corrupted Descent
Crown of Shadows
Daughter of Light
The Fateful Encounter with the Daughter
Clash of the Heirs and Daughter
Battles in the Twilight
The Vortex of Destiny
The Triumph of Light
Forgiveness and Daughter's Redemption
A New Era Dawns`
},
{
"role": "user",
"content": "Explain the grabby alien theory."
},
{
"role": "assistant",
"content": `1) Genre: Abstract surrealism, vibrant colors, distortion effects, psychedelic colors, futurism
2) Chapters:
Life is common, a rule rather than an exception
Advanced civilizations spread rapidly, like seeds in the wind
We're early, the cosmic party's yet to reach full swing
We're not unique; if we can, others can too
Advanced aliens leave noticeable marks, like humans on Earth
Eventually, we're likely to cross paths with these aliens
Tech-savvy civilizations expand swiftly into space
Space-faring civilizations are bound to bump into each other
Aliens, like us, use up their local resources
Unseen does not mean nonexistent; aliens could be beyond observation`
},
{
"role": "user",
"content": nextTask
}
]

const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: messages,
temperature: 1,
max_tokens: 500,
top_p: 1,
frequency_penalty: 0.35,
presence_penalty: 0.25
frequency_penalty: 0,
presence_penalty: 0,
});

let prompts = completion.data.choices[0].text;
prompts = prompts.split("\n");
prompts = prompts.filter((line) => line.length > 0);
prompts = prompts.map(removeNumbering);

const text = response.data.choices[0].message.content;
const lines = text.split('\n');

// extract genre
const genreLine = lines.find(line => line.includes('1) Genre:'));
if (!genreLine) throw new Error("Genre not found");
const genre = genreLine.split(': ')[1];

// extract chapters
const chapterIndex = lines.findIndex(line => line.includes('2) Chapters:'));
if (chapterIndex === -1) throw new Error("Chapters not found");
const chapters = lines.slice(chapterIndex + 1).map(line => line.trim()).filter(line => line !== '');

const prompts = chapters.map(chapter => {
return `${chapter}, ${genre}`;
});

console.log(nextTask);
console.log(prompts);

return prompts;
}

14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ async function sleep(ms) {

const main = async () => {

console.log("==========")
const prompts = await generatePrompts();

for (var i=0; i<prompts.length; i++) {
let prompt = prompts[i];
console.log("==========")
console.log(prompt)

let sizes = [[768, 768], [960, 960], [960, 640], [1024, 640], [1152, 768]];
Expand Down Expand Up @@ -61,18 +61,18 @@ const main = async () => {
"upscale_f": upscale_f,
}

// try {
let result = await eden.tasks.create({
try {
const result = await eden.tasks.create({
generatorName: "create",
config: config
});
console.log(config);
console.log(result);
nMade++;
// } catch (error) {
// console.error(error);
// }
await sleep(2 * 60 * 1000);
} catch (error) {
console.error(error);
}
await sleep(2.5 * 60 * 1000);
}
}

Expand Down

0 comments on commit 22db647

Please sign in to comment.