Skip to content

Commit

Permalink
Clean citation cards (onyx-dot-app#3396)
Browse files Browse the repository at this point in the history
* seed

* initial steps

* clean up

* fully clickable
  • Loading branch information
pablonyx authored and Aron Szanto committed Dec 23, 2024
1 parent c623148 commit 3f8bd8b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
3 changes: 1 addition & 2 deletions backend/danswer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from danswer.natural_language_processing.search_nlp_models import EmbeddingModel
from danswer.natural_language_processing.search_nlp_models import warm_up_bi_encoder
from danswer.natural_language_processing.search_nlp_models import warm_up_cross_encoder
from danswer.seeding.load_docs import seed_initial_documents
from danswer.seeding.load_yamls import load_chat_yamls
from danswer.server.manage.llm.models import LLMProviderUpsertRequest
from danswer.server.settings.store import load_settings
Expand Down Expand Up @@ -151,7 +150,7 @@ def setup_danswer(
# update multipass indexing setting based on GPU availability
update_default_multipass_indexing(db_session)

seed_initial_documents(db_session, tenant_id, cohere_enabled)
# seed_initial_documents(db_session, tenant_id, cohere_enabled)


def translate_saved_search_settings(db_session: Session) -> None:
Expand Down
20 changes: 6 additions & 14 deletions web/src/app/chat/message/MemoizedTextComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Citation } from "@/components/search/results/Citation";
import { WebResultIcon } from "@/components/WebResultIcon";
import { LoadedDanswerDocument } from "@/lib/search/interfaces";
import { getSourceMetadata } from "@/lib/sources";
import { getSourceMetadata, SOURCE_METADATA_MAP } from "@/lib/sources";
import { ValidSources } from "@/lib/types";
import React, { memo } from "react";
import isEqual from "lodash/isEqual";
import { SlackIcon } from "@/components/icons/icons";
import { SourceIcon } from "@/components/SourceIcon";

export const MemoizedAnchor = memo(
({ docs, updatePresentingDocument, children }: any) => {
Expand All @@ -19,19 +21,9 @@ export const MemoizedAnchor = memo(
? new URL(associatedDoc.link).origin + "/favicon.ico"
: "";

const getIcon = (sourceType: ValidSources, link: string) => {
return getSourceMetadata(sourceType).icon({ size: 18 });
};

const icon =
associatedDoc?.source_type === "web" ? (
<WebResultIcon url={associatedDoc.link} />
) : (
getIcon(
associatedDoc?.source_type || "web",
associatedDoc?.link || ""
)
);
const icon = (
<SourceIcon sourceType={associatedDoc?.source_type} iconSize={18} />
);

return (
<MemoizedLink
Expand Down
20 changes: 16 additions & 4 deletions web/src/components/search/DocumentDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CustomTooltip, TooltipGroup } from "../tooltip/CustomTooltip";
import { WarningCircle } from "@phosphor-icons/react";
import TextView from "../chat_search/TextView";
import { SearchResultIcon } from "../SearchResultIcon";
import { ValidSources } from "@/lib/types";

export const buildDocumentSummaryDisplay = (
matchHighlights: string[],
Expand Down Expand Up @@ -425,21 +426,32 @@ export function CompactDocumentCard({
document,
icon,
url,
updatePresentingDocument,
}: {
document: LoadedDanswerDocument;
icon?: React.ReactNode;
url?: string;
updatePresentingDocument: (documentIndex: LoadedDanswerDocument) => void;
}) {
return (
<div className="max-w-[250px] pb-0 pt-0 mt-0 flex gap-y-0 flex-col content-start items-start gap-0 ">
<h3 className="text-sm font-semibold flex items-center gap-x-1 text-text-900 pt-0 mt-0 truncate w-full">
<div
onClick={() => {
if (document.source_type === ValidSources.File) {
updatePresentingDocument(document);
} else if (document.link) {
window.open(document.link, "_blank");
}
}}
className="max-w-[250px] cursor-pointer pb-0 pt-0 mt-0 flex gap-y-0 flex-col content-start items-start gap-0 "
>
<div className="text-sm font-semibold flex items-center gap-x-1 text-text-900 pt-0 mt-0 truncate w-full">
{icon}
{(document.semantic_identifier || document.document_id).slice(0, 40)}
{(document.semantic_identifier || document.document_id).length > 40 &&
"..."}
</h3>
</div>
{document.blurb && (
<p className="text-xs mb-0 text-gray-600 line-clamp-2">
<p className="text-xs mb-0 text-gray-600 line-clamp-2">
{document.blurb}
</p>
)}
Expand Down
7 changes: 6 additions & 1 deletion web/src/components/search/results/Citation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export function Citation({
</div>
</TooltipTrigger>
<TooltipContent width="mb-2 max-w-lg" className="bg-background">
<CompactDocumentCard url={url} icon={icon} document={document} />
<CompactDocumentCard
updatePresentingDocument={updatePresentingDocument}
url={url}
icon={icon}
document={document}
/>
</TooltipContent>
</Tooltip>
</TooltipProvider>
Expand Down

0 comments on commit 3f8bd8b

Please sign in to comment.