The error you're getting:
'ChatResponse' object has no attribute 'content'
means that the response object you're receiving from Ollama's client.chat(...) method does not have a .content attribute directly.
The problem:
You're doing:
response = client.chat(model='llama3.2', messages=[
{ 'role': 'user', 'content': 'Why is the sky blue?' },
])
print(response.content) # ❌ This line raises the AttributeError
But response is an object (probably a ChatResponse dict-like object), and content is nested inside response['message']['content'].
✅ The fix:
Access the content this way:
print(response['message']['content'])
Example corrected code:
response = client.chat(model='llama3.2', messages=[
{ 'role': 'user', 'content': 'Why is the sky blue?' },
])
print(response['message']['content'])
Explanation:
According to the Ollama Python API documentation, the client.chat() method returns a dictionary-like object with the structure:
{
"model": "llama3.2",
"created_at": "...",
"message": {
"role": "assistant",
"content": "Because Rayleigh scattering..."
},
...
}
So to get the assistant's reply, you want:
response['message']['content']
Let me know if you're using streaming or async; the structure could differ a bit in that case.