mirascope.core.anthropic.call_response_chunk | Mirascope
MirascopeLilypad

mirascope.core.anthropic.call_response_chunk

Module call_response_chunk

This module contains the AnthropicCallResponseChunk class.

Usage

Attribute FinishReason

Type: Message.__annotations__['stop_reason']

Class AnthropicCallResponseChunk

A convenience wrapper around the Anthropic ChatCompletionChunk streamed chunks.

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

Example:

from mirascope.core import prompt_template
from mirascope.core.anthropic import anthropic_call


@anthropic_call("claude-3-5-sonnet-20240620", stream=True)
def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"


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

Bases:

BaseCallResponseChunk[MessageStreamEvent, FinishReason]

Attributes

NameTypeDescription
contentstrReturns the string content of the 0th message.
finish_reasonslist[FinishReason] | NoneReturns the finish reason of the response.
modelstr | NoneReturns the name of the response model.
idstr | NoneReturns the id of the response.
usageUsage | MessageDeltaUsage | NoneReturns the usage of the message.
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] | NoneProvider-agnostic finish reasons.