Skip to content

mirascope.core.cohere.call_response_chunk

This module contains the CohereCallResponseChunk class.

Usage Documentation

Streams

CohereCallResponseChunk

Bases: BaseCallResponseChunk[SkipValidation[StreamedChatResponse], ChatStreamEndEventFinishReason]

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)

content property

content: str

Returns the content for the 0th choice delta.

finish_reasons property

finish_reasons: list[ChatStreamEndEventFinishReason] | None

Returns the finish reasons of the response.

model property

model: str | None

Returns the name of the response model.

Cohere does not return model, so we return None

id property

id: str | None

Returns the id of the response.

usage property

usage: ApiMetaBilledUnits | None

Returns the usage of the response.

input_tokens property

input_tokens: float | None

Returns the number of input tokens.

output_tokens property

output_tokens: float | None

Returns the number of output tokens.