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

config quick fix : disable sliders if "Ragna/Demo" #155

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
48 changes: 39 additions & 9 deletions ragna/_ui/modal_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@ class ChatConfig(param.Parameterized):
bounds=(100, 10_000),
)

def is_assistant_disabled(self):
return "Ragna/Demo" in self.assistant_name

def is_source_storage_disabled(self):
return "Ragna/Demo" in self.source_storage_name

def to_params_dict(self):
return {
"chunk_overlap": self.chunk_overlap,
"chunk_size": self.chunk_size,
"num_tokens": self.max_context_tokens,
"max_new_tokens": self.max_new_tokens,
}
result = {}
if not self.is_assistant_disabled():
result["max_new_tokens"] = self.max_new_tokens

if not self.is_source_storage_disabled():
result["chunk_overlap"] = self.chunk_overlap
result["chunk_size"] = self.chunk_size
result["num_tokens"] = self.max_context_tokens

return result


class ModalConfiguration(pn.viewable.Viewer):
Expand All @@ -65,6 +75,8 @@ class ModalConfiguration(pn.viewable.Viewer):
new_chat_ready_callback = param.Callable()
cancel_button_callback = param.Callable()

advanced_config_collapsed = param.Boolean(default=True)

def __init__(self, api_wrapper, **params):
super().__init__(chat_name=get_default_chat_name(), **params)

Expand Down Expand Up @@ -191,11 +203,14 @@ async def model_section(self):
),
)

@pn.depends("config")
@pn.depends("config", "config.assistant_name", "config.source_storage_name")
def advanced_config_ui(self):
if self.config is None:
return

disabled_assistant = self.config.is_assistant_disabled()
disabled_source_storage = self.config.is_source_storage_disabled()

card = pn.Card(
pn.Row(
pn.Column(
Expand All @@ -211,13 +226,17 @@ def advanced_config_ui(self):
bar_color=ui.MAIN_COLOR,
stylesheets=[ui.SS_LABEL_STYLE],
width_policy="max",
disabled=disabled_source_storage,
css_classes=["disabled"] if disabled_source_storage else [],
),
pn.widgets.IntSlider.from_param(
self.config.param.chunk_overlap,
name="Chunk Overlap",
bar_color=ui.MAIN_COLOR,
stylesheets=[ui.SS_LABEL_STYLE],
width_policy="max",
disabled=disabled_source_storage,
css_classes=["disabled"] if disabled_source_storage else [],
),
margin=(0, 20, 0, 0),
width_policy="max",
Expand All @@ -234,12 +253,16 @@ def advanced_config_ui(self):
bar_color=ui.MAIN_COLOR,
stylesheets=[ui.SS_LABEL_STYLE],
width_policy="max",
disabled=disabled_source_storage,
css_classes=["disabled"] if disabled_source_storage else [],
),
pn.widgets.IntSlider.from_param(
self.config.param.max_new_tokens,
bar_color=ui.MAIN_COLOR,
stylesheets=[ui.SS_LABEL_STYLE],
width_policy="max",
disabled=disabled_assistant,
css_classes=["disabled"] if disabled_assistant else [],
),
width_policy="max",
height_policy="max",
Expand All @@ -250,14 +273,21 @@ def advanced_config_ui(self):
),
height=250,
),
collapsed=True,
collapsed=self.advanced_config_collapsed,
collapsible=True,
hide_header=True,
stylesheets=[ui.SS_ADVANCED_UI_CARD],
)

def toggle_card(event):
card.collapsed = not card.collapsed
if event.old < event.new:
# This callback is triggered when the card is rerendered,
# after changing the assistant, for example.
# This test prevents collapsing the card when it is not needed

card.collapsed = not card.collapsed
self.advanced_config_collapsed = card.collapsed

toggle_button = event.obj

if card.collapsed:
Expand Down
16 changes: 16 additions & 0 deletions ragna/_ui/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ def divider():
.noUi-handle, .noUi-connects {
background-color: var(--clear-button-active);
}

.noUi-target[disabled='true'] {
border-color: darkgray;
}


.noUi-target[disabled='true'] .noUi-connect {
background-color: darkgray !important;
}


:host(.disabled) div.bk-slider-title {
color: darkgray !important;
}


"""


Expand Down
Loading