mirascope.core.cohere.call_response | Mirascope
MirascopeLilypad

mirascope.core.cohere.call_response

This module contains the CohereCallResponse class.

Usage

Class CohereCallResponse

A convenience wrapper around the Cohere ChatCompletion response.

When calling the Cohere API using a function decorated with cohere_call, the response will be an CohereCallResponse instance with properties that allow for more convenience access to commonly used attributes.

Example:

from mirascope.core import prompt_template
from mirascope.core.cohere import cohere_call


@cohere_call("command-r-plus")
def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"


response = recommend_book("fantasy")  # response is an `CohereCallResponse` instance
print(response.content)

Bases:

BaseCallResponse[SkipValidation[NonStreamedChatResponse], CohereTool, SkipValidation[Tool], AsyncCohereDynamicConfig | CohereDynamicConfig, SkipValidation[ChatMessage], CohereCallParams, SkipValidation[ChatMessage], CohereMessageParamConverter]

Attributes

NameTypeDescription
contentstrReturns the content of the chat completion for the 0th choice.
finish_reasonslist[str] | NoneReturns the finish reasons of the response.
modelstrReturns the name of the response model. Cohere does not return model, so we return the model provided by the user.
idstr | NoneReturns the id of the response.
usageApiMetaBilledUnits | NoneReturns the usage of the response.
input_tokensfloat | NoneReturns the number of input tokens.
cached_tokensfloat | NoneReturns the number of cached tokens.
output_tokensfloat | NoneReturns the number of output tokens.
message_paramChatMessageReturns the assistant's response as a message parameter.
toolslist[CohereTool] | NoneReturns the tools for the 0th choice message.
toolCohereTool | NoneReturns the 0th tool for the 0th choice message.
common_finish_reasonslist[FinishReason] | None-
common_message_paramBaseMessageParam-
common_user_message_paramBaseMessageParam | None-
cost_metadataCostMetadataGet metadata required for cost calculation.

Function tool_message_params

Returns the tool message parameters for tool call results.

Parameters

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

Returns

TypeDescription
list[ToolResult]The list of constructed `ToolResult` parameters.