mirascope.core.cohere.call_response_chunk¶
This module contains the CohereCallResponseChunk
class.
Usage Documentation
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)