Skip to content

Commit

Permalink
Improve UX (#9)
Browse files Browse the repository at this point in the history
* Go to chat tab when resignin
* Allow placeholder message configurable
* Hide setting tabs if there aren't any settings
  • Loading branch information
trducng authored Apr 4, 2024
1 parent ecf09b2 commit e187e23
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 68 deletions.
80 changes: 49 additions & 31 deletions libs/ktem/ktem/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,57 @@ def ui(self):
"""Render the UI"""
self._tabs = {}

if self.f_user_management:
from ktem.pages.login import LoginPage

with gr.Tab("Welcome", elem_id="login-tab") as self._tabs["login-tab"]:
self.login_page = LoginPage(self)
with gr.Tabs() as self.tabs:
if self.f_user_management:
from ktem.pages.login import LoginPage

with gr.Tab(
"Chat", elem_id="chat-tab", visible=not self.f_user_management
) as self._tabs["chat-tab"]:
self.chat_page = ChatPage(self)
with gr.Tab(
"Welcome", elem_id="login-tab", id="login-tab"
) as self._tabs["login-tab"]:
self.login_page = LoginPage(self)

for index in self.index_manager.indices:
with gr.Tab(
f"{index.name} Index",
elem_id=f"{index.id}-tab",
elem_classes="indices-tab",
"Chat",
elem_id="chat-tab",
id="chat-tab",
visible=not self.f_user_management,
) as self._tabs[f"{index.id}-tab"]:
page = index.get_index_page_ui()
setattr(self, f"_index_{index.id}", page)
) as self._tabs["chat-tab"]:
self.chat_page = ChatPage(self)

for index in self.index_manager.indices:
with gr.Tab(
f"{index.name} Index",
elem_id=f"{index.id}-tab",
elem_classes="indices-tab",
id=f"{index.id}-tab",
visible=not self.f_user_management,
) as self._tabs[f"{index.id}-tab"]:
page = index.get_index_page_ui()
setattr(self, f"_index_{index.id}", page)

with gr.Tab(
"Admin", elem_id="admin-tab", visible=not self.f_user_management
) as self._tabs["admin-tab"]:
self.admin_page = AdminPage(self)
with gr.Tab(
"Admin",
elem_id="admin-tab",
id="admin-tab",
visible=not self.f_user_management,
) as self._tabs["admin-tab"]:
self.admin_page = AdminPage(self)

with gr.Tab(
"Settings", elem_id="settings-tab", visible=not self.f_user_management
) as self._tabs["settings-tab"]:
self.settings_page = SettingsPage(self)
with gr.Tab(
"Settings",
elem_id="settings-tab",
id="settings-tab",
visible=not self.f_user_management,
) as self._tabs["settings-tab"]:
self.settings_page = SettingsPage(self)

with gr.Tab(
"Help", elem_id="help-tab", visible=not self.f_user_management
) as self._tabs["help-tab"]:
self.help_page = HelpPage(self)
with gr.Tab(
"Help",
elem_id="help-tab",
id="help-tab",
visible=not self.f_user_management,
) as self._tabs["help-tab"]:
self.help_page = HelpPage(self)

def on_subscribe_public_events(self):
if self.f_user_management:
Expand All @@ -75,7 +91,7 @@ def signed_in_out(user_id):
else gr.update(visible=False)
)
for k in self._tabs.keys()
)
) + [gr.update(selected="login-tab")]

with Session(engine) as session:
user = session.exec(select(User).where(User.id == user_id)).first()
Expand All @@ -100,14 +116,16 @@ def signed_in_out(user_id):
else:
tabs_update.append(gr.update(visible=True))

tabs_update.append(gr.update(selected="chat-tab"))

return tabs_update

self.subscribe_event(
name="onSignIn",
definition={
"fn": signed_in_out,
"inputs": [self.user_id],
"outputs": list(self._tabs.values()),
"outputs": list(self._tabs.values()) + [self.tabs],
"show_progress": "hidden",
},
)
Expand All @@ -117,7 +135,7 @@ def signed_in_out(user_id):
definition={
"fn": signed_in_out,
"inputs": [self.user_id],
"outputs": list(self._tabs.values()),
"outputs": list(self._tabs.values()) + [self.tabs],
"show_progress": "hidden",
},
)
9 changes: 8 additions & 1 deletion libs/ktem/ktem/pages/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def on_subscribe_public_events(self):
self.chat_control.conversation,
self.chat_control.conversation_rn,
self.chat_panel.chatbot,
self.info_panel,
]
+ self._indices_input,
"show_progress": "hidden",
Expand Down Expand Up @@ -406,13 +407,19 @@ async def chat_fn(self, conversation_id, chat_history, settings, state, *selecte
text, refs = "", ""

len_ref = -1 # for logging purpose
msg_placeholder = getattr(
flowsettings, "KH_CHAT_MSG_PLACEHOLDER", "Thinking ..."
)

print(msg_placeholder)
while True:
try:
response = queue.get_nowait()
except Exception:
state[pipeline.get_info()["id"]] = reasoning_state["pipeline"]
yield chat_history + [(chat_input, text or "Thinking ...")], refs, state
yield chat_history + [
(chat_input, text or msg_placeholder)
], refs, state
continue

if response is None:
Expand Down
97 changes: 61 additions & 36 deletions libs/ktem/ktem/pages/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,41 @@ def __init__(self, app):
self._components = {}
self._reasoning_mode = {}

# render application page if there are application settings
self._render_app_tab = False
if self._default_settings.application.settings:
self._render_app_tab = True

# render index page if there are index settings (general and/or specific)
self._render_index_tab = False
if self._default_settings.index.settings:
self._render_index_tab = True
else:
for sig in self._default_settings.index.options.values():
if sig.settings:
self._render_index_tab = True
break

# render reasoning page if there are reasoning settings
self._render_reasoning_tab = False
if len(self._default_settings.reasoning.settings) > 1:
self._render_reasoning_tab = True
else:
for sig in self._default_settings.reasoning.options.values():
if sig.settings:
self._render_reasoning_tab = True
break

self.on_building_ui()

def on_building_ui(self):
self.setting_save_btn = gr.Button("Save settings")
if self._app.f_user_management:
with gr.Tab("User settings"):
self.user_tab()
with gr.Tab("General application settings"):
self.app_tab()
with gr.Tab("Index settings"):
self.index_tab()
with gr.Tab("Reasoning settings"):
self.reasoning_tab()
self.app_tab()
self.index_tab()
self.reasoning_tab()

def on_subscribe_public_events(self):
"""
Expand Down Expand Up @@ -221,9 +243,10 @@ def change_password(self, user_id, password, password_confirm):
return "", ""

def app_tab(self):
for n, si in self._default_settings.application.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"application.{n}"] = obj
with gr.Tab("General application settings", visible=self._render_app_tab):
for n, si in self._default_settings.application.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"application.{n}"] = obj

def index_tab(self):
# TODO: double check if we need general
Expand All @@ -232,37 +255,39 @@ def index_tab(self):
# obj = render_setting_item(si, si.value)
# self._components[f"index.{n}"] = obj

for pn, sig in self._default_settings.index.options.items():
with gr.Tab(f"Index {pn}"):
for n, si in sig.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"index.options.{pn}.{n}"] = obj
with gr.Tab("Index settings", visible=self._render_index_tab):
for pn, sig in self._default_settings.index.options.items():
with gr.Tab(f"Index {pn}"):
for n, si in sig.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"index.options.{pn}.{n}"] = obj

def reasoning_tab(self):
with gr.Group():
for n, si in self._default_settings.reasoning.settings.items():
if n == "use":
continue
obj = render_setting_item(si, si.value)
self._components[f"reasoning.{n}"] = obj
with gr.Tab("Reasoning settings", visible=self._render_reasoning_tab):
with gr.Group():
for n, si in self._default_settings.reasoning.settings.items():
if n == "use":
continue
obj = render_setting_item(si, si.value)
self._components[f"reasoning.{n}"] = obj

gr.Markdown("### Reasoning-specific settings")
self._components["reasoning.use"] = render_setting_item(
self._default_settings.reasoning.settings["use"],
self._default_settings.reasoning.settings["use"].value,
)
gr.Markdown("### Reasoning-specific settings")
self._components["reasoning.use"] = render_setting_item(
self._default_settings.reasoning.settings["use"],
self._default_settings.reasoning.settings["use"].value,
)

for idx, (pn, sig) in enumerate(
self._default_settings.reasoning.options.items()
):
with gr.Group(
visible=idx == 0,
elem_id=pn,
) as self._reasoning_mode[pn]:
gr.Markdown("**Name**: Description")
for n, si in sig.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"reasoning.options.{pn}.{n}"] = obj
for idx, (pn, sig) in enumerate(
self._default_settings.reasoning.options.items()
):
with gr.Group(
visible=idx == 0,
elem_id=pn,
) as self._reasoning_mode[pn]:
gr.Markdown("**Name**: Description")
for n, si in sig.settings.items():
obj = render_setting_item(si, si.value)
self._components[f"reasoning.options.{pn}.{n}"] = obj

def change_reasoning_mode(self, value):
output = []
Expand Down

0 comments on commit e187e23

Please sign in to comment.