Skip to content

Commit

Permalink
feat: separate disabled_send and disabled_input so we can type while …
Browse files Browse the repository at this point in the history
…the AI replies
  • Loading branch information
maartenbreddels committed Dec 20, 2024
1 parent 79baf37 commit e62acf4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions solara/lab/components/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def ChatBox(
def ChatInput(
send_callback: Optional[Callable[[str], None]] = None,
disabled: bool = False,
disabled_input: bool = False,
disabled_send: bool = False,
style: Optional[Union[str, Dict[str, str]]] = None,
autofocus: bool = False,
input_text_style: Optional[Union[str, Dict[str, str]]] = None,
Expand All @@ -57,8 +59,9 @@ def ChatInput(
# Arguments
* `send_callback`: A callback function for when the user presses enter or clicks the send button taking the message as an argument.
* `disabled`: Whether the input should be disabled. Useful for disabling sending further messages while a chatbot is replying,
among other things.
* `disabled`: disable both input and send.
* `disabled_input`: Whether the input should be disabled. Useful for disabling messages while a chatbot is replying.
* `disabled_send`: Whether the send button should be disabled. Useful for disabling sending further messages while a chatbot is replying.
* `style`: CSS styles to apply to the `solara.Row` containing the input field and submit button. Either a string or a dictionary.
* `autofocus`: Determines if a component is to be autofocused or not (Default is False). Autofocus will occur during page load and only one component per page can have autofocus active.
* `input_text_style`: CSS styles to apply to the `InputText` part of the component. Either a string or a dictionary.
Expand Down Expand Up @@ -88,13 +91,13 @@ def send(*ignore_args):
hide_details=True,
autofocus=autofocus,
style_="flex-grow: 1;" + input_text_style_flat,
disabled=disabled,
disabled=disabled or disabled_input,
class_=" ".join(input_text_classes),
)

use_change(message_input, send, update_events=["keyup.enter"])

button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "")
button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "" or disabled or disabled_send)

use_change(button, send, update_events=["click"])

Expand Down
4 changes: 3 additions & 1 deletion solara/website/pages/documentation/examples/ai/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ def Page():
if promt_ai.pending:
solara.Text("I'm thinking...", style={"font-size": "1rem", "padding-left": "20px"})
solara.ProgressLinear()
solara.lab.ChatInput(send_callback=promt_ai, disabled=promt_ai.pending)
# if we don't call .key(..) with a unique key, the ChatInput component will be re-created
# and we'll lose what we typed.
solara.lab.ChatInput(send_callback=promt_ai, disabled_send=promt_ai.pending, autofocus=True).key("input")

0 comments on commit e62acf4

Please sign in to comment.