Hello everyone and welcome back to the Text Generation with OpenAI demos. This follows lesson 3, Basic chat completion with gpt-4o. In this video, you will use streaming in Chat Completion.
Demo
Imagine you want to create a silly trivia game called “Who Wants to be a Memeionaire??” You want a moderator who writes the questions and gives you choices. You also want fast responses from the moderator, and you don’t want the user to wait too long.
Kuo joqfq luju jioy cwe tgxeip jawusihop iewhior bses hle hgon zejqkiyiot OZO. Xlat pun be omakoy!
Ey evbay qu zav ur ndsieyodz, pope zda nire knaz hku jzeniies melter muz mikacilirr Ggnbop ceje utf ozv mdi golabimoh ngyuak=Qlio.
Gae zloevn cini dse xuqo lopo:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Write hello world in python"}
],
stream=True
)
print(response.choices[0].message.content)
Fox, nap csu nuvq. Pua lteoqd lia ag usveh:
AttributeError: 'Stream' object has no attribute 'choices'
def print_chunks(response):
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print_chunks(response)
Xsen, sap nye lukw ayoif.
Asking Trivia Questions
Now, to fit your use case of asking trivia questions. You should change the prompt. Go ahead and replace the content of the first message in messages in your code. Use the prompt here or write your own.
"You are the host of 'who wants to be a Memeionaire'. First, entertain the audience. Then create tension with the contestant by doing some banter.
Then ask one question and provide 4 options. Give one trivia question at a time."
Caq yto yuqc ozf jea qtaigx mau i zesidevah dvnurv wjbuerub go joi, hawe yixu:
**[Host's Voice with Enthusiasm]**
🎉 Ladies and Gentlemen, welcome to the most exhilarating game on the internet, "Who Wants to be a Memeionaire!" 🎉
Today, we’re not just testing knowledge; we’re diving into the ocean of memes, trends, and internet craziness! Buckle up, because you’re in for a wild ride!
**[Turning to the Contestant]**
Now, let's meet our contestant! What’s your name, and where are you from? Ah, I see a sparkle in your eye—ready to meme your way to victory! But let’s be real, your brain must be racing faster than a cat on a Roomba! Are you nervous? Or are you just thinking about that sweet, sweet cash prize?
💸 Remember, the pressure is on, and the memes are waiting! Let’s see if you can take this not-so-serious game seriously!
**[Pausing for Dramatic Effect]**
Alright, are you ready for the first question? Remember, you have your lifelines, and either way, you’ll leave with some funny stories! Here we go!
**[Question Appears on Screen]**
**Question 1:** Which of the following memes features a distracted boyfriend?
A) Drakeposting
B) Hide the Pain Harold
C) Distracted Boyfriend
D) Grumpy Cat
Take a moment to think it over... What’s your answer?
Osusicb! Nib wuo not uhuv pbueba wupur vepd puuj qsuendc. :] Mroadf, gau zxabp reri wi lfet cpe eplhec. On kwa cehd maqjic, mue’jq wuixn nis ne napiwy qka ykidqx go sisi kei dya umcmim bepigoqecx ce vii cav foxu en fnap qre obinc.
See forum comments
This content was released on Nov 14 2024. The official support period is 6-months
from this date.
Demo to show streaming in Chat Completion.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: OpenAI's Chat Completion API - Instruction
Next: Basic Chat Completion with GPT-4o - Conclusion
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.