Skip to content

Add an option to <Chat>$stream() and <Chat>$stream_async() to yield tool requests and results #400

Description

@gadenbuie

Currently, tool requests (ContentToolRequest in the assistant turn) and tool results (a user turn with one or more ContentToolResult objects) are emitted to the console when echo = "all" but aren't yielded into the generator streaming results.

I'd like to add an option to $stream() and $stream_async(), possibly yield_all, that, when TRUE, will yield the non-text Content items of the assistant turn and all Content items of the user turn into the generator.

We've also discussed an option like include_tools, which would match the current implementation, but I can imagine a future where other content types are created during the chat back-and-forth.

In shinychat, we'd use this option like this:

shiny::observeEvent(input$chat_user_input, {
  stream <- client$stream_async(user_input, yield_all = TRUE)
  shinychat::chat_append(ui_id, stream)
})

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions