mirascope.core.cohere.call_response¶
This module contains the CohereCallResponse
class.
Usage Documentation
CohereCallResponse
¶
Bases: BaseCallResponse[SkipValidation[NonStreamedChatResponse], CohereTool, SkipValidation[Tool], AsyncCohereDynamicConfig | CohereDynamicConfig, SkipValidation[ChatMessage], CohereCallParams, SkipValidation[ChatMessage]]
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)
finish_reasons
property
¶
Returns the finish reasons of the response.
model
property
¶
model: str
Returns the name of the response model.
Cohere does not return model, so we return the model provided by the user.
message_param
cached
property
¶
Returns the assistant's response as a message parameter.
tools
cached
property
¶
tools: list[CohereTool] | None
Returns the tools for the 0th choice message.
Raises:
Type | Description |
---|---|
ValidationError
|
if a tool call doesn't match the tool's schema. |
tool
cached
property
¶
tool: CohereTool | None
Returns the 0th tool for the 0th choice message.
Raises:
Type | Description |
---|---|
ValidationError
|
if the tool call doesn't match the tool's schema. |
tool_message_params
classmethod
¶
tool_message_params(
tools_and_outputs: list[tuple[CohereTool, str]]
) -> list[ToolResult]
Returns the tool message parameters for tool call results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools_and_outputs |
list[tuple[CohereTool, str]]
|
The list of tools and their outputs from which the tool message parameters should be constructed. |
required |
Returns:
Type | Description |
---|---|
list[ToolResult]
|
The list of constructed |