mirascope.core.cohere.call_response_chunk | Mirascope
MirascopeLilypad

mirascope.core.cohere.call_response_chunk

This module contains the CohereCallResponseChunk class.

Usage

Class CohereCallResponseChunk

A convenience wrapper around the Cohere ChatCompletionChunk streamed chunks.

When calling the Cohere API using a function decorated with cohere_call and stream set to True, the stream will contain CohereResponseChunk instances with properties that allow for more convenient access to commonly used attributes.

Example:

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


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


stream = recommend_book("fantasy")  # response is an `CohereStream`
for chunk, _ in stream:
    print(chunk.content, end="", flush=True)

Bases:

BaseCallResponseChunk[SkipValidation[StreamedChatResponse], ChatStreamEndEventFinishReason]

Attributes

NameTypeDescription
contentstrReturns the content for the 0th choice delta.
finish_reasonslist[ChatStreamEndEventFinishReason] | NoneReturns the finish reasons of the response.
modelstr | NoneReturns the name of the response model. Cohere does not return model, so we return None
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.
cost_metadataCostMetadataReturns the cost metadata.
common_finish_reasonslist[types.FinishReason] | None-