MirascopeLilypad

mirascope.core.base.call_response

Module call_response

This module contains the base call response class.

Function transform_tool_outputs

Parameters

NameTypeDescription
fn(type[_BaseCallResponseT], Sequence[tuple[_BaseToolT, str]]) => list[_ToolMessageParamT]-

Returns

TypeDescription
(type[_BaseCallResponseT], Sequence[tuple[_BaseToolT, JsonableType]]) => list[_ToolMessageParamT]-

Class BaseCallResponse

A base abstract interface for LLM call responses.

Bases: BaseModel, Generic[_ResponseT, _BaseToolT, _ToolSchemaT, _BaseDynamicConfigT, _MessageParamT, _CallParamsT, _UserMessageParamT, _BaseMessageParamConverterT], ABC

Attributes

NameTypeDescription
metadataMetadata-
response_ResponseT-
tool_typeslist[type[_BaseToolT]] | None-
prompt_templatestr | None-
fn_argsdict[str, Any]-
dynamic_config_BaseDynamicConfigT-
messagesSkipValidation[list[_MessageParamT]]-
call_paramsSkipValidation[_CallParamsT]-
call_kwargsBaseCallKwargs[_ToolSchemaT]-
user_message_param_UserMessageParamT | None-
start_timefloat-
end_timefloat-
model_configConfigDict(extra='allow', arbitrary_types_allowed=True)-
contentstrShould return the string content of the response. If there are multiple choices in a response, this method should select the 0th choice and return it's string content. If there is no string content (e.g. when using tools), this method must return the empty string.
finish_reasonslist[str] | NoneShould return the finish reasons of the response. If there is no finish reason, this method must return None.
modelstr | NoneShould return the name of the response model.
idstr | NoneShould return the id of the response.
usageAnyShould return the usage of the response. If there is no usage, this method must return None.
input_tokensint | float | NoneShould return the number of input tokens. If there is no input_tokens, this method must return None.
cached_tokensint | float | NoneShould return the number of cached tokens. If there is no cached_tokens, this method must return None.
output_tokensint | float | NoneShould return the number of output tokens. If there is no output_tokens, this method must return None.
cost_metadataCostMetadataGet metadata required for cost calculation.
costfloat | NoneCalculate the cost of this API call using the unified calculate_cost function.
providerProviderGet the provider used for this API call.
message_paramAnyReturns the assistant's response as a message parameter.
toolslist[_BaseToolT] | NoneReturns the tools for the 0th choice message.
tool_BaseToolT | NoneReturns the 0th tool for the 0th choice message.
common_finish_reasonslist[FinishReason] | NoneProvider-agnostic finish reasons.
common_message_paramBaseMessageParamProvider-agnostic assistant message param.
common_user_message_paramBaseMessageParam | NoneProvider-agnostic user message param.
common_messageslist[BaseMessageParam]Provider-agnostic list of messages.
common_toolslist[Tool] | NoneProvider-agnostic tools.
common_usageUsage | NoneProvider-agnostic usage info.

Function serialize_tool_types

Parameters

NameTypeDescription
selfAny-
tool_typeslist[type[_BaseToolT]] | None-
infoFieldSerializationInfo-

Returns

TypeDescription
list[dict[str, str]]-

Function tool_message_params

Returns the tool message parameters for tool call results.

Parameters

NameTypeDescription
clsAny-
tools_and_outputsSequence[tuple[_BaseToolT, str]]The sequence of tools and their outputs from which the tool message parameters should be constructed.

Returns

TypeDescription
list[Any]-