`enter code here`# Process streaming response
response_text = ""
for chunk in stream:
if hasattr(chunk, 'choices') and chunk.choices:
if hasattr(chunk.choices[0], 'delta'):
if hasattr(chunk.choices[0].delta, 'content'):
content = chunk.choices[0].delta.content
if content is not None:
print(content, end="", flush=True)
response_text += content
print(response_text)