-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add value prop to ui.chatbot_card #2367
- Loading branch information
1 parent
c524498
commit d6ceb3b
Showing
14 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Chatbot / Value | ||
# Use this card for chatbot interactions. | ||
# #chatbot #value | ||
# --- | ||
from h2o_wave import main, app, Q, ui, data | ||
|
||
templates = { | ||
'template_poem': 'Write a poem about [SUBJECT]. Be creative and use [EMOTION] words.', | ||
'template_summarize': 'Summarize the following text with [WORD_COUNT] words maximum while keeping all of the important information: [PASTE_YOUR_TEXT_HERE]', | ||
'template_professional': 'Rewrite the following text professionally while sounding like a high-class writer: [PASTE_YOUR_TEXT_HERE]', | ||
} | ||
|
||
template_choices = [ | ||
ui.choice('template_poem', 'Write a poem'), | ||
ui.choice('template_summarize', 'Summarize'), | ||
ui.choice('template_professional', 'Rewrite professionally'), | ||
] | ||
|
||
@app('/demo') | ||
async def serve(q: Q): | ||
if not q.client.initialized: | ||
q.page['dropdown'] = ui.form_card( | ||
box='6 1 2 2', | ||
items=[ | ||
ui.dropdown( | ||
name='dropdown', | ||
label='Select a template', | ||
value="template_poem", | ||
choices=template_choices, | ||
trigger=True) | ||
] | ||
) | ||
q.page['example'] = ui.chatbot_card( | ||
box='1 1 5 5', | ||
data=data('content from_user', t='list'), | ||
name='chatbot', | ||
value=templates['template_poem'] | ||
) | ||
q.client.initialized = True | ||
|
||
# Handle template change. | ||
if q.args.dropdown: | ||
if q.args.dropdown == 'template_poem': | ||
q.page['example'].value = templates['template_poem'] | ||
elif q.args.dropdown == 'template_summarize': | ||
q.page['example'].value = templates['template_summarize'] | ||
elif q.args.dropdown == 'template_professional': | ||
q.page['example'].value = templates['template_professional'] | ||
# A new message arrived. | ||
elif q.args.chatbot: | ||
# Append user message. | ||
q.page['example'].data += [q.args.chatbot, True] | ||
# Append bot response. | ||
q.page['example'].data += ['I am a fake chatbot. Sorry, I cannot help you.', False] | ||
|
||
await q.page.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.