mirascope.core.bedrock.call_response
This module contains the BedrockCallResponse
class.
Usage
Class BedrockCallResponse
A convenience wrapper around the Bedrock ChatCompletion
response.
When calling the Bedrock API using a function decorated with bedrock_call
, the
response will be an BedrockCallResponse
instance with properties that allow for
more convenience 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")
@prompt_template("Recommend a {genre} book")
def recommend_book(genre: str):
...
response = recommend_book("fantasy") # response is an `BedrockCallResponse` instance
print(response.content)
Bases:
BaseCallResponse[SyncConverseResponseTypeDef | AsyncConverseResponseTypeDef, BedrockTool, ToolTypeDef, AsyncBedrockDynamicConfig | BedrockDynamicConfig, InternalBedrockMessageParam, BedrockCallParams, UserMessageTypeDef, BedrockMessageParamConverter]Attributes
Name | Type | Description |
---|---|---|
response | SkipValidation[SyncConverseResponseTypeDef | AsyncConverseResponseTypeDef] | - |
message | SyncMessageTypeDef | AsyncMessageTypeDef | None | Returns the message of the response. |
content | str | Returns the content of the chat completion for the 0th choice. |
finish_reasons | list[str] | Returns the finish reasons of the response. |
model | str | Returns the name of the response model. |
id | str | Returns the id of the response. |
usage | TokenUsageTypeDef | Returns the usage of the chat completion. |
input_tokens | int | None | Returns the number of input tokens. |
cached_tokens | int | None | Returns the number of cached tokens. |
output_tokens | int | None | Returns the number of output tokens. |
message_param | SerializeAsAny[AssistantMessageTypeDef] | Returns the assistants's response as a message parameter. |
tools | list[BedrockTool] | None | Returns any available tool calls as their `BedrockTool` definition. |
tool | BedrockTool | None | Returns the 0th tool for the 0th choice message. |
common_finish_reasons | list[FinishReason] | None | - |
common_message_param | BaseMessageParam | - |
common_user_message_param | BaseMessageParam | None | - |
cost_metadata | CostMetadata | Get metadata required for cost calculation. |
Function tool_message_params
Returns the tool message parameters for tool call results.
Parameters
Name | Type | Description |
---|---|---|
cls | Any | - |
tools_and_outputs | Sequence[tuple[BedrockTool, str]] | The sequence of tools and their outputs from which the tool message parameters should be constructed. |
Returns
Type | Description |
---|---|
list[ToolResultBlockMessageTypeDef] | The list of constructed `ChatCompletionToolMessageParam` parameters. |