Skip to content

Commit

Permalink
chore: rename prompt_suggestions to suggestions, refactor #2250
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed Feb 16, 2024
1 parent 9a45ba2 commit e8e8fbd
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 60 deletions.
10 changes: 5 additions & 5 deletions py/examples/chatbot_events_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ async def serve(q: Q):
data=data(fields='content from_user', t='list'),
name='chatbot',
placeholder='Ask me anything...',
events=['prompt_suggestion'],
prompt_suggestions=[ui.chat_prompt_suggestion(name, label=value[0], caption=value[1], icon=value[2]) for
events=['suggestion'],
suggestions=[ui.chat_prompt_suggestion(name, label=value[0], caption=value[1], icon=value[2]) for
name, value in suggestions.items()]
)
q.client.initialized = True

elif q.events.chatbot or q.args.chatbot:
# Clear prompt suggestions.
q.page['example'].prompt_suggestions = []
q.page['example'].suggestions = []

# Handle user input.
if q.args.chatbot:
# Append user message typed manually.
q.page['example'].data += [q.args.chatbot, True]
else:
label, caption, icon = suggestions[q.events.chatbot.prompt_suggestion]
# Append user message based on the prompt_suggestion event.
label, caption, icon = suggestions[q.events.chatbot.suggestion]
# Append user message based on the prompt suggestion event.
q.page['example'].data += [label + ' ' + caption, True]

# Append bot response.
Expand Down
20 changes: 10 additions & 10 deletions py/h2o_lightwave/h2o_lightwave/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8315,7 +8315,7 @@ def __init__(
placeholder: Optional[str] = None,
events: Optional[List[str]] = None,
generating: Optional[bool] = None,
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None,
suggestions: Optional[List[ChatPromptSuggestion]] = None,
disabled: Optional[bool] = None,
commands: Optional[List[Command]] = None,
):
Expand All @@ -8324,7 +8324,7 @@ def __init__(
_guard_scalar('ChatbotCard.placeholder', placeholder, (str,), False, True, False)
_guard_vector('ChatbotCard.events', events, (str,), False, True, False)
_guard_scalar('ChatbotCard.generating', generating, (bool,), False, True, False)
_guard_vector('ChatbotCard.prompt_suggestions', prompt_suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_vector('ChatbotCard.suggestions', suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_scalar('ChatbotCard.disabled', disabled, (bool,), False, True, False)
_guard_vector('ChatbotCard.commands', commands, (Command,), False, True, False)
self.box = box
Expand All @@ -8336,10 +8336,10 @@ def __init__(
self.placeholder = placeholder
"""Chat input box placeholder. Use for prompt examples."""
self.events = events
"""The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'."""
"""The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'suggestion'."""
self.generating = generating
"""True to show a button to stop the text generation. Defaults to False."""
self.prompt_suggestions = prompt_suggestions
self.suggestions = suggestions
"""Clickable prompt suggestions shown below the last response."""
self.disabled = disabled
"""True if the user input should be disabled."""
Expand All @@ -8353,7 +8353,7 @@ def dump(self) -> Dict:
_guard_scalar('ChatbotCard.placeholder', self.placeholder, (str,), False, True, False)
_guard_vector('ChatbotCard.events', self.events, (str,), False, True, False)
_guard_scalar('ChatbotCard.generating', self.generating, (bool,), False, True, False)
_guard_vector('ChatbotCard.prompt_suggestions', self.prompt_suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_vector('ChatbotCard.suggestions', self.suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_scalar('ChatbotCard.disabled', self.disabled, (bool,), False, True, False)
_guard_vector('ChatbotCard.commands', self.commands, (Command,), False, True, False)
return _dump(
Expand All @@ -8364,7 +8364,7 @@ def dump(self) -> Dict:
placeholder=self.placeholder,
events=self.events,
generating=self.generating,
prompt_suggestions=None if self.prompt_suggestions is None else [__e.dump() for __e in self.prompt_suggestions],
suggestions=None if self.suggestions is None else [__e.dump() for __e in self.suggestions],
disabled=self.disabled,
commands=None if self.commands is None else [__e.dump() for __e in self.commands],
)
Expand All @@ -8383,8 +8383,8 @@ def load(__d: Dict) -> 'ChatbotCard':
_guard_vector('ChatbotCard.events', __d_events, (str,), False, True, False)
__d_generating: Any = __d.get('generating')
_guard_scalar('ChatbotCard.generating', __d_generating, (bool,), False, True, False)
__d_prompt_suggestions: Any = __d.get('prompt_suggestions')
_guard_vector('ChatbotCard.prompt_suggestions', __d_prompt_suggestions, (dict,), False, True, False)
__d_suggestions: Any = __d.get('suggestions')
_guard_vector('ChatbotCard.suggestions', __d_suggestions, (dict,), False, True, False)
__d_disabled: Any = __d.get('disabled')
_guard_scalar('ChatbotCard.disabled', __d_disabled, (bool,), False, True, False)
__d_commands: Any = __d.get('commands')
Expand All @@ -8395,7 +8395,7 @@ def load(__d: Dict) -> 'ChatbotCard':
placeholder: Optional[str] = __d_placeholder
events: Optional[List[str]] = __d_events
generating: Optional[bool] = __d_generating
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None if __d_prompt_suggestions is None else [ChatPromptSuggestion.load(__e) for __e in __d_prompt_suggestions]
suggestions: Optional[List[ChatPromptSuggestion]] = None if __d_suggestions is None else [ChatPromptSuggestion.load(__e) for __e in __d_suggestions]
disabled: Optional[bool] = __d_disabled
commands: Optional[List[Command]] = None if __d_commands is None else [Command.load(__e) for __e in __d_commands]
return ChatbotCard(
Expand All @@ -8405,7 +8405,7 @@ def load(__d: Dict) -> 'ChatbotCard':
placeholder,
events,
generating,
prompt_suggestions,
suggestions,
disabled,
commands,
)
Expand Down
8 changes: 4 additions & 4 deletions py/h2o_lightwave/h2o_lightwave/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2909,7 +2909,7 @@ def chatbot_card(
placeholder: Optional[str] = None,
events: Optional[List[str]] = None,
generating: Optional[bool] = None,
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None,
suggestions: Optional[List[ChatPromptSuggestion]] = None,
disabled: Optional[bool] = None,
commands: Optional[List[Command]] = None,
) -> ChatbotCard:
Expand All @@ -2920,9 +2920,9 @@ def chatbot_card(
name: An identifying name for this component.
data: Chat messages data. Requires cyclic buffer.
placeholder: Chat input box placeholder. Use for prompt examples.
events: The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'.
events: The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'suggestion'.
generating: True to show a button to stop the text generation. Defaults to False.
prompt_suggestions: Clickable prompt suggestions shown below the last response.
suggestions: Clickable prompt suggestions shown below the last response.
disabled: True if the user input should be disabled.
commands: Contextual menu commands for this component.
Returns:
Expand All @@ -2935,7 +2935,7 @@ def chatbot_card(
placeholder,
events,
generating,
prompt_suggestions,
suggestions,
disabled,
commands,
)
Expand Down
20 changes: 10 additions & 10 deletions py/h2o_wave/h2o_wave/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8315,7 +8315,7 @@ def __init__(
placeholder: Optional[str] = None,
events: Optional[List[str]] = None,
generating: Optional[bool] = None,
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None,
suggestions: Optional[List[ChatPromptSuggestion]] = None,
disabled: Optional[bool] = None,
commands: Optional[List[Command]] = None,
):
Expand All @@ -8324,7 +8324,7 @@ def __init__(
_guard_scalar('ChatbotCard.placeholder', placeholder, (str,), False, True, False)
_guard_vector('ChatbotCard.events', events, (str,), False, True, False)
_guard_scalar('ChatbotCard.generating', generating, (bool,), False, True, False)
_guard_vector('ChatbotCard.prompt_suggestions', prompt_suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_vector('ChatbotCard.suggestions', suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_scalar('ChatbotCard.disabled', disabled, (bool,), False, True, False)
_guard_vector('ChatbotCard.commands', commands, (Command,), False, True, False)
self.box = box
Expand All @@ -8336,10 +8336,10 @@ def __init__(
self.placeholder = placeholder
"""Chat input box placeholder. Use for prompt examples."""
self.events = events
"""The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'."""
"""The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'suggestion'."""
self.generating = generating
"""True to show a button to stop the text generation. Defaults to False."""
self.prompt_suggestions = prompt_suggestions
self.suggestions = suggestions
"""Clickable prompt suggestions shown below the last response."""
self.disabled = disabled
"""True if the user input should be disabled."""
Expand All @@ -8353,7 +8353,7 @@ def dump(self) -> Dict:
_guard_scalar('ChatbotCard.placeholder', self.placeholder, (str,), False, True, False)
_guard_vector('ChatbotCard.events', self.events, (str,), False, True, False)
_guard_scalar('ChatbotCard.generating', self.generating, (bool,), False, True, False)
_guard_vector('ChatbotCard.prompt_suggestions', self.prompt_suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_vector('ChatbotCard.suggestions', self.suggestions, (ChatPromptSuggestion,), False, True, False)
_guard_scalar('ChatbotCard.disabled', self.disabled, (bool,), False, True, False)
_guard_vector('ChatbotCard.commands', self.commands, (Command,), False, True, False)
return _dump(
Expand All @@ -8364,7 +8364,7 @@ def dump(self) -> Dict:
placeholder=self.placeholder,
events=self.events,
generating=self.generating,
prompt_suggestions=None if self.prompt_suggestions is None else [__e.dump() for __e in self.prompt_suggestions],
suggestions=None if self.suggestions is None else [__e.dump() for __e in self.suggestions],
disabled=self.disabled,
commands=None if self.commands is None else [__e.dump() for __e in self.commands],
)
Expand All @@ -8383,8 +8383,8 @@ def load(__d: Dict) -> 'ChatbotCard':
_guard_vector('ChatbotCard.events', __d_events, (str,), False, True, False)
__d_generating: Any = __d.get('generating')
_guard_scalar('ChatbotCard.generating', __d_generating, (bool,), False, True, False)
__d_prompt_suggestions: Any = __d.get('prompt_suggestions')
_guard_vector('ChatbotCard.prompt_suggestions', __d_prompt_suggestions, (dict,), False, True, False)
__d_suggestions: Any = __d.get('suggestions')
_guard_vector('ChatbotCard.suggestions', __d_suggestions, (dict,), False, True, False)
__d_disabled: Any = __d.get('disabled')
_guard_scalar('ChatbotCard.disabled', __d_disabled, (bool,), False, True, False)
__d_commands: Any = __d.get('commands')
Expand All @@ -8395,7 +8395,7 @@ def load(__d: Dict) -> 'ChatbotCard':
placeholder: Optional[str] = __d_placeholder
events: Optional[List[str]] = __d_events
generating: Optional[bool] = __d_generating
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None if __d_prompt_suggestions is None else [ChatPromptSuggestion.load(__e) for __e in __d_prompt_suggestions]
suggestions: Optional[List[ChatPromptSuggestion]] = None if __d_suggestions is None else [ChatPromptSuggestion.load(__e) for __e in __d_suggestions]
disabled: Optional[bool] = __d_disabled
commands: Optional[List[Command]] = None if __d_commands is None else [Command.load(__e) for __e in __d_commands]
return ChatbotCard(
Expand All @@ -8405,7 +8405,7 @@ def load(__d: Dict) -> 'ChatbotCard':
placeholder,
events,
generating,
prompt_suggestions,
suggestions,
disabled,
commands,
)
Expand Down
8 changes: 4 additions & 4 deletions py/h2o_wave/h2o_wave/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2909,7 +2909,7 @@ def chatbot_card(
placeholder: Optional[str] = None,
events: Optional[List[str]] = None,
generating: Optional[bool] = None,
prompt_suggestions: Optional[List[ChatPromptSuggestion]] = None,
suggestions: Optional[List[ChatPromptSuggestion]] = None,
disabled: Optional[bool] = None,
commands: Optional[List[Command]] = None,
) -> ChatbotCard:
Expand All @@ -2920,9 +2920,9 @@ def chatbot_card(
name: An identifying name for this component.
data: Chat messages data. Requires cyclic buffer.
placeholder: Chat input box placeholder. Use for prompt examples.
events: The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'.
events: The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'suggestion'.
generating: True to show a button to stop the text generation. Defaults to False.
prompt_suggestions: Clickable prompt suggestions shown below the last response.
suggestions: Clickable prompt suggestions shown below the last response.
disabled: True if the user input should be disabled.
commands: Contextual menu commands for this component.
Returns:
Expand All @@ -2935,7 +2935,7 @@ def chatbot_card(
placeholder,
events,
generating,
prompt_suggestions,
suggestions,
disabled,
commands,
)
Expand Down
10 changes: 5 additions & 5 deletions r/R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -3371,9 +3371,9 @@ ui_chat_prompt_suggestion <- function(
#' @param name An identifying name for this component.
#' @param data Chat messages data. Requires cyclic buffer.
#' @param placeholder Chat input box placeholder. Use for prompt examples.
#' @param events The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'prompt_suggestion'.
#' @param events The events to capture on this chatbot. One of 'stop' | 'scroll_up' | 'feedback' | 'suggestion'.
#' @param generating True to show a button to stop the text generation. Defaults to False.
#' @param prompt_suggestions Clickable prompt suggestions shown below the last response.
#' @param suggestions Clickable prompt suggestions shown below the last response.
#' @param disabled True if the user input should be disabled.
#' @param commands Contextual menu commands for this component.
#' @return A ChatbotCard instance.
Expand All @@ -3385,7 +3385,7 @@ ui_chatbot_card <- function(
placeholder = NULL,
events = NULL,
generating = NULL,
prompt_suggestions = NULL,
suggestions = NULL,
disabled = NULL,
commands = NULL) {
.guard_scalar("box", "character", box)
Expand All @@ -3394,7 +3394,7 @@ ui_chatbot_card <- function(
.guard_scalar("placeholder", "character", placeholder)
.guard_vector("events", "character", events)
.guard_scalar("generating", "logical", generating)
.guard_vector("prompt_suggestions", "WaveChatPromptSuggestion", prompt_suggestions)
.guard_vector("suggestions", "WaveChatPromptSuggestion", suggestions)
.guard_scalar("disabled", "logical", disabled)
.guard_vector("commands", "WaveCommand", commands)
.o <- list(
Expand All @@ -3404,7 +3404,7 @@ ui_chatbot_card <- function(
placeholder=placeholder,
events=events,
generating=generating,
prompt_suggestions=prompt_suggestions,
suggestions=suggestions,
disabled=disabled,
commands=commands,
view='chatbot')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,28 +1138,28 @@
<option name="Python" value="true"/>
</context>
</template>
<template name="w_full_chatbot" value="ui.chatbot(name='$name$',data=$data$,placeholder='$placeholder$',generating=$generating$,disabled=$disabled$,events=[&#10; $events$ &#10;],prev_items=[&#10; $prev_items$ &#10;],prompt_suggestions=[&#10; $prompt_suggestions$ &#10;]),$END$" description="Create Wave Chatbot with full attributes." toReformat="true" toShortenFQNames="true">
<template name="w_full_chatbot" value="ui.chatbot(name='$name$',data=$data$,placeholder='$placeholder$',generating=$generating$,disabled=$disabled$,events=[&#10; $events$ &#10;],prev_items=[&#10; $prev_items$ &#10;],suggestions=[&#10; $suggestions$ &#10;]),$END$" description="Create Wave Chatbot with full attributes." toReformat="true" toShortenFQNames="true">
<variable name="name" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="data" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="placeholder" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="generating" expression="" defaultValue="&quot;False&quot;" alwaysStopAt="true"/>
<variable name="disabled" expression="" defaultValue="&quot;False&quot;" alwaysStopAt="true"/>
<variable name="events" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="prev_items" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="prompt_suggestions" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="suggestions" expression="" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="Python" value="true"/>
</context>
</template>
<template name="w_full_chatbot_card" value="ui.chatbot_card(box='$box$',name='$name$',data=$data$,placeholder='$placeholder$',generating=$generating$,disabled=$disabled$,events=[&#10; $events$ &#10;],prompt_suggestions=[&#10; $prompt_suggestions$ &#10;],commands=[&#10; $commands$ &#10;])$END$" description="Create Wave ChatbotCard with full attributes." toReformat="true" toShortenFQNames="true">
<template name="w_full_chatbot_card" value="ui.chatbot_card(box='$box$',name='$name$',data=$data$,placeholder='$placeholder$',generating=$generating$,disabled=$disabled$,events=[&#10; $events$ &#10;],suggestions=[&#10; $suggestions$ &#10;],commands=[&#10; $commands$ &#10;])$END$" description="Create Wave ChatbotCard with full attributes." toReformat="true" toShortenFQNames="true">
<variable name="box" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="name" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="data" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="placeholder" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="generating" expression="" defaultValue="&quot;False&quot;" alwaysStopAt="true"/>
<variable name="disabled" expression="" defaultValue="&quot;False&quot;" alwaysStopAt="true"/>
<variable name="events" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="prompt_suggestions" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="suggestions" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="commands" expression="" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="Python" value="true"/>
Expand Down
Loading

0 comments on commit e8e8fbd

Please sign in to comment.