Skip to content

Commit c4a6ea4

Browse files
committed
Fix ingestion of multiple files & delete v2
1 parent a7d86c4 commit c4a6ea4

File tree

13 files changed

+66
-585
lines changed

13 files changed

+66
-585
lines changed

src/client/components/ChatV2/Conversation.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { t } from 'i18next'
1818
import FormatQuoteIcon from '@mui/icons-material/FormatQuote'
1919
import useLocalStorageState from '../../hooks/useLocalStorageState'
2020
import { BlueButton } from './general/Buttons'
21-
import { MutableRefObject } from 'react'
2221

2322
const UserMessage = ({ content, attachements }: { content: string; attachements?: string }) => (
2423
<Box
@@ -60,13 +59,13 @@ const AssistantMessage = ({
6059
error,
6160
fileSearchResult,
6261
setActiveFileSearchResult,
63-
setShowAnnotations,
62+
setShowFileSearchResults,
6463
}: {
6564
content: string
6665
error?: string
6766
fileSearchResult?: FileSearchCompletedData
6867
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
69-
setShowAnnotations: (show: boolean) => void
68+
setShowFileSearchResults: (show: boolean) => void
7069
}) => {
7170
const processedContent = preprocessMath(content)
7271
const katexOptions = {
@@ -109,9 +108,9 @@ const AssistantMessage = ({
109108
}
110109
let codeCount = 0
111110

112-
const handleAnnotations = (fileSearchResult: FileSearchCompletedData) => {
111+
const handleFileSearchResult = (fileSearchResult: FileSearchCompletedData) => {
113112
setActiveFileSearchResult(fileSearchResult)
114-
setShowAnnotations(true)
113+
setShowFileSearchResults(true)
115114
}
116115

117116
return (
@@ -232,7 +231,7 @@ const AssistantMessage = ({
232231
borderRadius: '0.6rem',
233232
}}
234233
onClick={() => {
235-
handleAnnotations(fileSearchResult)
234+
handleFileSearchResult(fileSearchResult)
236235
}}
237236
>
238237
<FormatQuoteIcon sx={{ fontSize: '2rem' }} />
@@ -255,7 +254,7 @@ const AssistantMessage = ({
255254
>
256255
{`${t('chat:displaySources')}: `}
257256

258-
<em>{fileSearchResult?.searchedFiles?.join('\r\n')}</em>
257+
<em>{fileSearchResult?.searchedFileNames.join('\r\n')}</em>
259258
</Typography>
260259
</Box>
261260
</Box>
@@ -271,13 +270,13 @@ const MessageItem = ({
271270
isLastAssistantNode,
272271
expandedNodeHeight,
273272
setActiveFileSearchResult,
274-
setShowAnnotations,
273+
setShowFileSearchResults,
275274
}: {
276275
message: Message
277276
isLastAssistantNode: boolean
278277
expandedNodeHeight: number
279278
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
280-
setShowAnnotations: (show: boolean) => void
279+
setShowFileSearchResults: (show: boolean) => void
281280
}) => {
282281
if (message.role === 'assistant') {
283282
return (
@@ -294,7 +293,7 @@ const MessageItem = ({
294293
error={message.error}
295294
fileSearchResult={message.fileSearchResult}
296295
setActiveFileSearchResult={setActiveFileSearchResult}
297-
setShowAnnotations={setShowAnnotations}
296+
setShowFileSearchResults={setShowFileSearchResults}
298297
/>
299298
</Box>
300299
)
@@ -317,7 +316,7 @@ export const Conversation = ({
317316
toolCalls,
318317
isStreaming,
319318
setActiveFileSearchResult,
320-
setShowAnnotations,
319+
setShowFileSearchResults,
321320
}: {
322321
courseName?: string
323322
courseDate?: ActivityPeriod
@@ -328,7 +327,7 @@ export const Conversation = ({
328327
toolCalls: { id: string; name?: string }[]
329328
isStreaming: boolean
330329
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
331-
setShowAnnotations: (show: boolean) => void
330+
setShowFileSearchResults: (show: boolean) => void
332331
}) => {
333332
const [reminderSeen, setReminderSeen] = useLocalStorageState<boolean>('reminderSeen', false)
334333

@@ -356,7 +355,7 @@ export const Conversation = ({
356355
isLastAssistantNode={isLastAssistantNode}
357356
expandedNodeHeight={expandedNodeHeight}
358357
setActiveFileSearchResult={setActiveFileSearchResult}
359-
setShowAnnotations={setShowAnnotations}
358+
setShowFileSearchResults={setShowFileSearchResults}
360359
/>
361360
)
362361
})}
@@ -369,7 +368,7 @@ export const Conversation = ({
369368
isLastAssistantNode={true}
370369
expandedNodeHeight={expandedNodeHeight}
371370
setActiveFileSearchResult={setActiveFileSearchResult}
372-
setShowAnnotations={setShowAnnotations}
371+
setShowFileSearchResults={setShowFileSearchResults}
373372
/>
374373
) : (
375374
<LoadingMessage expandedNodeHeight={expandedNodeHeight} isFileSearching={toolCalls.length > 0} />

src/client/components/ChatV2/FileSearchResults.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const AnnotationTruncated = ({
7171
>
7272
{relevanceOrder}
7373
</Box>
74-
<Typography sx={multilineEllipsisTruncate}>{data.text}</Typography>
74+
<Typography sx={multilineEllipsisTruncate}>{'data.text'}</Typography> {/* @todo fix */}
7575
</Box>
7676
)
7777
}
@@ -119,7 +119,7 @@ const AnnotationExpanded = ({ data, relevanceOrder, isSelected }: { data: FileSe
119119
alignItems: { xs: 'flex-start', md: 'center' },
120120
}}
121121
>
122-
<Typography fontWeight={600}>{data.filename}</Typography>
122+
<Typography fontWeight={600}>{'data.filename'}</Typography> {/* @todo implement file preview */}
123123
<Typography
124124
sx={{
125125
opacity: 0.7,
@@ -145,7 +145,7 @@ const AnnotationExpanded = ({ data, relevanceOrder, isSelected }: { data: FileSe
145145
100% { background-color: #f5f5f5; }
146146
}
147147
`}</style>
148-
<ReactMarkdown remarkPlugins={[remarkGfm]}>{data.text}</ReactMarkdown>
148+
<ReactMarkdown remarkPlugins={[remarkGfm]}>{'data.text'}</ReactMarkdown> {/* @todo implement file preview */}
149149
</Box>
150150
</Box>
151151
</Box>

src/server/routes/ai/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import express from 'express'
22
import fileSearchResultsRouter from './fileSearchResults'
33
import v1Router from './v1'
4-
import v2Router from './v2'
54
import v3Router from './v3'
65

76
const aiRouter = express.Router()
87

98
aiRouter.use('/v1', v1Router)
10-
aiRouter.use('/v2', v2Router)
119
aiRouter.use('/v3', v3Router)
1210

1311
aiRouter.use('/fileSearchResults', fileSearchResultsRouter)

src/server/routes/ai/v2.ts

Lines changed: 0 additions & 208 deletions
This file was deleted.

src/server/routes/rag/ragIndex.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ChatInstance, RagFile, RagIndex, Responsibility } from '../../db/models
66
import { FileStore } from '../../services/rag/fileStore'
77
import type { RequestWithUser } from '../../types'
88
import { ApplicationError } from '../../util/ApplicationError'
9-
import { ingestRagFile } from '../../services/rag/ingestion'
9+
import { ingestRagFiles } from '../../services/rag/ingestion'
1010
import { search } from '../../services/rag/search'
1111
import { getRedisVectorStore } from '../../services/rag/vectorStore'
1212

@@ -193,7 +193,7 @@ ragIndexRouter.post('/upload', [indexUploadDirMiddleware, uploadMiddleware], asy
193193
throw ApplicationError.BadRequest('No files uploaded')
194194
}
195195

196-
const ragFiles: RagFile[] = await Promise.all(
196+
await Promise.all(
197197
req.files.map((file: Express.Multer.File) =>
198198
RagFile.create({
199199
userId: user.id,
@@ -207,13 +207,8 @@ ragIndexRouter.post('/upload', [indexUploadDirMiddleware, uploadMiddleware], asy
207207
),
208208
)
209209

210-
await Promise.all(
211-
ragFiles.map(async (rf) => {
212-
await ingestRagFile(rf, ragIndex.metadata.language)
213-
rf.pipelineStage = 'completed'
214-
await rf.save()
215-
}),
216-
)
210+
// @todo This should be a job
211+
await ingestRagFiles(ragIndex)
217212

218213
res.json({ message: 'Files uploaded successfully' })
219214
})

0 commit comments

Comments
 (0)