Skip to content

Commit 6d3251b

Browse files
Merge branch 'main' of github.com:UniversityOfHelsinkiCS/gptwrapper
2 parents 2b980a9 + 6fe738d commit 6d3251b

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const ChatV2 = () => {
8181
// RAG states
8282
const [ragIndexId, setRagIndexId] = useState<number | undefined>()
8383
const [ragDisplay, setRagDisplay] = useState<boolean>(true)
84+
const [activeFileSearchResult, setActiveFileSearchResult] = useState<FileSearchCompletedData | undefined>()
8485
const ragIndex = ragIndices?.find((index) => index.id === ragIndexId)
8586

8687
// Refs
@@ -320,7 +321,6 @@ export const ChatV2 = () => {
320321
}
321322
}, [])
322323

323-
// @todo fix this shit when having long file search results
324324
useEffect(() => {
325325
// Scrolls to last assistant message on text generation
326326
if (!appContainerRef?.current || !conversationRef.current || messages.length === 0) return
@@ -411,7 +411,6 @@ export const ChatV2 = () => {
411411
}
412412
}
413413

414-
const showFileSearch = isFileSearching || messages.some((m) => m.fileSearchResult) || fileSearch
415414
const showRagSelector = (ragIndices?.length ?? 0) > 0
416415

417416
return (
@@ -507,9 +506,7 @@ export const ChatV2 = () => {
507506
messages={messages}
508507
completion={completion}
509508
isCompletionDone={isCompletionDone}
510-
fileSearchResult={fileSearch}
511-
ragDisplay={ragDisplay}
512-
toggleRagDisplay={handleRagDisplay}
509+
setActiveFileSearchResult={setActiveFileSearchResult}
513510
/>
514511
</Box>
515512

@@ -549,6 +546,7 @@ export const ChatV2 = () => {
549546
{/* Annotations columns ----------------------------------------------------------------------------------------------------- */}
550547

551548

549+
{/* LEGACY - keep here for legacy when new annotations flow is work in progres */}
552550
{/* {showFileSearch && (
553551
<FileSearchInfo
554552
isFileSearching={isFileSearching}
@@ -567,11 +565,11 @@ export const ChatV2 = () => {
567565
flex: 1,
568566
minWidth: 300,
569567
position: 'relative',
570-
borderLeft: fileSearch ? '1px solid rgba(0, 0, 0, 0.12)' : 'none',
568+
borderLeft: activeFileSearchResult ? '1px solid rgba(0, 0, 0, 0.12)' : 'none',
571569
}}
572570
>
573571
<Box sx={{ position: 'sticky', top: 65, padding: '2rem' }}>
574-
{fileSearch && <Annotations fileSearchResult={fileSearch} />}
572+
{activeFileSearchResult && <Annotations fileSearchResult={activeFileSearchResult} />}
575573
</Box>
576574
</Box>
577575

src/client/components/ChatV2/Conversation.tsx

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import 'katex/dist/katex.min.css'
1515
import 'katex/dist/contrib/mhchem'
1616
import CopyToClipboardButton from '../Chat/CopyToClipboardButton'
1717
import { t } from 'i18next'
18-
import { OutlineButtonBlue } from './generics/Buttons'
18+
import { OutlineButtonBlack, } from './generics/Buttons'
19+
import FormatQuoteIcon from '@mui/icons-material/FormatQuote';
1920

2021
const UserMessage = ({
2122
content,
@@ -73,17 +74,15 @@ const AssistantMessage = ({
7374
error,
7475
isLastAssistantNode,
7576
expandedNodeHeight,
76-
fileSearchStatus,
77-
ragDisplay,
78-
toggleRagDisplay,
77+
fileSearchResult,
78+
setActiveFileSearchResult
7979
}: {
8080
content: string
8181
error?: string
8282
isLastAssistantNode: boolean
8383
expandedNodeHeight: number
84-
fileSearchStatus: boolean
85-
ragDisplay: boolean
86-
toggleRagDisplay: () => void
84+
fileSearchResult?: FileSearchCompletedData
85+
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
8786
}) => {
8887
const processedContent = preprocessMath(content)
8988
const katexOptions = {
@@ -209,11 +208,12 @@ const AssistantMessage = ({
209208
<Typography variant="body1" fontStyle="italic" color="#cc0000">{`\n\n ${error}`}</Typography>
210209
</Box>
211210
)}
212-
{isLastAssistantNode && fileSearchStatus && (
213-
<OutlineButtonBlue sx={{ padding: '0.4rem 0.8rem', fontSize: '14px' }} onClick={() => toggleRagDisplay()}>
214-
{ragDisplay ? t('chat:hideSources') : t('chat:displaySources')}
215-
</OutlineButtonBlue>
216-
)}
211+
{/* {ragDisplay ? t('chat:hideSources') : t('chat:displaySources')} */}
212+
{fileSearchResult?.status === "completed" &&
213+
<OutlineButtonBlack sx={{ mt: 3 }} startIcon={<FormatQuoteIcon />} onClick={() => setActiveFileSearchResult(fileSearchResult)}>
214+
<Typography variant='body2'>Lähteet: <em>{fileSearchResult.id}</em></Typography>
215+
</OutlineButtonBlack>
216+
}
217217
</Box>
218218
</Box>
219219
)
@@ -223,14 +223,12 @@ const MessageItem = ({
223223
message,
224224
isLastAssistantNode,
225225
expandedNodeHeight,
226-
ragDisplay,
227-
toggleRagDisplay,
226+
setActiveFileSearchResult
228227
}: {
229228
message: Message
230229
isLastAssistantNode: boolean
231230
expandedNodeHeight: number
232-
ragDisplay: boolean
233-
toggleRagDisplay: () => void
231+
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
234232
}) => {
235233

236234
if (message.role === 'assistant') {
@@ -240,9 +238,8 @@ const MessageItem = ({
240238
error={message.error}
241239
isLastAssistantNode={isLastAssistantNode}
242240
expandedNodeHeight={expandedNodeHeight}
243-
fileSearchStatus={message.fileSearchResult?.status == 'completed'}
244-
ragDisplay={ragDisplay}
245-
toggleRagDisplay={toggleRagDisplay}
241+
fileSearchResult={message.fileSearchResult}
242+
setActiveFileSearchResult={setActiveFileSearchResult}
246243
/>
247244
)
248245
} else {
@@ -265,9 +262,7 @@ export const Conversation = ({
265262
messages,
266263
completion,
267264
isCompletionDone,
268-
fileSearchResult,
269-
ragDisplay,
270-
toggleRagDisplay,
265+
setActiveFileSearchResult
271266
}: {
272267
courseName?: string
273268
courseDate?: ActivityPeriod
@@ -276,9 +271,7 @@ export const Conversation = ({
276271
messages: Message[]
277272
completion: string
278273
isCompletionDone: boolean
279-
fileSearchResult?: FileSearchCompletedData
280-
ragDisplay: boolean
281-
toggleRagDisplay: () => void
274+
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
282275
}) => (
283276
<Box
284277
style={{
@@ -300,20 +293,18 @@ export const Conversation = ({
300293
message={message}
301294
isLastAssistantNode={isLastAssistantNode}
302295
expandedNodeHeight={expandedNodeHeight}
303-
ragDisplay={ragDisplay}
304-
toggleRagDisplay={toggleRagDisplay}
296+
setActiveFileSearchResult={setActiveFileSearchResult}
305297
/>
306298
)
307299
})}
308300
{!isCompletionDone &&
309301
messages.length > 0 &&
310302
(completion.length > 0 ? (
311303
<MessageItem
312-
message={{ role: 'assistant', content: completion, fileSearchResult }}
304+
message={{ role: 'assistant', content: completion }}
313305
isLastAssistantNode={true}
314306
expandedNodeHeight={expandedNodeHeight}
315-
ragDisplay={ragDisplay}
316-
toggleRagDisplay={toggleRagDisplay}
307+
setActiveFileSearchResult={setActiveFileSearchResult}
317308
/>
318309
) : (
319310
<LoadingMessage expandedNodeHeight={expandedNodeHeight} />

0 commit comments

Comments
 (0)