Title: | Inline Asynchronous Generator Results into Documents |
---|---|
Description: | Given a 'coro' asynchronous generator instance that produces text, write that text into a document selection in 'RStudio' and 'Positron'. This is particularly helpful for streaming large language model responses into the user's editor. |
Authors: | Simon Couch [aut, cre], Posit Software, PBC [cph, fnd] |
Maintainer: | Simon Couch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2025-03-14 06:00:24 UTC |
Source: | https://github.com/simonpcouch/streamy |
Given an asychronous generator that produces text, this function iteratively polls that generator and inlines its results into the currently open RStudio or Positron document. This is particularly useful for streaming results from large language models.
stream( generator, context = active_document_context(), interface = c("prefix", "replace", "suffix") )
stream( generator, context = active_document_context(), interface = c("prefix", "replace", "suffix") )
generator |
A |
context |
Optional. An RStudio document context. |
interface |
One of |
This function is generally not intended for interactive usage. See the gander, pal, and ensure package, which this package powers.
The streamed result, invisibly; called for its side effect, modifying the context of the current selection with results from the generator.
## Not run: if (rlang::is_installed("ellmer") && !identical("ANTHROPIC_API_KEY", "") && rstudioapi::isAvailable() ) { library(ellmer) gen <- chat_claude()$stream("hey there!") stream(gen, interface = "suffix") } ## End(Not run)
## Not run: if (rlang::is_installed("ellmer") && !identical("ANTHROPIC_API_KEY", "") && rstudioapi::isAvailable() ) { library(ellmer) gen <- chat_claude()$stream("hey there!") stream(gen, interface = "suffix") } ## End(Not run)