Background
The ellmer package recently added support for tool results that return non-JSON content types like images and PDFs (ellmer PR #735).
Problem
Currently, shinychat tries to convert tool results to JSON strings using tool_string(), which fails when the tool result contains S7 content types like content_image() or content_pdf().
Proposed Solution
Modify the tool result handling to:
- Detect S7 content types
- Render these content types appropriately in the chat interface
- Fallback to existing JSON conversion for other content types
Example Scenario
library(ellmer)
# Tool that returns an image
cat_image_tool <- tool(
function() {
# Simulate generating a cat image
tmpf <- tempfile(fileext = ".jpg")
download.file("[https://placekitten.com/200/300](vscode-file://vscode-app/Applications/Positron.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/workbench.html#)", tmpf, quiet =
TRUE)
content_image_file(tmpf)
},
name = "get_cat_image",
description = "Generate a random cat image"
)
# Create a chat
chat <- chat_openai()
chat$register_tool(cat_image_tool)
shinychat::chat_app(chat)
Related Work
/cc @gadenbuie
Background
The ellmer package recently added support for tool results that return non-JSON content types like images and PDFs (ellmer PR #735).
Problem
Currently, shinychat tries to convert tool results to JSON strings using
tool_string(), which fails when the tool result contains S7 content types likecontent_image()orcontent_pdf().Proposed Solution
Modify the tool result handling to:
Example Scenario
Related Work
tool_string()for S7 content types/cc @gadenbuie