async def streaming_prediction() -> str:
    """Streaming Text Example with a Large Language Model"""

    model = GenerativeModel(
        model_name="gemini-1.5-flash-001",
        system_instruction=[
            "You are a helpful language translator.",
            "Your mission is to translate text in English to French.",
        ],
    )

    prompt = """
    User input: I like bagels.
    Answer:
    """

    contents = [prompt]

    response = await model.generate_content_async(contents, stream=True)
    async for chunk in response:
        print(chunk.text)
Streaming Text Example with a Large Language Model
packages/sample-app/sample_app/vertexai_streaming.py