Skip to content
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

pn.chat.ChatAreaInput <Enter> key binding Feature Request #6575

Closed
ea42gh opened this issue Mar 25, 2024 · 14 comments
Closed

pn.chat.ChatAreaInput <Enter> key binding Feature Request #6575

ea42gh opened this issue Mar 25, 2024 · 14 comments

Comments

@ea42gh
Copy link
Contributor

ea42gh commented Mar 25, 2024

Multiline input will likely cause users to inadvertently send an incomplete prompt when typing

I would prefer having the option to bind to carriage return/line feed
and and/or be bound to Send

This would be in line with the behavior of jupyter cells.

@ea42gh ea42gh changed the title pn.chat.ChatAreaInput <Enter> key bindning pn.chat.ChatAreaInput <Enter> key bindning Feature Request Mar 25, 2024
@ea42gh ea42gh changed the title pn.chat.ChatAreaInput <Enter> key bindning Feature Request pn.chat.ChatAreaInput <Enter> key binding Feature Request Mar 25, 2024
@ahuang11
Copy link
Contributor

I don't fully comprehend the bind to carriage return/line feed or and and/or be bound to Send

The current behavior of to send follows OpenAI, MistralAI, etc.

For multi-line input, use <Shift + Enter>

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 26, 2024

I know about , and I know that is what OpenAI, etc bind to new-line.
It causes me no end of greaf, since most other apps and all my editors use for newline.

Result: I send incomplete prompts to the LLM more often than not.
I am not suggesting you change the default binding,
I am suggesting you give me the option to override the default!

@ahuang11
Copy link
Contributor

ahuang11 commented Mar 26, 2024

Thanks for clarifying. In that case, I'd be happy to accept and review a PR to configure it.

Perhaps a param boolean to swap the order.
https://github.com/holoviz/panel/blob/main/panel/models/chatarea_input.ts#L34

Let me know if you're interested in contributing that PR and I can provide additional info.

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 26, 2024

OK, I can try my hand at it. Hope I won't have to bother you with explanations about how the code works:
about to go have a look!

@ahuang11
Copy link
Contributor

ahuang11 commented Mar 26, 2024

Thanks! #6508 Here's a good PR to use as reference; it adds a new parameter disable_enter and connects the Python to Typescript model (the only irrelevant change is in interface.py)

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 26, 2024

Thinking about it: I'd need explanations of what was meant in the comment PR.

right this moment I think there are three states:
None: Send is disabled
Enter: Send occurs when is pressed
Shift-Enter: Send occurs when is pressed

Actually, I could imagine allowing any combination of Enter, Shift-Enter, or Ctrl-Enter
What do you think?

@ahuang11
Copy link
Contributor

ahuang11 commented Mar 26, 2024

None: Send is disabled

I don't think this should be considered because that's captured by disabled=True

I'm a tad hesitant on Ctrl-Enter because it's unclear in Mac.

Right now I think it could simply be a boolean that swaps the behavior between shift + enter and enter; not entirely swayed for all the keystroke customization until Bokeh natively supports keystroke customization.

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 26, 2024

OK, perfect.

@ahuang11
Copy link
Contributor

When working with typescript models in Panel, don't forget to properly set up your env and run panel build panel upon every typescript change.

See https://panel.holoviz.org/developer_guide/index.html

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 27, 2024

think I got it set up right, and am running panel build panel
Trying to test it with

def output(value):
    return f"Submitted: {value}"

chat_area_input = pn.chat.ChatAreaInput(placeholder=">") #, shift_enter_sends=True)
output_markdown = pn.bind(output, chat_area_input.param.value)
pn.Row(chat_area_input, output_markdown)

Then chat_area_inputs.controls() shows the new variable.
I added some console.log() statements to

    this.el.addEventListener("keydown", (event) => {
      console.log( "keydown event" )

but do not see any keydown event logs?!
Typing a message and hitting Enter works.

Any idea what step I might be missing?

@ahuang11
Copy link
Contributor

Can you create a pr to see the changes

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 27, 2024

I think I did the pr right. Really curious about why I can't see any console logs. (and why it does not yet work... :-D
The console error I do see is

VM265:361 Uncaught (in promise) Error: unknown property panel.models.chatarea_input.ChatAreaInput.shift_enter_sends

@ea42gh
Copy link
Contributor Author

ea42gh commented Mar 27, 2024

Let me work on this some more: this might be related to the comms problem I keep having every so often:
I shut down all but one notebook, reloaded the page, and now I do see the console.log messages.
A bit frustrating, that.

@ahuang11
Copy link
Contributor

ahuang11 commented Jun 13, 2024

Completed in #6592

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

No branches or pull requests

2 participants