mirascope.core.anthropic.stream
Module stream
The AnthropicStream
class for convenience around streaming LLM calls.
Usage
Attribute FinishReason
Type: Message.__annotations__['stop_reason']
Class AnthropicStream
A class for convenience around streaming Anthropic LLM calls.
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") # returns `AnthropicStream` instance
for chunk, _ in stream:
print(chunk.content, end="", flush=True)
Bases:
BaseStream[AnthropicCallResponse, AnthropicCallResponseChunk, MessageParam, MessageParam, MessageParam, MessageParam, AnthropicTool, ToolParam, AsyncAnthropicDynamicConfig | AnthropicDynamicConfig, AnthropicCallParams, FinishReason]Attributes
Name | Type | Description |
---|---|---|
cost_metadata | CostMetadata | Get metadata required for cost calculation. |
Function construct_call_response
Constructs the call response from a consumed AnthropicStream.
Parameters
Name | Type | Description |
---|---|---|
self | Any | - |
Returns
Type | Description |
---|---|
AnthropicCallResponse | - |