feat: Update and submit user value

Open
#32 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
frontend

Research direction

Start with the chat.chat_async("NEW_MSG") path and the Shiny UI integration around chat_ui.update_user_input and textarea#chat_user_input. Compare the current workaround with the desired behavior, then verify that programmatic user values update the UI and display the streaming response as if submitted interactively.

Written by the indexing model from the issue text.

Description

While this feature is directly related towards shiny.ui.Chat, I'm posting the issue here as it is targeted towards chatlas.

Goal: Set and submit user value and display streaming result as if the user had done it.

Using await chat.chat_async("NEW_MSG") does not update the Shiny UI, but it'd be really cool if it did.

Current work around:

@reactive.effect
@reactive.event(trigger)
async def _():
    chat_ui.update_user_input(value="who is the tallest skywalker")

    add_chat_entry = ui.HTML("""
    <script>
        setTimeout(async () => {
            const enterEvent = new KeyboardEvent('keydown', {
                key: 'Enter',
                code: 'Enter',
                keyCode: 13,
                which: 13,
            });

            // Dispatch the 'Enter' event on the input element
            console.log("Dispatching Enter event");
            document.querySelector("textarea#chat_user_input").dispatchEvent(enterEvent);
        }, 500);
    </script>
            """)
    ui.insert_ui(add_chat_entry, "body")
Dominant language
Python
Stars
179
Forks
32
Avg merge
1d 3h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/chatlas

All issues in posit-dev/chatlas

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.