Return ContentThinking objects from stream_text()#909
Merged
simonpcouch merged 7 commits intomainfrom Jan 12, 2026
Merged
Conversation
simonpcouch
commented
Dec 19, 2025
| "ellmer::ContentThinking" = content@thinking, | ||
| "ellmer::ContentText" = content@text, | ||
| if (S7_inherits(content, Content)) format(content) else content | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
I'm not sure if using switch on S7 objects is considered bad practice, but the control flow was gnarly otherwise😅
Member
There was a problem hiding this comment.
Maybe we should have a stream_data() that returns the object and then stream_text() would contain this code to extract out just the text?
hadley
reviewed
Jan 7, 2026
| ) | ||
|
|
||
| stream_content <- function(provider, event) { | ||
| result <- stream_text(provider, event) |
Member
There was a problem hiding this comment.
This feels inside out to me? Why doesn't stream_text() call stream_content()?
Collaborator
Author
There was a problem hiding this comment.
I had been wondering whether I was interpreting that incorrectly. :) Just switched those out.
hadley
reviewed
Jan 8, 2026
| content_text(content) | ||
| } | ||
|
|
||
| content_text <- function(content) { |
Member
There was a problem hiding this comment.
Yes, you ate my feedback and left no crumbs.
hadley
approved these changes
Jan 9, 2026
cpsievert
added a commit
to posit-dev/chatlas
that referenced
this pull request
Jan 14, 2026
Add stream_content() method to providers that returns Content objects (ContentText or ContentThinking) instead of strings. This allows downstream consumers like shinychat to distinguish between content types during streaming. - Add abstract stream_content() method to Provider base class - Change stream_text() to delegate to stream_content() - Update all providers to implement stream_content() - Add thinking content support to Google provider's _as_turn() Port of tidyverse/ellmer#909 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #837, and a subset of #828. Companion to posit-dev/shinychat#167.
Changes
stream_text()to returnContentobjects instead of strings, allowing downstream consumers to distinguish between content types during streaming. With the companion shinychat PR, results look like this:ellmer-shinychat-thinking.mp4
I'm not sure if this is the opposite direction of the dev dependency that yall would usually introduce. With
mainshinychat and this PR, each thinking delta would otherwise get its own collapsible:So, I opted to make ellmer depend on the shinychat Remotes. If this is a no-go, we could add some version-dependent logic, but felt cleaner to start with this approach.
Here's the reprex I use in the video: