Skip to content

Commit

Permalink
chore: add a simple indicator when using context
Browse files Browse the repository at this point in the history
  • Loading branch information
ydennisy committed Jun 29, 2024
1 parent cfcd110 commit 28e21be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def get_ask_route(
raise HTTPException(429)

query_emb = await NodeEmbedder.embed(q)
if len(node_ids) > 0:
if node_ids:
# TODO: check this node belongs to the user requesting it!
# TODO: add a method to fetch multiple items in one query!
chunks = []
Expand Down
37 changes: 28 additions & 9 deletions frontend/pages/ask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ const router = useRouter();
const apiBase = config.public.apiBase;
const nodeId = route.query.id;
const nodeIds = route.query.ids;
const nodeIds = Array.isArray(route.query.ids)
? route.query.ids
: typeof route.query.ids === 'string'
? route.query.ids.split(',')
: [];
const nodeTitle = route.query.title;
isAskWithNode.value = !!nodeId;
isAskWithNodes.value = !!nodeIds;
isAskWithNodes.value = nodeIds.length > 0;
const chat = async (query: string) => {
isLoading.value = true;
Expand All @@ -71,8 +75,8 @@ const chat = async (query: string) => {
apiUrl = `${apiUrl}&id=${nodeId}`;
}
// TODO: improve this logic!
if (isAskWithNodes.value && typeof nodeIds === 'string') {
for (const id of nodeIds.split(',')) {
if (isAskWithNodes.value) {
for (const id of nodeIds) {
apiUrl += `&id=${id}`;
}
}
Expand Down Expand Up @@ -124,20 +128,17 @@ const chat = async (query: string) => {
const clearAskWithNode = async () => {
await router.replace({});
isAskWithNode.value = false;
isAskWithNodes.value = false;
context.value = [];
};
const preProcessLatex = (text: string) => {
return text.replace(/\\/g, '\\\\');
};
</script>

<template>
<div>
<!-- Search Bar -->
<SearchBar :is-loading="isLoading" @search="chat" />

<!-- Notification Banner -->
<!-- Notification Banner (single node) -->
<div
v-if="isAskWithNode"
class="bg-gray-100 border border-gray-300 text-slate-600 mt-2 px-4 py-2 rounded-md relative"
Expand All @@ -155,6 +156,24 @@ const preProcessLatex = (text: string) => {
>
</div>

<!-- Notification Banner (multi node) -->
<div
v-if="isAskWithNodes"
class="bg-gray-100 border border-gray-300 text-slate-600 mt-2 px-4 py-2 rounded-md relative"
role="alert"
>
<span class="block sm:inline text-xs"
>You are using
<strong class="font-bold text-xs">"{{ nodeIds.length }}"</strong>
documents as context for your question, to use all documents
<strong
class="underline cursor-pointer font-bold text-xs"
@click="clearAskWithNode"
>click here</strong
>.</span
>
</div>

<!-- Context / Chunks Viewer -->
<div v-show="context.length > 0">
<ContextViewer :chunks="context" />
Expand Down

0 comments on commit 28e21be

Please sign in to comment.