Skip to content

Commit

Permalink
fix: code block overflow in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
taprosoft committed Nov 20, 2024
1 parent 747bff8 commit 0e12e32
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 36 deletions.
3 changes: 0 additions & 3 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ developers in mind.
[User Guide](https://cinnamon.github.io/kotaemon/) |
[Developer Guide](https://cinnamon.github.io/kotaemon/development/) |
[Feedback](https://github.com/Cinnamon/kotaemon/issues)

[Dark Mode](?__theme=dark) |
[Light Mode](?__theme=light)
63 changes: 61 additions & 2 deletions libs/ktem/ktem/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ button.selected {
font-weight: bold;
}

.message-row.bubble.bot-row{
overflow-x: auto;
}

.flex-wrap.bot {
overflow-x: inherit;
}

#chat-tab,
#indices-tab,
#settings-tab,
Expand Down Expand Up @@ -191,11 +199,11 @@ mark {
right: 15px;
}

#new-conv-button > img {
/* #new-conv-button > img {
position: relative;
top: 0px;
right: -50%;
}
} */

span.icon {
color: #cecece;
Expand Down Expand Up @@ -271,3 +279,54 @@ pdfjs-viewer-element {
flex: 1;
overflow: auto;
}

/** Switch
-------------------------------------*/

#is-public-checkbox {
position: relative;
top: 4px;
}

.switch input {
position: absolute;
opacity: 0;
}

/**
* 1. Adjust this to size
*/

.switch {
display: inline-block;
/* 1 */
height: 1em;
width: 2em;
background: #8f8f8f;
border-radius: 1em;
position: relative;
top: 2px;
margin-right: 1em;
}

.switch div {
height: 1em;
width: 1em;
border-radius: 1em;
background: #FFF;
box-shadow: 0 0.1em 0.3em rgba(0, 0, 0, 0.3);
-webkit-transition: all 300ms;
-moz-transition: all 300ms;
transition: all 300ms;
}

.switch input:checked+div {
-webkit-transform: translate3d(100%, 0, 0);
-moz-transform: translate3d(100%, 0, 0);
transform: translate3d(100%, 0, 0);
background: #12df9a;
}

.switch:has(> input:checked) {
background: #0c895f;
}
10 changes: 10 additions & 0 deletions libs/ktem/ktem/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ function run() {
let chat_info_panel = document.getElementById("info-expand");
chat_info_panel.insertBefore(info_expand_button, chat_info_panel.childNodes[2]);

// create slider toggle
const is_public_checkbox = document.getElementById("is-public-checkbox");
const label_element = is_public_checkbox.getElementsByTagName("label")[0];
const checkbox_span = is_public_checkbox.getElementsByTagName("span")[0];
new_div = document.createElement("div");

label_element.classList.add("switch");
is_public_checkbox.appendChild(checkbox_span);
label_element.appendChild(new_div)

// clpse
globalThis.clpseFn = (id) => {
var obj = document.getElementById('clpse-btn-' + id);
Expand Down
3 changes: 0 additions & 3 deletions libs/ktem/ktem/assets/md/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ An open-source tool for you to chat with your documents.
[User Guide](https://cinnamon.github.io/kotaemon/) |
[Developer Guide](https://cinnamon.github.io/kotaemon/development/) |
[Feedback](https://github.com/Cinnamon/kotaemon/issues)

[Dark Mode](?__theme=dark)
[Night Mode](?__theme=light)
49 changes: 35 additions & 14 deletions libs/ktem/ktem/pages/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def __init__(self, app):

self._preview_links = gr.State(value=None)
self._reasoning_type = gr.State(value=None)
self._llm_type = gr.State(value=None)
self._conversation_renamed = gr.State(value=False)
self._suggestion_updated = gr.State(value=False)
self._info_panel_expanded = gr.State(value=True)
Expand Down Expand Up @@ -142,20 +141,21 @@ def on_building_ui(self):
with gr.Row():
gr.HTML("Reasoning method")
gr.HTML("Model")
gr.HTML("Generate mindmap")

with gr.Row():
reasoning_type_values = [
(DEFAULT_SETTING, DEFAULT_SETTING)
] + self._app.default_settings.reasoning.settings[
"use"
].choices
self.reasoning_types = gr.Dropdown(
self.reasoning_type = gr.Dropdown(
choices=reasoning_type_values,
value=DEFAULT_SETTING,
container=False,
show_label=False,
)
self.model_types = gr.Dropdown(
self.model_type = gr.Dropdown(
choices=self._app.default_settings.reasoning.options[
"simple"
]
Expand All @@ -165,6 +165,17 @@ def on_building_ui(self):
container=False,
show_label=False,
)
binary_default_choices = [
(DEFAULT_SETTING, DEFAULT_SETTING),
("Enable", True),
("Disable", False),
]
self.use_mindmap = gr.Dropdown(
value=DEFAULT_SETTING,
choices=binary_default_choices,
container=False,
show_label=False,
)

with gr.Column(
scale=INFO_PANEL_SCALES[False], elem_id="chat-info-panel"
Expand Down Expand Up @@ -222,7 +233,8 @@ def on_register_events(self):
self.chat_panel.chatbot,
self._app.settings_state,
self._reasoning_type,
self._llm_type,
self.model_type,
self.use_mindmap,
self.state_chat,
self._app.user_id,
]
Expand Down Expand Up @@ -489,16 +501,11 @@ def on_register_events(self):
+ self._indices_input,
outputs=None,
)
self.reasoning_types.change(
self.reasoning_type.change(
self.reasoning_changed,
inputs=[self.reasoning_types],
inputs=[self.reasoning_type],
outputs=[self._reasoning_type],
)
self.model_types.change(
lambda x: x,
inputs=[self.model_types],
outputs=[self._llm_type],
)
self.chat_control.conversation_id.change(
lambda: gr.update(visible=False),
outputs=self.plot_panel,
Expand Down Expand Up @@ -714,6 +721,7 @@ def create_pipeline(
settings: dict,
session_reasoning_type: str,
session_llm: str,
session_use_mindmap: bool | str,
state: dict,
user_id: int,
*selecteds,
Expand All @@ -730,7 +738,12 @@ def create_pipeline(
- the pipeline objects
"""
# override reasoning_mode by temporary chat page state
print("Session reasoning type", session_reasoning_type)
print(
"Session reasoning type",
session_reasoning_type,
"use mindmap",
session_use_mindmap,
)
print("Session LLM", session_llm)
reasoning_mode = (
settings["reasoning.use"]
Expand All @@ -743,9 +756,16 @@ def create_pipeline(

settings = deepcopy(settings)
llm_setting_key = f"reasoning.options.{reasoning_id}.llm"
if llm_setting_key in settings and session_llm not in (DEFAULT_SETTING, None):
if llm_setting_key in settings and session_llm not in (
DEFAULT_SETTING,
None,
"",
):
settings[llm_setting_key] = session_llm

if session_use_mindmap not in (DEFAULT_SETTING, None):
settings["reasoning.options.simple.create_mindmap"] = session_use_mindmap

# get retrievers
retrievers = []
for index in self._app.index_manager.indices:
Expand Down Expand Up @@ -777,6 +797,7 @@ def chat_fn(
settings,
reasoning_type,
llm_type,
use_mind_map,
state,
user_id,
*selecteds,
Expand All @@ -793,7 +814,7 @@ def chat_fn(

# construct the pipeline
pipeline, reasoning_state = self.create_pipeline(
settings, reasoning_type, llm_type, state, user_id, *selecteds
settings, reasoning_type, llm_type, use_mind_map, state, user_id, *selecteds
)
print("Reasoning state", reasoning_state)
pipeline.set_output_queue(queue)
Expand Down
33 changes: 19 additions & 14 deletions libs/ktem/ktem/pages/chat/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ def __init__(self, app):
def on_building_ui(self):
with gr.Row():
gr.Markdown("## Conversations")
self.btn_new = gr.Button(
value="",
icon=f"{ASSETS_DIR}/new.svg",
min_width=2,
scale=1,
size="sm",
elem_classes=["no-background", "body-text-color"],
elem_id="new-conv-button",
)
self.btn_toggle_dark_mode = gr.Button(
value="",
icon=f"{ASSETS_DIR}/dark_mode.svg",
Expand Down Expand Up @@ -87,6 +78,22 @@ def on_building_ui(self):
)

with gr.Row() as self._new_delete:
self.cb_is_public = gr.Checkbox(
value=False,
label="Shared",
min_width=10,
scale=4,
elem_id="is-public-checkbox",
container=False,
)
self.btn_conversation_rn = gr.Button(
value="",
icon=f"{ASSETS_DIR}/rename.svg",
min_width=2,
scale=1,
size="sm",
elem_classes=["no-background", "body-text-color"],
)
self.btn_del = gr.Button(
value="",
icon=f"{ASSETS_DIR}/delete.svg",
Expand All @@ -95,16 +102,14 @@ def on_building_ui(self):
size="sm",
elem_classes=["no-background", "body-text-color"],
)
self.btn_conversation_rn = gr.Button(
self.btn_new = gr.Button(
value="",
icon=f"{ASSETS_DIR}/rename.svg",
icon=f"{ASSETS_DIR}/new.svg",
min_width=2,
scale=1,
size="sm",
elem_classes=["no-background", "body-text-color"],
)
self.cb_is_public = gr.Checkbox(
value=False, label="Share conversation", min_width=10, scale=6
elem_id="new-conv-button",
)

with gr.Row(visible=False) as self._delete_confirm:
Expand Down

0 comments on commit 0e12e32

Please sign in to comment.