0
0
Prompt Engineering / GenAIml~20 mins

Streaming responses in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Streaming Response Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main benefit of streaming responses in AI models?

Imagine you are chatting with an AI assistant that starts answering your question immediately, instead of waiting to finish the whole answer. What is the main benefit of this streaming response?

AIt allows the AI to learn from your feedback instantly during the response.
BIt improves the accuracy of the AI model's final answer.
CIt reduces the waiting time by sending partial answers as soon as they are ready.
DIt compresses the data to use less internet bandwidth.
Attempts:
2 left
💡 Hint

Think about how you feel when you get some information quickly instead of waiting for everything.

Predict Output
intermediate
2:00remaining
What is the output of this streaming simulation code?

Consider this Python code simulating streaming output from an AI model. What will it print?

Prompt Engineering / GenAI
import time

def stream_response():
    parts = ['Hello', ', ', 'this ', 'is ', 'streamed ', 'text.']
    for part in parts:
        print(part, end='', flush=True)
        time.sleep(0.1)

stream_response()
AHello, this is streamed text
B
Hello
, 
this 
is 
streamed 
text.
C.txet demaerts si siht ,olleH
DHello, this is streamed text.
Attempts:
2 left
💡 Hint

Look at how print is used with end='' and flush=True.

Model Choice
advanced
2:00remaining
Which model architecture is best suited for streaming text generation?

You want to build an AI that generates text word by word and sends each word immediately as it is created. Which model type is best for this streaming task?

ATransformer with full sequence attention computed before output
BRecurrent Neural Network (RNN) that processes input step-by-step
CConvolutional Neural Network (CNN) for image classification
DFeedforward Neural Network with no memory
Attempts:
2 left
💡 Hint

Think about which model can generate output one step at a time.

Metrics
advanced
2:00remaining
Which metric best measures the quality of streaming text generation?

When evaluating streaming text generation, which metric helps measure how well the generated text matches expected text over time?

ABLEU score comparing generated and reference text n-grams
BMean Squared Error between predicted and actual token IDs
CPerplexity measuring how surprised the model is by the next token
DAccuracy of classifying text sentiment
Attempts:
2 left
💡 Hint

Think about comparing generated sentences to reference sentences.

🔧 Debug
expert
2:30remaining
Why does this streaming code cause a delay before any output?

Look at this Python code meant to stream words with a delay between each. However, it waits fully before printing anything. Why?

Prompt Engineering / GenAI
import time

def stream_words(words):
    output = ''
    for w in words:
        output += w + ' '
        time.sleep(0.5)
    print(output)

stream_words(['This', 'is', 'streamed', 'text'])
AThe print is outside the loop, so output prints only after all words are added.
BThe time.sleep call blocks printing until the loop finishes.
CThe output string is not flushed after each word, causing buffering.
DThe function is missing a yield statement to stream words.
Attempts:
2 left
💡 Hint

Check where the print statement is placed relative to the loop.