NaNoGenMo / 2022

National Novel Generation Month, 2022 edition.
51 stars 0 forks source link

NaNoGenGenMo #15

Open lizadaly opened 1 year ago

lizadaly commented 1 year ago

It's time to automate away the tedious work of automating away the tedious work of writing a novel.


$ curl https://api.openai.com/v1/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ${OPENAI_API_KEY}" \
    -d '{"model": "text-davinci-002", 
         "max_tokens": 4000, "temperature": 0.7,
         "prompt": "We need to generate a novel of 50,000 words!! Write your output in the form of a python program."}'

{"id":"cmpl-67mysX59fF0APxm7I3BEmWbn4InhP",
 "object":"text_completion",
 "created":1667314598,
 "model":"text-davinci-002",
 "choices":[
    {"text":
    "\n\nimport random\n\n# list of possible words\nwords = [\"apple\", \"banana\", \"cat\", \"dog\", \"elephant\", \"fish\", \"giraffe\", \"horse\",
    \"iguana\", \"jaguar\", \"kangaroo\", \"lion\", \"monkey\", \"narwhal\", \"octopus\", \"penguin\", \"quail\", \"rhinoceros\", \"seagull\", 
    \"toucan\", \"unicorn\", \"vulture\", \"walrus\", \"xenomorph\", \"yak\", \"zebra\"]\n\n# variables to keep track of word count and sentence
    count\nword_count = 0\nsentence_count = 0\n\n# open a new file to write the novel to\nf = open(\"novel.txt\", \"w\")\n\n# write a new sentence
    to the file until we reach the desired word count\nwhile word_count < 50000:\n    # pick a random word from the list\n    
    word = random.choice(words)\n    \n    # write the word to the file\n    f.write(word + \" \")\n    \n    
    # increment the word count\n    word_count += 1\n    \n    # every 10 words, start a new sentence\n    if word_count % 10 == 0:\n   
    f.write(\"\\n\")\n        sentence_count += 1\n    \n    # every 100 sentences, start a new paragraph\n    if sentence_count == 100:\n
    f.write(\"\\n\\n\")\n        sentence_count = 0\n\n# close the file\nf.close()",
 "index":0,
 "logprobs":null,
 "finish_reason":"stop"
}

The generated program.

The generated program's generated novel. Sample:

giraffe banana jaguar lion dog dog dog cat walrus kangaroo octopus zebra zebra fish narwhal jaguar horse horse iguana dog xenomorph xenomorph fish lion toucan cat zebra narwhal zebra giraffe apple jaguar rhinoceros banana monkey yak penguin cat walrus kangaroo apple monkey octopus rhinoceros lion apple xenomorph giraffe seagull walrus dog zebra fish walrus monkey dog yak yak seagull seagull

Repo: https://github.com/lizadaly/nanogengenmo2022

lizadaly commented 1 year ago

(I suspect there's prior art here so please point out previous entries!)