h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.9k stars 323 forks source link

feat: Prompt suggestions for ui.chatbot #2250 #2265

Closed marek-mihok closed 4 months ago

marek-mihok commented 4 months ago

The PR fulfills these requirements: (check all the apply)


This PR brings suggestions: ChatSuggestion[] attribute to show clickable prompt suggestions under the last response in ui.chatbot component. When the suggestion is clicked, it fires suggestion event which can subsequently be handled by the user.

The user input can be limited to prompt suggestions only by specifying disabled prop which disables user input or it can be used in a combination with text input as well.

chatbot-prompt-suggestions

Updated API is as follows:

/** Create a chat prompt suggestion displayed as button below the last response in the chatbot component. */
export interface ChatSuggestion {
  /** An identifying name for this component. */
  name: Id
  /** The text displayed for this suggestion. */
  label: S
  /** The caption displayed below the label. */
  caption?: S
  /** The icon to be displayed for this suggestion. */
  icon?: S
}

/** Create a chatbot card to allow getting prompts from users and providing them with LLM generated answers. */
export interface Chatbot {
  /** An identifying name for this component. */
  name: Id
  /** Chat messages data. Requires list or cyclic buffer. */
  data: Rec
  /** Chat input box placeholder. Use for prompt examples. */
  placeholder?: S
  /** The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'. */
  events?: S[]
  /** True to show a button to stop the text generation. Defaults to False. */
  generating?: B
  /** The previous messages to show as the user scrolls up. */
  prev_items?: ChatbotMessage[]
  /** Clickable prompt suggestions shown below the last response. */
  suggestions?: ChatSuggestion[]
  /** True if the user input should be disabled. */
  disabled?: B
}

The same API update also applies to ui.chatbot_card component.

Closes #2250

marek-mihok commented 4 months ago

First 2 points are done:

https://github.com/h2oai/wave/assets/23740173/feabd35c-41c3-40d6-9fd3-781e1860b749

https://github.com/h2oai/wave/assets/23740173/826238cb-bd9a-4fd6-a598-ea20212b885f

The example could use some polish as well, it's very rough at the moment.

@mturoci what do you mean by rough? In terms of code quality or the use case relevance? Can you give me some thoughts about what you consider a proper example?

mturoci commented 4 months ago

what do you mean by rough?

Would that demo persuade you to use Wave? Probably not. Would be better to append the suggestion right away, but add a slight timeout on suggestion selection to emulate computation, hide suggestions in the meantime, then append the response.

mturoci commented 4 months ago

First 2 points are done:

Looks better, the border radius is off though. Try to use the same as used in the rest of our cards/components.