Update rate limits and use Chatcompletion (#818)

pull/890/head
dylanra-openai 6 months ago committed by GitHub
parent 8aafc85391
commit 6390b8c66e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,72 +31,13 @@
"source": [
"## Default rate limits\n",
"\n",
"As of Jan 2023, the default rate limits are:\n",
"\n",
"<table>\n",
"<thead>\n",
" <tr>\n",
" <th></th>\n",
" <th>Text Completion &amp; Embedding endpoints</th>\n",
" <th>Code &amp; Edit endpoints</th>\n",
" </tr>\n",
"</thead>\n",
"<tbody>\n",
" <tr>\n",
" <td>Free trial users</td>\n",
" <td>\n",
" <ul>\n",
" <li>20 requests / minute</li>\n",
" <li>150,000 tokens / minute</li>\n",
" </ul>\n",
" </td>\n",
" <td>\n",
" <ul>\n",
" <li>20 requests / minute</li>\n",
" <li>150,000 tokens / minute</li>\n",
" </ul>\n",
" </td>\n",
" </tr>\n",
" <tr>\n",
" <td>Pay-as-you-go users (in your first 48 hours)</td>\n",
" <td>\n",
" <ul>\n",
" <li>60 requests / minute</li>\n",
" <li>250,000 davinci tokens / minute (and proportionally more for cheaper models)</li>\n",
" </ul>\n",
" </td>\n",
" <td>\n",
" <ul>\n",
" <li>20 requests / minute</li>\n",
" <li>150,000 tokens / minute</li>\n",
" </ul>\n",
" </td>\n",
" </tr>\n",
" <tr>\n",
" <td>Pay-as-you-go users (after your first 48 hours)</td>\n",
" <td>\n",
" <ul>\n",
" <li>3,000 requests / minute</li>\n",
" <li>250,000 davinci tokens / minute (and proportionally more for cheaper models)</li>\n",
" </ul>\n",
" </td>\n",
" <td>\n",
" <ul>\n",
" <li>20 requests / minute</li>\n",
" <li>150,000 tokens / minute</li>\n",
" </ul>\n",
" </td>\n",
" </tr>\n",
"</tbody>\n",
"</table>\n",
"\n",
"For reference, 1,000 tokens is roughly a page of text.\n",
"Your rate limit and spending limit (quota) are automatically adjusted based on a number of factors. As your usage of the OpenAI API goes up and you successfully pay the bill, we automatically increase your usage tier. You can find specific information regarding rate limits using the resources below.\n",
"\n",
"### Other rate limit resources\n",
"\n",
"Read more about OpenAI's rate limits in these other resources:\n",
"\n",
"- [Guide: Rate limits](https://beta.openai.com/docs/guides/rate-limits/overview)\n",
"- [Guide: Rate limits](https://platform.openai.com/docs/guides/rate-limits?context=tier-free)\n",
"- [Help Center: Is API usage subject to any rate limits?](https://help.openai.com/en/articles/5955598-is-api-usage-subject-to-any-rate-limits)\n",
"- [Help Center: How can I solve 429: 'Too Many Requests' errors?](https://help.openai.com/en/articles/5955604-how-can-i-solve-429-too-many-requests-errors)\n",
"\n",
@ -124,19 +65,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import openai # for making OpenAI API requests\n",
"from openai import OpenAI # for making OpenAI API requests\n",
"client = OpenAI()\n",
"\n",
"# request a bunch of completions in a loop\n",
"for _ in range(100):\n",
" openai.ChatCompletion.create(\n",
" client.chat.completions.create(\n",
" model=\"gpt-3.5-turbo\",\n",
" messages=[{\"role\": \"user\", \"content\": \"Hello\"}],\n",
" max_tokens=10,\n",
" )\n"
" )"
]
},
{
@ -175,53 +117,35 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<OpenAIObject text_completion id=cmpl-5oowO391reUW8RGVfFyzBM1uBs4A5 at 0x10d8cae00> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"length\",\n",
" \"index\": 0,\n",
" \"logprobs\": null,\n",
" \"text\": \" a little girl dreamed of becoming a model.\\n\\nNowadays, that dream\"\n",
" }\n",
" ],\n",
" \"created\": 1662793900,\n",
" \"id\": \"cmpl-5oowO391reUW8RGVfFyzBM1uBs4A5\",\n",
" \"model\": \"text-davinci-002\",\n",
" \"object\": \"text_completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 16,\n",
" \"prompt_tokens\": 5,\n",
" \"total_tokens\": 21\n",
" }\n",
"}"
"ChatCompletion(id='chatcmpl-8PAu6anX2JxQdYmJRzps38R8u0ZBC', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content='in a small village nestled among green fields and rolling hills, there lived a kind-hearted and curious young girl named Lily. Lily was known for her bright smile and infectious laughter, bringing joy to everyone around her.\\n\\nOne sunny morning, as Lily played in the meadows, she stumbled upon a mysterious book tucked away beneath a tall oak tree. Intrigued, she picked it up and dusted off its weathered cover to reveal intricate golden patterns. Without hesitation, she opened it, discovering that its pages were filled with magical tales and enchanting adventures.\\n\\nAmong the stories she found, one particularly caught her attention—a tale of a long-lost treasure hidden deep within a mysterious forest. Legend had it that whoever found this hidden treasure would be granted one wish, no matter how big or small. Excited by the prospect of finding such treasure and fulfilling her wildest dreams, Lily decided to embark on a thrilling journey to the forest.\\n\\nGathering her courage, Lily told her parents about the magical book and her quest to find the hidden treasure. Though concerned for their daughter\\'s safety, they couldn\\'t help but admire her spirit and determination. They hugged her tightly and blessed her with love and luck, promising to await her return.\\n\\nEquipped with a map she found within the book, Lily ventured into the depths of the thick forest. The trees whispered tales of forgotten secrets, and the enchanted creatures hidden within watched her every step. But Lily remained undeterred, driven by her desire to discover what lay ahead.\\n\\nDays turned into weeks as Lily traversed through dense foliage, crossed swift rivers, and climbed treacherous mountains. She encountered mystical beings who offered guidance and protection along her perilous journey. With their help, she overcame countless obstacles and grew braver with each passing day.\\n\\nFinally, after what felt like an eternity, Lily reached the heart of the forest. There, beneath a jeweled waterfall, she found the long-lost treasure—a magnificent chest adorned with sparkling gemstones. Overwhelmed with excitement, she gently opened the chest to reveal a brilliant light that illuminated the forest.\\n\\nWithin the glow, a wise voice echoed, \"You have proven your courage and pure heart, young Lily. Make your wish, and it shall be granted.\"\\n\\nLily thought deeply about her wish, realizing that her true treasure was the love and happiness she felt in her heart. Instead of making a wish for herself, she asked for the wellbeing and prosperity of her village, spreading joy and harmony to everyone living there.\\n\\nAs the light faded, Lily knew her quest was complete. She retraced her steps through the forest, returning home to find her village flourishing. Fields bloomed with vibrant flowers, and laughter filled the air.\\n\\nThe villagers greeted Lily with open arms, recognizing her selflessness and the magic she had brought into their lives. From that day forward, they told the tale of Lily\\'s journey, celebrating her as a heroine who embodied the power of love, kindness, and the belief that true treasure lies within oneself.\\n\\nAnd so, the story of Lily became an everlasting legend, inspiring generations to follow their dreams, be selfless, and find the true treasures that lie within their hearts.', role='assistant', function_call=None, tool_calls=None))], created=1701010806, model='gpt-3.5-turbo-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=641, prompt_tokens=12, total_tokens=653))"
]
},
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import openai # for OpenAI API calls\n",
"from openai import OpenAI # for OpenAI API calls\n",
"client = OpenAI()\n",
"from tenacity import (\n",
" retry,\n",
" stop_after_attempt,\n",
" wait_random_exponential,\n",
") # for exponential backoff\n",
"\n",
"\n",
"@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))\n",
"def completion_with_backoff(**kwargs):\n",
" return openai.Completion.create(**kwargs)\n",
" return client.chat.completions.create(**kwargs)\n",
"\n",
"\n",
"completion_with_backoff(model=\"text-davinci-002\", prompt=\"Once upon a time,\")\n"
"completion_with_backoff(model=\"gpt-3.5-turbo\", messages=[{\"role\": \"user\", \"content\": \"Once upon a time,\"}])"
]
},
{
@ -237,49 +161,33 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<OpenAIObject text_completion id=cmpl-5oowPhIdUvshEsF1rBhhwE9KFfI3M at 0x111043680> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"length\",\n",
" \"index\": 0,\n",
" \"logprobs\": null,\n",
" \"text\": \" two children lived in a poor country village. In the winter, the temperature would\"\n",
" }\n",
" ],\n",
" \"created\": 1662793901,\n",
" \"id\": \"cmpl-5oowPhIdUvshEsF1rBhhwE9KFfI3M\",\n",
" \"model\": \"text-davinci-002\",\n",
" \"object\": \"text_completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 16,\n",
" \"prompt_tokens\": 5,\n",
" \"total_tokens\": 21\n",
" }\n",
"}"
"ChatCompletion(id='chatcmpl-8PAwkg7Q9pPeAkvVuAZ8AyA108WhR', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content=\"in a small village, there lived a young girl named Lily. She had fiery red hair, lively green eyes, and a spirit as wild as the rushing river nearby. Lily was known for her curious nature and her desire to explore the world beyond the village boundaries.\\n\\nOne day, while playing near the river, Lily spotted an injured bird nested on a branch. Its wing was broken, and it seemed unable to fly away. Lily's heart filled with sadness, and she knew she couldn't leave the bird alone.\\n\\nCarefully, she climbed up the tree and gently placed the bird inside her pocket. Lily brought it home and made a cozy bed for it in a small wooden box. She named the bird Ruby, after its shimmering red feathers.\\n\\nDays turned into weeks, and Ruby's wing slowly healed under Lily's constant care and attention. As they spent time together, a deep bond grew between them. Ruby would chirp happily whenever Lily approached, and she would spend hours talking to the bird, sharing stories of her adventures, dreams, and fears.\\n\\nOne evening, as Lily was about to go to bed, a peculiar thing happened. Ruby hopped out of his box and fluttered onto the windowsill. He turned to face Lily with his bright eyes and began to sing a beautiful melody.\\n\\nLily was astonished. Never before had she heard Ruby sing. The tune was so captivating that it filled the room and made the quiet night come alive. The magical music seemed to touch Lily's soul, awakening a deep sense of wonder and wanderlust within her.\\n\\nFilled with an undeniable urge to explore, Lily decided it was time to go on an adventure with her newfound friend, Ruby. She packed a small bag and bid farewell to her family and friends, promising to return one day.\\n\\nTogether, Lily and Ruby embarked on a grand journey, soaring across expansive skies, diving into lush forests, and exploring hidden caves. They encountered magnificent landscapes, unique creatures, and encountered kind-hearted individuals who shared their wisdom and stories.\\n\\nThroughout their journey, Ruby's song continued to inspire and guide them. It became a symbol of hope, reminding them to embrace bravery, follow their dreams, and always remain true to themselves.\\n\\nAs the years passed, Lily and Ruby traversed the world, weaving their stories into the tapestry of time. They became renowned for their extraordinary bond and the magic they shared with everyone they encountered.\\n\\nEventually, it was time for Lily to return to her village, a place eagerly awaiting her return. She had grown wise, learned many lessons, and gained a deeper understanding of herself and the world around her.\\n\\nWith Ruby perched on her shoulder, they descended upon the village like a ray of sunshine, bringing joy and wonder to every heart. Lily shared the wisdom she had acquired and inspired others to embrace their own adventures, no matter how big or small.\\n\\nAnd so, the tale of Lily and Ruby became legend, passed down from generation to generation. Their story reminded people to cherish the connections they make, to nurture their dreams, and to believe in the magic that lies within them.\", role='assistant', function_call=None, tool_calls=None))], created=1701010970, model='gpt-3.5-turbo-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=621, prompt_tokens=12, total_tokens=633))"
]
},
"execution_count": 2,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import backoff # for exponential backoff\n",
"import openai # for OpenAI API calls\n",
"from openai import OpenAI # for OpenAI API calls\n",
"import openai\n",
"client = OpenAI() \n",
"\n",
"\n",
"@backoff.on_exception(backoff.expo, openai.error.RateLimitError)\n",
"@backoff.on_exception(backoff.expo, openai.RateLimitError)\n",
"def completions_with_backoff(**kwargs):\n",
" return openai.Completion.create(**kwargs)\n",
" return client.chat.completions.create(**kwargs)\n",
"\n",
"\n",
"completions_with_backoff(model=\"text-davinci-002\", prompt=\"Once upon a time,\")\n"
"completions_with_backoff(model=\"gpt-3.5-turbo\", messages=[{\"role\": \"user\", \"content\": \"Once upon a time,\"}])\n"
]
},
{
@ -293,34 +201,16 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<OpenAIObject text_completion id=cmpl-5oowRsCXv3AkUgVJyyo3TQrVq7hIT at 0x111024220> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"length\",\n",
" \"index\": 0,\n",
" \"logprobs\": null,\n",
" \"text\": \" a man decided to greatly improve his karma by turning his life around.\\n\\n\"\n",
" }\n",
" ],\n",
" \"created\": 1662793903,\n",
" \"id\": \"cmpl-5oowRsCXv3AkUgVJyyo3TQrVq7hIT\",\n",
" \"model\": \"text-davinci-002\",\n",
" \"object\": \"text_completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 16,\n",
" \"prompt_tokens\": 5,\n",
" \"total_tokens\": 21\n",
" }\n",
"}"
"ChatCompletion(id='chatcmpl-8PAxGvV3GbLpnOoKSvJ00XCUdOglM', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content=\"in a faraway kingdom, there lived a young princess named Aurora. She was known for her beauty, grace, and kind heart. Aurora's kingdom was filled with lush green meadows, towering mountains, and sparkling rivers. The princess loved spending time exploring the enchanting forests surrounding her castle.\\n\\nOne day, while Aurora was wandering through the woods, she stumbled upon a hidden clearing. At the center stood a majestic oak tree, its branches reaching towards the sky. Aurora approached the tree with curiosity, and as she got closer, she noticed a small door at its base.\\n\\nIntrigued, she gently pushed open the door and was amazed to find herself in a magical realm. The forest transformed into a breathtaking wonderland, with colorful flowers blooming in every direction and woodland creatures frolicking joyously. Aurora's eyes widened with wonder as she explored this extraordinary world.\\n\\nAs she explored further, Aurora came across a small cottage in the distance. Curiosity overcame her, and she cautiously approached the cottage. To her surprise, an elderly woman with twinkling eyes and a warm smile stood in the doorway, welcoming her inside.\\n\\nThe woman revealed herself to be a fairy named Luna. Luna informed Aurora that she had been chosen to undertake a quest that would bring harmony to both her kingdom and the mystical realm. Aurora, eager to help, listened intently as Luna explained that a powerful enchantress had cast a spell on the kingdom, causing darkness and despair to loom over the land.\\n\\nTo break the curse, Aurora had to embark on a journey to retrieve a magical crystal hidden deep within the heart of an ancient cave. Without hesitation, the princess agreed and bid farewell to Luna, promising to return victorious.\\n\\nWith newfound determination, Aurora set off on her quest. Along the way, she encountered numerous challenges and obstacles but never lost hope. She often drew strength from the enchanting woodland creatures who accompanied her on this journey, reminding her that she was not alone.\\n\\nAfter a long and arduous journey, Aurora reached the entrance of the ancient cave. Inside, she faced a series of tests that pushed her physical and emotional limits. With sheer determination and unwavering courage, she overcame each trial, paving her way to the crystal's resting place.\\n\\nAs Aurora held the crystal in her hands, its warmth spread through her body. The artifact contained unimaginable power that could shatter the enchantress's curse and restore light to her kingdom. Brimming with joy and newfound strength, she made her way back to Luna's cottage.\\n\\nUpon her return, Aurora and Luna performed a powerful ritual, using the crystal's magic to break the curse. Waves of light and color spread across the kingdom, banishing darkness and despair. The once-gray skies turned blue, and laughter filled the air once again. The kingdom rejoiced, thanking Princess Aurora for her bravery and selflessness.\\n\\nFrom that day forward, Aurora was hailed as a hero, not only in her kingdom but also in the mystical realm. She continued to be a beacon of hope and kindness, reminding everyone that true courage lies within, waiting to be awakened.\\n\\nAnd so, Princess Aurora's tale lived on as a timeless reminder that even in the darkest of times, there is always light and hope to be found.\", role='assistant', function_call=None, tool_calls=None))], created=1701011002, model='gpt-3.5-turbo-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=657, prompt_tokens=12, total_tokens=669))"
]
},
"execution_count": 3,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
@ -331,6 +221,8 @@
"import time\n",
"\n",
"import openai\n",
"from openai import OpenAI\n",
"client = OpenAI()\n",
"\n",
"# define a retry decorator\n",
"def retry_with_exponential_backoff(\n",
@ -339,7 +231,7 @@
" exponential_base: float = 2,\n",
" jitter: bool = True,\n",
" max_retries: int = 10,\n",
" errors: tuple = (openai.error.RateLimitError,),\n",
" errors: tuple = (openai.RateLimitError,),\n",
"):\n",
" \"\"\"Retry a function with exponential backoff.\"\"\"\n",
"\n",
@ -379,10 +271,10 @@
"\n",
"@retry_with_exponential_backoff\n",
"def completions_with_backoff(**kwargs):\n",
" return openai.Completion.create(**kwargs)\n",
" return client.chat.completions.create(**kwargs)\n",
"\n",
"\n",
"completions_with_backoff(model=\"text-davinci-002\", prompt=\"Once upon a time,\")\n"
"completions_with_backoff(model=\"gpt-3.5-turbo\", messages=[{\"role\": \"user\", \"content\": \"Once upon a time,\"}])"
]
},
{
@ -407,34 +299,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<OpenAIObject text_completion id=cmpl-5oowVVZnAzdCPtUJ0rifeamtLcZRp at 0x11b2c7680> JSON: {\n",
" \"choices\": [\n",
" {\n",
" \"finish_reason\": \"length\",\n",
" \"index\": 0,\n",
" \"logprobs\": null,\n",
" \"text\": \" there was an idyllic little farm that sat by a babbling brook\"\n",
" }\n",
" ],\n",
" \"created\": 1662793907,\n",
" \"id\": \"cmpl-5oowVVZnAzdCPtUJ0rifeamtLcZRp\",\n",
" \"model\": \"text-davinci-002\",\n",
" \"object\": \"text_completion\",\n",
" \"usage\": {\n",
" \"completion_tokens\": 16,\n",
" \"prompt_tokens\": 5,\n",
" \"total_tokens\": 21\n",
" }\n",
"}"
"ChatCompletion(id='chatcmpl-8PAyCR1axKsomV0e349XiCN1Z81pH', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content=\"in a small village, there lived a young girl named Maya. Maya was known for her kindness and love for nature. She spent hours exploring the forests surrounding the village, admiring the vibrant flowers and talking to the animals.\\n\\nOne sunny day, as Maya was picking wildflowers, she stumbled upon a wounded blackbird with a broken wing. Feeling sorry for the bird, Maya gently picked it up and cradled it in her hands. She knew she had to help the bird, so she hurried back to her cottage.\\n\\nMaya set up a cozy nest for the blackbird and carefully splinted its wing. She fed it worms and berries, doing everything she could to nurse it back to health. Each day, she would sing lullabies and tell stories to keep the blackbird company. Slowly, the bird's wing healed, and before long, it was ready to fly again.\\n\\nOn a beautiful morning, Maya opened the window of her cottage and released the blackbird into the sky. As the bird soared into the air, Maya's heart filled with joy and gratitude. Little did she know, this act of kindness would change her life forever.\\n\\nThe following night, a mysterious glowing light illuminated Maya's room. Startled, she sat up and saw a magical creature standing before her. It was a fairy, tiny yet radiating warmth and light.\\n\\nThe fairy introduced herself as Luna, the Guardian of the Forest. She had witnessed Maya's kindness towards the blackbird and had been watching her ever since. Luna explained that she had come to reward Maya for her selflessness.\\n\\nWith a wave of her wand, Luna granted Maya the ability to communicate with animals. Maya's eyes widened with amazement as she realized she could now understand the language of nature. Birds chirped melodies, rabbits whispered secrets, and trees shared their ancient wisdom.\\n\\nOver time, Maya's ability made her beloved by both humans and animals. Farmers sought her advice on how to care for their crops, and children flocked to her for stories of her enchanting encounters with the forest creatures. Maya used her gift to teach others about the importance of living in harmony with nature.\\n\\nAs years passed, Maya became known as the Village Guardian. She dedicated herself to protecting the surrounding forests from harm and educating others on sustainable living. The village flourished under Maya's guidance, and animals and humans lived side by side peacefully.\\n\\nAnd so, Maya's story became a legend passed down through generations. Her kindness, love for nature, and her ability to communicate with animals inspired people to treat the world around them with compassion and care.\", role='assistant', function_call=None, tool_calls=None))], created=1701011060, model='gpt-3.5-turbo-0613', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=524, prompt_tokens=12, total_tokens=536))"
]
},
"execution_count": 4,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
@ -442,7 +316,8 @@
"source": [
"# imports\n",
"import time\n",
"import openai\n",
"from openai import OpenAI\n",
"client = OpenAI()\n",
"\n",
"# Define a function that adds a delay to a Completion API call\n",
"def delayed_completion(delay_in_seconds: float = 1, **kwargs):\n",
@ -452,7 +327,7 @@
" time.sleep(delay_in_seconds)\n",
"\n",
" # Call the Completion API and return the result\n",
" return openai.Completion.create(**kwargs)\n",
" return client.chat.completions.create(**kwargs)\n",
"\n",
"\n",
"# Calculate the delay based on your rate limit\n",
@ -461,8 +336,8 @@
"\n",
"delayed_completion(\n",
" delay_in_seconds=delay,\n",
" model=\"text-davinci-002\",\n",
" prompt=\"Once upon a time,\"\n",
" model=\"gpt-3.5-turbo\",\n",
" messages=[{\"role\": \"user\", \"content\": \"Once upon a time,\"}]\n",
")\n"
]
},
@ -487,43 +362,44 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Once upon a time, before there were grandiloquent tales of the massacre at Fort Mims, there were stories of\n",
"Once upon a time, a full-sized search and rescue was created. However, CIDIs are the addition of requiring\n",
"Once upon a time, Schubert was hot with the films. “Schubert sings of honey, flowers,\n",
"Once upon a time, you could watch these films on your VCR, sometimes years after their initial theatrical release, and there\n",
"Once upon a time, there was a forest. In that forest, the forest animals ruled. The forest animals had their homes\n",
"Once upon a time, there were two programs that complained about false positive scans. Peacock and Midnight Manager alike, only\n",
"Once upon a time, a long, long time ago, tragedy struck. it was the darkest of nights, and there was\n",
"Once upon a time, when Adam was a perfect little gentleman, he was presented at Court as a guarantee of good character.\n",
"Once upon a time, Adam and Eve made a mistake. They ate the fruit from the tree of immortality and split the consequences\n",
"Once upon a time, there was a set of programming fundamental principles known as the \"X model.\" This is a set of\n"
"Once upon a time,in a small village nestled between rolling green hills, there lived a young girl named Lily. She had\n",
"Once upon a time,in a small village nestled in the heart of a lush forest, lived a young girl named Evelyn.\n",
"Once upon a time,in a faraway kingdom, there lived a young princess named Aurora. She was known for her kind\n",
"Once upon a time,in a faraway kingdom called Enchantia, there lived a young girl named Ella. Ella was\n",
"Once upon a time,in a small village nestled among the rolling hills, lived a young woman named Lucy. Lucy was known\n",
"Once upon a time,in a small village nestled between rolling hills, there lived a young girl named Ava. Ava was a\n",
"Once upon a time,in a faraway kingdom, there lived a wise and just king named Arthur. King Arthur ruled over\n",
"Once upon a time,in a small village nestled among towering mountains, lived a young girl named Lily. She was known for\n",
"Once upon a time,in a small village nestled in the heart of a lush forest, there lived a young girl named Lily\n",
"Once upon a time,in a far-off kingdom, there lived a kind and beloved queen named Isabella. She ruled with\n"
]
}
],
"source": [
"import openai # for making OpenAI API requests\n",
"from openai import OpenAI # for making OpenAI API requests\n",
"client = OpenAI() \n",
"\n",
"\n",
"num_stories = 10\n",
"prompt = \"Once upon a time,\"\n",
"content = \"Once upon a time,\"\n",
"\n",
"# serial example, with one story completion per request\n",
"for _ in range(num_stories):\n",
" response = openai.Completion.create(\n",
" model=\"curie\",\n",
" prompt=prompt,\n",
" response = client.chat.completions.create(\n",
" model=\"gpt-3.5-turbo\",\n",
" messages=[{\"role\": \"user\", \"content\": content}],\n",
" max_tokens=20,\n",
" )\n",
"\n",
" # print story\n",
" print(prompt + response.choices[0].text)\n"
" print(content + response.choices[0].message.content)\n"
]
},
{
@ -535,35 +411,36 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Once upon a time, there were two sisters, Eliza Pickering and Ariana 'Ari' Lucas. When these lovely\n",
"Once upon a time, Keene was stung by a worm — actually, probably a python — snaking through his leg\n",
"Once upon a time, there was a professor of physics during the depression. It was difficult, during this time, to get\n",
"Once upon a time, before you got sick, you told stories to all and sundry, and your listeners believed in you\n",
"Once upon a time, there was one very old nice donkey. He was incredibly smart, in a very old, kind of\n",
"Once upon a time, the property of a common lodging house was a common cup for all the inhabitants. Betimes a constant\n",
"Once upon a time, in an unspecified country, there was a witch who had an illegal product. It was highly effective,\n",
"Once upon a time, a long time ago, I turned 13, my beautiful dog Duncan swept me up into his jaws like\n",
"Once upon a time, as a thoroughly reformed creature from an army of Nazis, he took On Judgement Day myself and his\n",
"Once upon a time, Capcom made a game for the Atari VCS called Missile Command. While it was innovative at the time\n"
"Once upon a time, I lived in hope. I convinced myself I knew best, because, naive as it might sound,\n",
"Once upon a time, Thierry Henry was invited to have a type of frosty exchange with English fans, in which\n",
"Once upon a time, and a long time ago as well, PV was passively cooled because coils cooled by use of metal driving\n",
"Once upon a time, there was a land called Texas. It was about the size of Wisconsin. It contained, however,\n",
"Once upon a time, there was an old carpenter who had three sons. The locksmith never learned to read or write\n",
"Once upon a time, there was a small farming town called Moonridge Village, far West across the great vast plains that lay\n",
"Once upon a time, Californias shorelines, lakes, and valleys were host to expanses of untamed wilderness\n",
"Once upon a time, she said. It started with a simple question: Why dont we know any stories?\n",
"Once upon a time, when I was a young woman, there was a movie named Wuthering Heights. Stand by alleges\n",
"Once upon a time, a very long time I mean, in the year 1713, died a beautiful Duchess called the young\n"
]
}
],
"source": [
"import openai # for making OpenAI API requests\n",
"from openai import OpenAI # for making OpenAI API requests\n",
"client = OpenAI() \n",
"\n",
"\n",
"num_stories = 10\n",
"prompts = [\"Once upon a time,\"] * num_stories\n",
"\n",
"# batched example, with 10 stories completions per request\n",
"response = openai.Completion.create(\n",
"response = client.completions.create(\n",
" model=\"curie\",\n",
" prompt=prompts,\n",
" max_tokens=20,\n",
@ -601,7 +478,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.9 ('openai')",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -615,7 +492,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9 (main, Dec 7 2021, 18:04:56) \n[Clang 13.0.0 (clang-1300.0.29.3)]"
"version": "3.10.8"
},
"orig_nbformat": 4,
"vscode": {

Loading…
Cancel
Save