mirascope.core.anthropic.call_response_chunk¶
This module contains the AnthropicCallResponseChunk
class.
Usage Documentation
AnthropicCallResponseChunk
¶
Bases: BaseCallResponseChunk[MessageStreamEvent, FinishReason]
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)