Using the Cohere Chat API for Text Generation
The Chat API endpoint is used to generate text with Cohere LLMs. This endpoint facilitates a conversational interface, allowing users to send messages to the model and receive text responses.
Every message comes with a content field and an associated role, which indicates who that message is sent from. Roles can be user, assistant, system and tool.
Response Structure
Below is a sample response from the Chat API. Here, the role of the message is going to be assistant.
Every response contains the following fields:
messagethe generated message from the model.idthe ID corresponding to this response.finish_reasoncan be one of the following:COMPLETEthe model successfully finished generating the messageMAX_TOKENSthe model’s context limit was reached before the generation could be completed
metacontains information with token counts, billing etc.
System Message
Developers can adjust the LLMs behavior by including a system message in the messages list
with the role set to system.
The system message contains instructions that the model will respect over any instructions sent in messages sent from other roles. It is often used by developers to control the style in which the model communicates and to provide guidelines for how to handle various topics.
It is recommended to send the system message as the first element in the messages list.
Multi-Turn Conversations
A single Chat request can encapsulate multiple turns of a conversation, where each message in the messages list appears in the order it was sent. Sending multiple messages can give the model context for generating a response.