mirascope.core.bedrock.call_response_chunk | Mirascope
MirascopeLilypad

mirascope.core.bedrock.call_response_chunk

This module contains the BedrockCallResponseChunk class.

Usage

Class BedrockCallResponseChunk

A convenience wrapper around the Bedrock ChatCompletionChunk streamed chunks.

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

Example:

from mirascope.core import prompt_template
from mirascope.core.bedrock import bedrock_call


@bedrock_call("anthropic.claude-3-haiku-20240307-v1:0", stream=True)
@prompt_template("Recommend a {genre} book")
def recommend_book(genre: str):
    ...


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

Bases:

BaseCallResponseChunk[StreamOutputChunk | AsyncStreamOutputChunk, FinishReason]

Attributes

NameTypeDescription
chunkSkipValidation[StreamOutputChunk | AsyncStreamOutputChunk]-
contentstrReturns the content for the 0th choice delta.
finish_reasonslist[FinishReason]Returns the finish reasons of the response.
modelstrReturns the name of the response model.
idstrReturns the id of the response.
usageTokenUsageTypeDef | NoneReturns the usage of the chat completion.
input_tokensint | NoneReturns the number of input tokens.
cached_tokensint | NoneReturns the number of cached tokens.
output_tokensint | NoneReturns the number of output tokens.
cost_metadataCostMetadataReturns the cost metadata.
common_finish_reasonslist[types.FinishReason] | None-