(docs: DocumentsWithIndexingStatus[])
| 274 | }; |
| 275 | |
| 276 | const indexDocuments = async (docs: DocumentsWithIndexingStatus[]): Promise<boolean> => { |
| 277 | try { |
| 278 | // TODO: See if we can parallelize this in batches! |
| 279 | for (let i = 0; i < docs.length; i++) { |
| 280 | const doc = docs[i]!; |
| 281 | setProcessingDocumentName(doc.name); |
| 282 | await indexDocument({ |
| 283 | collectionId: Id.from(chat.documentCollectionId!), |
| 284 | doc: doc, |
| 285 | onGeneratedChunk: (chunk) => { |
| 286 | if (chunk.status) { |
| 287 | setProcessingDocumentStatus(chunk.status); |
| 288 | } |
| 289 | }, |
| 290 | }); |
| 291 | setNumberOfProcessedDocuments(i + 1); |
| 292 | } |
| 293 | setProcessingDocumentName(""); |
| 294 | setProcessingDocumentStatus("Processed all documents"); |
| 295 | } catch (e) { |
| 296 | console.error("could not index documents: ", e); |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | return true; |
| 301 | }; |
| 302 | |
| 303 | useEffect(() => { |
| 304 | const chatTitle = chat.title; |
no test coverage detected