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

Feat chatinput improvements #941

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions solara/lab/components/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ 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,
classes: List[str] = [],
input_text_classes: List[str] = [],
Expand All @@ -56,9 +59,11 @@ 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.
* `classes`: A list of CSS classes to apply to the component. Also applied to the container.
* `input_text_classes`: A list of CSS classes to apply to the `InputText` part of the component.
Expand All @@ -84,14 +89,15 @@ def send(*ignore_args):
rounded=True,
filled=True,
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")
Loading