Find answers from the community

Updated 8 months ago

```

Plain Text
messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="Tell me a story"),
]
resp = Anthropic(model="claude-3-opus-20240229").chat(messages)

print(resp.chat.messages)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], line 1
----> 1 print(resp.chat.messages)

AttributeError: 'ChatResponse' object has no attribute 'chat'

What on earth is there in ChatResponse? It doesn't even work as .text
W
2 comments
If you want to print the resp object just do
Plain Text
print(resp)
or 
print(resp.message)
This is what ChatResponse object looks like

Plain Text
class ChatResponse(BaseModel):
    """Chat response."""

    message: ChatMessage
    raw: Optional[dict] = None
    delta: Optional[str] = None
    logprobs: Optional[List[List[LogProb]]] = None
    additional_kwargs: dict = Field(default_factory=dict)

    def __str__(self) -> str:
        return str(self.message)
Add a reply
Sign up and join the conversation on Discord