# Chat

## Messages

* Message structure:
  * v1: uses separate `preamble` and `message` parameters.
  * v2: uses a single `messages` parameter consisting of a list of roles (`system`, `user`, `assistant`, or `tool`). The `system` role in v2 replaces the `preamble` parameter in v1.

* Chat history:
  * v1: manages the chat history via the `chat_history` parameter.
  * v2: manages the chat history via the `messages` list.

**v1**

```python PYTHON
res = co_v1.chat(
    model="command-a-03-2025",
    preamble="You respond in concise sentences.",
    chat_history=[
        {"role": "user", "message": "Hello"},
        {
            "role": "chatbot",
            "message": "Hi, how can I help you today?",
        },
    ],
    message="I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates?",
)

print(res.text)
```

```
Excited to join the team at Co1t, where I look forward to contributing my skills and collaborating with everyone to drive innovation and success.
```

**v2**

```python PYTHON
res = co_v2.chat(
    model="command-a-03-2025",
    messages=[
        {
            "role": "system",
            "content": "You respond in concise sentences.",
        },
        {"role": "user", "content": "Hello"},
        {
            "role": "assistant",
            "content": "Hi, how can I help you today?",
        },
        {
            "role": "user",
            "content": "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates.",
        },
    ],
)

print(res.message.content[0].text)
```

```
Excited to join the team at Co1t, bringing my passion for innovation and a background in [your expertise] to contribute to the company's success!
```

## Response content

* v1: Accessed via `text`
* v2: Accessed via `message.content[0].text`

**v1**

```python PYTHON
res = co_v1.chat(model="command-a-03-2025", message="What is 2 + 2")

print(res.text)
```

```
The answer is 4.
```

**v2**

```python PYTHON
res = co_v2.chat(
    model="command-a-03-2025",
    messages=[{"role": "user", "content": "What is 2 + 2"}],
)

print(res.message.content[0].text)
```

```
The answer is 4.
```

## Streaming

* Events containing content:
  * v1: `chunk.event_type == "text-generation"`
  * v2: `chunk.type == "content-delta"`

* Accessing response content:
  * v1: `chunk.text`
  * v2: `chunk.delta.message.content.text`

**v1**

```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

res = co_v1.chat_stream(model="command-a-03-2025", message=message)

for chunk in res:
    if chunk.event_type == "text-generation":
        print(chunk.text, end="")
```

```
"Hi, I'm [your name] and I'm thrilled to join the Co1t team today as a [your role], eager to contribute my skills and ideas to help drive innovation and success for our startup!"
```

**v2**

```python PYTHON
message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message to my teammates."

res = co_v2.chat_stream(
    model="command-a-03-2025",
    messages=[{"role": "user", "content": message}],
)

for chunk in res:
    if chunk:
        if chunk.type == "content-delta":
            print(chunk.delta.message.content.text, end="")
```

```
"Hi everyone, I'm thrilled to join the Co1t team today and look forward to contributing my skills and ideas to drive innovation and success!"
```