Skip to content

mirascope.core.vertex.call_response_chunk

This module contains the VertexCallResponseChunk class.

Usage Documentation

Streams

VertexCallResponseChunk

Bases: BaseCallResponseChunk[GenerationResponse, FinishReason]

A convenience wrapper around the Vertex AI streamed response chunks.

When calling the Vertex AI API using a function decorated with vertex_call and stream set to True, the stream will contain VertexCallResponseChunk instances with properties that allow for more convenient access to commonly used attributes.

Example:

from mirascope.core import prompt_template
from mirascope.core.vertex import vertex_call


@vertex_call("gemini-1.5-flash", stream=True)
def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"

stream = recommend_book("fantasy")  # response is an `VertexStream`
for chunk, _ in stream:
    print(chunk.content, end="", flush=True)

content property

content: str

Returns the chunk content for the 0th choice.

finish_reasons property

finish_reasons: list[FinishReason]

Returns the finish reasons of the response.

model property

model: None

Returns the model name.

vertex does not return model, so we return None

id property

id: str | None

Returns the id of the response.

vertex does not return an id

usage property

usage: None

Returns the usage of the chat completion.

vertex does not have Usage, so we return None

input_tokens property

input_tokens: None

Returns the number of input tokens.

output_tokens property

output_tokens: None

Returns the number of output tokens.