Generate 10 Short Stories with OpenAI API
import openai # for making OpenAI API requests
num_stories = 10 prompts = ['Once upon a time,'] * num_stories
batched example, with 10 story completions per request
response = openai.Completion.create( model='curie', prompt=prompts, max_tokens=20, )
match completions to prompts by index
stories = ['' ] * len(prompts) for choice in response.choices: stories[choice.index] = prompts[choice.index] + choice.text
print stories
for story in stories: print(story)
'Once upon a time, there was a beautiful princess who lived in a magical kingdom. 'Once upon a time, there was a brave knight who set out on a quest to save his kingdom. 'Once upon a time, there was a mischievous fairy who loved to play pranks on humans. 'Once upon a time, there was a wise old wizard who lived in a tower. 'Once upon a time, there was a curious cat who loved to explore new places. 'Once upon a time, there was a young boy who dreamed of becoming a great adventurer. 'Once upon a time, there was a powerful dragon who guarded a treasure hoard. 'Once upon a time, there was a kind-hearted queen who ruled her kingdom with compassion. 'Once upon a time, there was a group of friends who went on a magical journey together. 'Once upon a time, there was a mysterious stranger who arrived in town and changed everything.'
原文地址: https://www.cveoy.top/t/topic/lU7p 著作权归作者所有。请勿转载和采集!