Repository navigation
Build-Things Tutorial - response message content index - #845
garjarbinks wants to merge 1 commit into
Conversation
changed response.message.content[0].text to response.message.content[-1].text. In non-thinking/non-reasoning models index 0 is what we want, but in thinking/reasoning models, content index 0 is the "thoughts". Ideally we'd enumerate the content array for responses of the correct type, but to keep the code super-simple, I'd use the LAST index of the content array, vs that 0th.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 6f553cd. Configure here.
| print(response.message.content[0].text) | ||
| # for message in response.message.content: | ||
| # if hasattr(message, 'text'): | ||
| # print(message.text) |
There was a problem hiding this comment.
Leftover commented-out tutorial code
Low Severity
A commented-out loop over response.message.content was left in the first chatbot example after the content[-1].text print. It has no surrounding explanation, appears in only this snippet, and looks like an exploratory alternative rather than tutorial content.
Reviewed by Cursor Bugbot for commit 6f553cd. Configure here.
There was a problem hiding this comment.
Could add a comment description if necessary. Just wanted to show an example for the user of iterating the messages for only those that have a text attribute.


Problem
Several Python examples access the generated response using response.message.content[0].text.
For non-reasoning models, the first content block typically contains the generated text. However, reasoning models can return a thinking block before the final text block.
This causes existing examples to fail or incorrectly access the reasoning content.
Proposed change
Replace response.message.content[0].text with response.message.content[-1].text where the final content block contains the generated response.
Although filtering the content array by content type would be more robust, accessing the final content block keeps introductory code examples simple while supporting both reasoning and non-reasoning models.
Scope
Documentation and Python code examples, including notebooks, related only to the "Build Things with Cohere" turorial
fern/pages/v2/tutorials/build-things-with-cohere
notebooks/guides/getting-started/v2
Note
Low Risk
Documentation and notebook example updates only; no application or API runtime code changes.
Overview
Updates Build Things with Cohere docs and matching v2 notebooks so examples read assistant output from
response.message.content[-1].textinstead ofcontent[0].text, so copied code still works when models return a reasoning/thinking block before the final text.The text-generation tutorial prose now describes that last-content-block pattern. Streaming examples only print
content-deltatokens whenevent.delta.message.content.textis notNone. The chatbot tutorial adds an optional commented loop for iterating content blocks.Reviewed by Cursor Bugbot for commit 6f553cd. Bugbot is set up for automated code reviews on this repo. Configure here.