mirascope.core.bedrock.stream¶
The BedrockStream
class for convenience around streaming LLM calls.
Usage Documentation
BedrockStream
¶
Bases: BaseStream[BedrockCallResponse, BedrockCallResponseChunk, UserMessageTypeDef, AssistantMessageTypeDef, ToolUseBlockMessageTypeDef, InternalBedrockMessageParam, BedrockTool, ToolTypeDef, AsyncBedrockDynamicConfig | BedrockDynamicConfig, BedrockCallParams, StopReasonType]
A class for convenience around streaming Bedrock LLM calls.
Example:
from mirascope.core import prompt_template
from mirascope.core.bedrock import bedrock_call
@bedrock_call("gpt-4o-mini", stream=True)
@prompt_template("Recommend a {genre} book")
def recommend_book(genre: str):
...
stream = recommend_book("fantasy") # returns `BedrockStream` instance
for chunk, _ in stream:
print(chunk.content, end="", flush=True)
Source code in mirascope/core/bedrock/stream.py
construct_call_response
¶
construct_call_response() -> BedrockCallResponse
Constructs the call response from a consumed BedrockStream.
Raises:
Type | Description |
---|---|
ValueError
|
if the stream has not yet been consumed. |