Skip to content

Commit 393f8af

Browse files
committed
add new annotaion flow: work in progress
1 parent 5a507d0 commit 393f8af

File tree

2 files changed

+134
-11
lines changed

2 files changed

+134
-11
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { Box, Typography, Chip } from '@mui/material'
2+
import { FileSearchCompletedData, FileSearchResultData } from '../../../shared/types'
3+
import { useTranslation } from 'react-i18next'
4+
import { useFileSearchResults } from './api'
5+
import { GrayButton } from './generics/Buttons'
6+
import { ShortText, Subject } from '@mui/icons-material'
7+
8+
9+
const AnnotationBox = ({
10+
data,
11+
relevanceOrder
12+
}: {
13+
data: FileSearchResultData,
14+
relevanceOrder: number // By default the backend returns the RAG results in most relevant results first
15+
}) => {
16+
const lineNum = 3;
17+
const multilineEllipsisTruncate = {
18+
// This is a trick to achieve a multu-line ellipsis truncation for max 3 rows of text.
19+
// -webkit-box is used to support legacy browsers and for WebkitBoxOrient
20+
overflow: 'hidden',
21+
flex: '1',
22+
display: '-webkit-box',
23+
WebkitLineClamp: lineNum,
24+
WebkitBoxOrient: 'vertical',
25+
textOverflow: 'ellipsis',
26+
lineHeight: '1.5',
27+
maxHeight: `calc(1.5em * ${lineNum})`,
28+
}
29+
30+
return (
31+
<Box sx={{ display: 'flex', gap: 2 }}>
32+
<Box sx={{
33+
color: 'black',
34+
backgroundColor: 'rgba(0,0,0,0.12)',
35+
width: 24,
36+
height: 24,
37+
display: 'flex',
38+
justifyContent: 'center',
39+
alignItems: 'center',
40+
borderRadius: '100%',
41+
fontSize: '0.8rem',
42+
mt: '0.4rem'
43+
}}>
44+
{relevanceOrder}
45+
</Box>
46+
<Typography sx={multilineEllipsisTruncate}>
47+
{data.text}
48+
</Typography>
49+
</Box>
50+
)
51+
}
52+
53+
const Queries = ({ queries }: { queries: string[] }) => {
54+
const { t } = useTranslation()
55+
56+
return (<Box
57+
sx={{
58+
display: 'flex',
59+
flexDirection: 'row',
60+
flexWrap: 'wrap',
61+
gap: 1,
62+
mb: 5,
63+
}}
64+
>
65+
<Typography fontWeight={'bold'}>{t('chat:searchTerms')}</Typography>
66+
{queries.map((q, idx) => (
67+
<Chip
68+
key={idx}
69+
label={q}
70+
sx={{
71+
width: 'fit-content',
72+
p: 0.5,
73+
borderRadius: 2,
74+
fontWeight: '600',
75+
height: 'auto',
76+
'& .MuiChip-label': {
77+
display: 'block',
78+
whiteSpace: 'normal',
79+
},
80+
}}
81+
color="info"
82+
/>
83+
))}
84+
</Box>)
85+
}
86+
87+
const Annotations = ({ fileSearchResult }: { fileSearchResult: FileSearchCompletedData }) => {
88+
const { data: results, isSuccess: isResultsSuccess } = useFileSearchResults(fileSearchResult.id)
89+
const arrayResults = Array.isArray(results) ? results : []
90+
const { t } = useTranslation()
91+
92+
93+
return (
94+
<Box>
95+
<Typography variant="h6" fontWeight={'bold'} sx={{ mb: 2.5 }}>
96+
{t('chat:sources')}
97+
</Typography>
98+
<Queries queries={fileSearchResult.queries} />
99+
{isResultsSuccess ?
100+
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '1.5rem', minHeight: 400 }}>
101+
{arrayResults.map((result, i) => (
102+
<AnnotationBox key={i} data={result} relevanceOrder={i + 1} />
103+
))}
104+
{/* <Box>
105+
<GrayButton startIcon={<Subject />}>{t('chat:readMore')}</GrayButton>
106+
</Box> */}
107+
</Box> :
108+
<Typography>Failed to display search results</Typography>
109+
}
110+
</Box>
111+
)
112+
}
113+
114+
export default Annotations

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { SettingsModal } from './SettingsModal'
2828
import { getCompletionStream } from './util'
2929
import { OutlineButtonBlack } from './generics/Buttons'
3030
import useCurrentUser from '../../hooks/useCurrentUser'
31+
import Annotations from './Annotations'
3132
import { enqueueSnackbar } from 'notistack'
3233

3334
export const ChatV2 = () => {
@@ -547,24 +548,32 @@ export const ChatV2 = () => {
547548
</Box>
548549

549550
{/* Annotations columns ----------------------------------------------------------------------------------------------------- */}
550-
<Box
551-
sx={{
552-
flex: 1,
553-
minWidth: 300,
554-
height: '100vh',
555-
position: 'sticky',
556-
top: 70,
557-
}}
558-
>
559-
{showFileSearch && (
551+
552+
553+
{/* {showFileSearch && (
560554
<FileSearchInfo
561555
isFileSearching={isFileSearching}
562556
fileSearchResult={fileSearch}
563557
messages={messages}
564558
ragDisplay={ragDisplay}
565559
toggleRagDisplay={handleRagDisplay}
566560
/>
567-
)}
561+
)} */}
562+
{/* <pre>{isFileSearching}</pre>
563+
<pre>{JSON.stringify(fileSearch, null, 2)}</pre>
564+
<pre>{ragDisplay}</pre> */}
565+
566+
<Box
567+
sx={{
568+
flex: 1,
569+
minWidth: 300,
570+
position: 'relative',
571+
borderLeft: fileSearch ? '1px solid rgba(0, 0, 0, 0.12)' : 'none',
572+
}}
573+
>
574+
<Box sx={{ position: 'sticky', top: 65, padding: '2rem' }}>
575+
{fileSearch && <Annotations fileSearchResult={fileSearch} />}
576+
</Box>
568577
</Box>
569578

570579
{/* Modals --------------------------------------*/}

0 commit comments

Comments
 (0)