A. Streaming response must be looped over to get chunks, not printed directly.
B. The parameter should be stream=False to print response.
C. The model.generate method does not support streaming.
D. The prompt variable is missing.
Solution
Step 1: Understand streaming response type
With stream=True, the response is an iterable, not a complete string.
Step 2: Explain why print(response) is incorrect
Printing the iterable directly shows its object info, not the content chunks. You must loop over it to get data.
Final Answer:
Streaming response must be looped over to get chunks, not printed directly. -> Option A
Quick Check:
Print iterable directly shows object, loop to get data [OK]
Hint: Loop over streaming response; don't print it directly [OK]
Common Mistakes:
Printing streaming response directly
Setting stream=False to fix printing
Assuming model.generate lacks streaming support
5. You want to display AI-generated text to users as soon as possible using streaming. Which approach correctly combines streaming with real-time display in Python?
hard
A. Use stream=True but collect all chunks in a list before printing.
B. Use stream=True and loop over response, printing each chunk immediately.
C. Set stream=False and print the full response after generation.
D. Disable streaming and use a timer to print partial results.
Solution
Step 1: Understand real-time display with streaming
Streaming with stream=True allows receiving data chunks as they are generated.
Step 2: Explain how to display chunks immediately
Looping over the response and printing each chunk immediately shows output in real time to users.
Step 3: Compare other options
Using stream=True but collecting all chunks in a list before printing defeats real-time display. Setting stream=False waits for the full response. Using a timer without streaming is inefficient.
Final Answer:
Use stream=True and loop over response, printing each chunk immediately. -> Option B