mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-30 04:31:49 +02:00
Initial document display
This commit is contained in:
parent
6028523198
commit
66130c8845
@ -90,7 +90,7 @@ def get_application() -> FastAPI:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@application.on_event("startup")
|
@application.on_event("startup")
|
||||||
async def startup_event() -> None:
|
def startup_event() -> None:
|
||||||
from danswer.semantic_search.semantic_search import (
|
from danswer.semantic_search.semantic_search import (
|
||||||
warm_up_models,
|
warm_up_models,
|
||||||
) # To avoid circular imports
|
) # To avoid circular imports
|
||||||
|
@ -81,7 +81,7 @@ async def promote_admin(
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/direct-qa", response_model=QAResponse)
|
@router.get("/direct-qa", response_model=QAResponse)
|
||||||
def direct_qa(question: QAQuestion):
|
def direct_qa(question: QAQuestion = Depends()):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
query = question.query
|
query = question.query
|
||||||
@ -104,7 +104,7 @@ def direct_qa(question: QAQuestion):
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/stream-direct-qa")
|
@router.get("/stream-direct-qa")
|
||||||
def stream_direct_qa(question: QAQuestion):
|
def stream_direct_qa(question: QAQuestion = Depends()):
|
||||||
top_documents_key = "top_documents"
|
top_documents_key = "top_documents"
|
||||||
answer_key = "answer"
|
answer_key = "answer"
|
||||||
quotes_key = "quotes"
|
quotes_key = "quotes"
|
||||||
@ -147,7 +147,7 @@ def stream_direct_qa(question: QAQuestion):
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/keyword-search", response_model=KeywordResponse)
|
@router.get("/keyword-search", response_model=KeywordResponse)
|
||||||
def keyword_search(question: QAQuestion):
|
def keyword_search(question: QAQuestion = Depends()):
|
||||||
ts_client = TSClient.get_instance()
|
ts_client = TSClient.get_instance()
|
||||||
query = question.query
|
query = question.query
|
||||||
collection = question.collection
|
collection = question.collection
|
||||||
|
@ -11,7 +11,7 @@ export const Header: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="bg-gray-800 text-gray-200 py-4">
|
<header className="bg-gray-800 text-gray-200 py-4">
|
||||||
<div className="mx-auto mx-8 flex">
|
<div className="mx-8 flex">
|
||||||
<h1 className="text-2xl font-bold">danswer 💃</h1>
|
<h1 className="text-2xl font-bold">danswer 💃</h1>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -7,14 +7,14 @@ import { SearchResultsDisplay } from "./SearchResultsDisplay";
|
|||||||
import { SearchResponse } from "./types";
|
import { SearchResponse } from "./types";
|
||||||
|
|
||||||
const searchRequest = async (query: string): Promise<SearchResponse> => {
|
const searchRequest = async (query: string): Promise<SearchResponse> => {
|
||||||
const response = await fetch("/api/direct-qa", {
|
const url = new URL("/api/direct-qa", window.location.origin);
|
||||||
method: "POST",
|
const params = new URLSearchParams({
|
||||||
headers: { "Content-Type": "application/json" },
|
query,
|
||||||
body: JSON.stringify({
|
collection: "semantic_search",
|
||||||
query: query,
|
}).toString();
|
||||||
collection: "semantic_search",
|
url.search = params;
|
||||||
}),
|
|
||||||
});
|
const response = await fetch(url);
|
||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Globe, SlackLogo, GoogleDriveLogo } from "@phosphor-icons/react";
|
import { Globe, SlackLogo, GoogleDriveLogo } from "@phosphor-icons/react";
|
||||||
import "tailwindcss/tailwind.css";
|
import "tailwindcss/tailwind.css";
|
||||||
import { SearchResponse } from "./types";
|
import { Quote, SearchResponse } from "./types";
|
||||||
import { ThinkingAnimation } from "./Thinking";
|
import { ThinkingAnimation } from "./Thinking";
|
||||||
|
|
||||||
interface SearchResultsDisplayProps {
|
interface SearchResultsDisplayProps {
|
||||||
@ -38,31 +38,64 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { answer, quotes } = data;
|
const { answer, quotes } = data;
|
||||||
|
|
||||||
if (!answer || !quotes) {
|
if (!answer || !quotes) {
|
||||||
return <div>Unable to find an answer</div>;
|
return <div>Unable to find an answer</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const dedupedQuotes: Quote[] = [];
|
||||||
<div className="p-4 border rounded-md border-gray-700">
|
const seen = new Set<string>();
|
||||||
<h2 className="text font-bold mb-2">Answer</h2>
|
Object.values(quotes).forEach((quote) => {
|
||||||
<p className="mb-4">{answer}</p>
|
if (!seen.has(quote.document_id)) {
|
||||||
|
dedupedQuotes.push(quote);
|
||||||
|
seen.add(quote.document_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
<h2 className="text-sm font-bold mb-2">Sources</h2>
|
return (
|
||||||
<div className="flex">
|
<>
|
||||||
{Object.entries(quotes).map(([_, quoteInfo]) => (
|
<div className="p-4 border rounded-md border-gray-700">
|
||||||
<a
|
<h2 className="text font-bold mb-2">AI Answer</h2>
|
||||||
key={quoteInfo.document_id}
|
<p className="mb-4">{answer}</p>
|
||||||
className="p-2 border border-gray-800 rounded-lg text-sm flex max-w-[230px] hover:bg-gray-800"
|
|
||||||
href={quoteInfo.link}
|
<h2 className="text-sm font-bold mb-2">Sources</h2>
|
||||||
target="_blank"
|
<div className="flex">
|
||||||
rel="noopener noreferrer"
|
{dedupedQuotes.map((quoteInfo) => (
|
||||||
>
|
<a
|
||||||
{getSourceIcon(quoteInfo.source_type)}
|
key={quoteInfo.document_id}
|
||||||
<p className="truncate break-all">{quoteInfo.document_id}</p>
|
className="p-2 border border-gray-800 rounded-lg text-sm flex max-w-[230px] hover:bg-gray-800"
|
||||||
</a>
|
href={quoteInfo.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{getSourceIcon(quoteInfo.source_type)}
|
||||||
|
<p className="truncate break-all">
|
||||||
|
{quoteInfo.semantic_identifier || quoteInfo.document_id}
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-4">
|
||||||
|
<div className="font-bold border-b mb-4 pb-1 border-gray-800">
|
||||||
|
Results
|
||||||
|
</div>
|
||||||
|
{dedupedQuotes.map((quoteInfo) => (
|
||||||
|
<div key={quoteInfo.document_id} className="text-sm">
|
||||||
|
<a
|
||||||
|
className="rounded-lg flex font-bold"
|
||||||
|
href={quoteInfo.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{getSourceIcon(quoteInfo.source_type)}
|
||||||
|
<p className="truncate break-all">
|
||||||
|
{quoteInfo.semantic_identifier || quoteInfo.document_id}
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
<p className="p-2 mb-2 text-gray-200">{quoteInfo.blurb}</p>
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,8 @@ export interface Quote {
|
|||||||
document_id: string;
|
document_id: string;
|
||||||
link: string;
|
link: string;
|
||||||
source_type: string;
|
source_type: string;
|
||||||
|
blurb: string;
|
||||||
|
semantic_identifier: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchResponse {
|
export interface SearchResponse {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user