Skip to content

feat: add citation style quick setting #554

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

Merged
merged 1 commit into from
Dec 5, 2024
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
9 changes: 9 additions & 0 deletions libs/kotaemon/kotaemon/llms/chats/langchain_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ class LCGeminiChat(LCChatMixin, ChatLLM): # type: ignore
required=True,
)

def _get_tool_call_kwargs(self):
return {
"tool_config": {
"function_calling_config": {
"mode": "ANY",
}
}
}

def __init__(
self,
api_key: str | None = None,
Expand Down
21 changes: 17 additions & 4 deletions libs/ktem/ktem/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ mark {
position: absolute;
top: 6px;
right: -10px;
z-index: 10;
z-index: 1;
}

#quick-setting-labels {
margin-top: 5px;
margin-bottom: -10px;
}

#use-mindmap-checkbox {
Expand All @@ -218,6 +223,14 @@ mark {
right: 25px;
}

#citation-dropdown {
width: min(25%, 100px);
position: absolute;
top: 2px;
left: 120px;
height: 35px;
}

#quick-url textarea {
resize: none;
background: transparent;
Expand Down Expand Up @@ -262,7 +275,7 @@ pdfjs-viewer-element {
.modal {
display: none;
position: relative;
z-index: 1;
z-index: 2;
left: 0;
top: 0;
width: 100%;
Expand Down Expand Up @@ -351,11 +364,11 @@ pdfjs-viewer-element {
/* Bot animation */

.message.bot {
animation: fadein 1.5s ease-in-out forwards;
animation: fadein 1.0s ease-in-out forwards;
}

details.evidence {
animation: fadein 0.5s ease-in-out forwards;
animation: fadein 0.3s ease-in-out forwards;
}

@keyframes fadein {
Expand Down
2 changes: 2 additions & 0 deletions libs/ktem/ktem/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ function run() {

// move use mind-map checkbox
let mindmap_checkbox = document.getElementById("use-mindmap-checkbox");
let citation_dropdown = document.getElementById("citation-dropdown");
let chat_setting_panel = document.getElementById("chat-settings-expand");
chat_setting_panel.insertBefore(mindmap_checkbox, chat_setting_panel.childNodes[2]);
chat_setting_panel.insertBefore(citation_dropdown, mindmap_checkbox);

// create slider toggle
const is_public_checkbox = document.getElementById("is-public-checkbox");
Expand Down
5 changes: 2 additions & 3 deletions libs/ktem/ktem/pages/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ def on_building_ui(self):
elem_id="chat-settings-expand",
open=False,
):
# a quick switch for reasoning type option
with gr.Row():
with gr.Row(elem_id="quick-setting-labels"):
gr.HTML("Reasoning method")
gr.HTML("Model")
gr.HTML("Language")
gr.HTML("Citation")

with gr.Row():
reasoning_type_values = [
Expand Down Expand Up @@ -236,6 +234,7 @@ def on_building_ui(self):
container=False,
show_label=False,
interactive=True,
elem_id="citation-dropdown",
)

self.use_mindmap = gr.State(value=DEFAULT_SETTING)
Expand Down
16 changes: 13 additions & 3 deletions libs/ktem/ktem/reasoning/prompt_optimization/decompose_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ def run(self, question: str) -> list: # type: ignore
sub_queries = []
if tool_calls:
for tool_call in tool_calls:
if "function" in tool_call:
# openai and cohere format
function_output = tool_call["function"]["arguments"]
else:
# anthropic format
function_output = tool_call["args"]

if isinstance(function_output, str):
sub_query = SubQuery.parse_raw(function_output).sub_query
else:
sub_query = SubQuery.parse_obj(function_output).sub_query

sub_queries.append(
Document(
content=SubQuery.parse_raw(
tool_call["function"]["arguments"]
).sub_query
content=sub_query,
)
)

Expand Down
6 changes: 3 additions & 3 deletions libs/ktem/ktem/reasoning/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ def get_user_settings(cls) -> dict:
"value": "highlight",
"component": "radio",
"choices": [
("highlight (long answer)", "highlight"),
("inline (precise answer)", "inline"),
("off", "off"),
("highlight (verbose)", "highlight"),
("inline (concise)", "inline"),
("no citation", "off"),
],
},
"create_mindmap": {
Expand Down
Loading