Skip to content

WIP: Tool calling UI #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 85 commits into
base: main
Choose a base branch
from
Draft

WIP: Tool calling UI #52

wants to merge 85 commits into from

Conversation

gadenbuie
Copy link
Collaborator

@gadenbuie gadenbuie commented May 19, 2025

TODO

  • Update toggle indicator to be a + or - depending on state (with a neat animation)
  • Add article about tool-calling plus shinychat to R package
  • Implement Python interface to tool calling UI
  • Playwright tests
  • R package testthat tests

simonpcouch added a commit to simonpcouch/predictive that referenced this pull request Jun 27, 2025
@cpsievert cpsievert mentioned this pull request Jul 21, 2025
4 tasks
Comment on lines +77 to +83
<button
class="card-header"
id="${headerId}"
@click="${this.#toggleCollapse}"
aria-expanded="${this.expanded}"
aria-controls="${contentId}"
>
Copy link
Collaborator

@cpsievert cpsievert Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice -- maybe worth bringing to bslib as well (not now, but eventually)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to consider adding when we turn bslib::card() into a custom component 😉


return html`
<div
class="shiny-tool-card card bslib-card bslib-mb-spacing html-fill-item html-fill-container m-0"
Copy link
Collaborator

@cpsievert cpsievert Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe a little too aggressive in removing classes, but seems like we don't need filling layout, and also don't need bslib's complex margin/spacing rules?

Suggested change
class="shiny-tool-card card bslib-card bslib-mb-spacing html-fill-item html-fill-container m-0"
class="shiny-tool-card card m-0"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking we do want filling -- if you return only HTML and turn off tool request display, you could have your tool return a map or plot that fills the card. I have a demo planned to show that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And just generally the further we get away from bslib::card() markup, the more space we leave for updates to bslib::card() to miss the nuance of differences in this component. Sounds like a bad time waiting to happen.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh OK, I had missed the max-height setting on .shiny-tool-card

Copy link
Collaborator

@cpsievert cpsievert Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem worth dropping bslib-mb-spacing and bslib-gap-spacing though since we're in control of the container of the card?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unless you can think of a way this would cause problems. My take is that we should follow bslib::card() as close as reasonably possible unless we have evidence that including a class is going to cause issues.

<div class="collapse-indicator">${unsafeHTML(ICONS.plus)}</div>
</button>
<div
class="card-body bslib-gap-spacing html-fill-item html-fill-container${this
Copy link
Collaborator

@cpsievert cpsievert Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we don't actually need filling layout or complex gap spacing

Suggested change
class="card-body bslib-gap-spacing html-fill-item html-fill-container${this
class="card-body ${this

Comment on lines +171 to +172
@property({ type: Boolean, attribute: "show-request" })
showRequest = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to document that what we mean here is showing the request inside the result container (i.e., the request container element should always be hidden).

Comment on lines 136 to 141
html <- list(
value = format(display),
value_type = "html",
deps = htmltools::findDependencies(display)
)
return(html)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could get away with just returning value and value_type from this function?

Suggested change
html <- list(
value = format(display),
value_type = "html",
deps = htmltools::findDependencies(display)
)
return(html)
return(list(value = display, value_type = "html"))

Copy link
Collaborator

@cpsievert cpsievert Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going even further, seems the logic could be cleaner if you had one function to just get the value_type, and another function that uses it, but returns the value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some overlapping logic between value_type and value that doesn't make it worth separating into two functions. But I was able to clean this up quite a bit with a second pass in f3c28fa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants