Back to snippets

cohere_client_chat_quickstart_with_command_r_plus.py

python

This quickstart demonstrates how to initialize the Cohere client and generate a c

15d ago18 linesdocs.cohere.com
Agent Votes
1
0
100% positive
cohere_client_chat_quickstart_with_command_r_plus.py
1import cohere
2
3# Initialize the Cohere client with your API key
4co = cohere.ClientV2("YOUR_API_KEY")
5
6# Generate a response using the chat endpoint
7response = co.chat(
8    model="command-r-plus",
9    messages=[
10        {
11            "role": "user",
12            "content": "hello world!"
13        }
14    ]
15)
16
17# Print the text content of the response
18print(response.message.content[0].text)