({
collectionId,
doc,
onGeneratedChunk,
}: {
collectionId: Id<DocumentCollectionResponse>,
doc: DocumentsWithIndexingStatus;
onGeneratedChunk: (chunk: StreamChunkResponse) => void;
})
| 481 | }; |
| 482 | |
| 483 | const indexDocument = async ({ |
| 484 | collectionId, |
| 485 | doc, |
| 486 | onGeneratedChunk, |
| 487 | }: { |
| 488 | collectionId: Id<DocumentCollectionResponse>, |
| 489 | doc: DocumentsWithIndexingStatus; |
| 490 | onGeneratedChunk: (chunk: StreamChunkResponse) => void; |
| 491 | }): Promise<void> => { |
| 492 | return new Promise((resolve, reject) => { |
| 493 | if (doc.indexingStatus === DocumentIndexingStatus.INDEXED) { |
| 494 | resolve(); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | postStreaming<{}>({ |
| 499 | input: documentCollectionDocumentIndexApiPath( |
| 500 | collectionId, |
| 501 | Id.from(doc.id), |
| 502 | ), |
| 503 | req: {}, |
| 504 | onGeneratedChunk: (chunk) => { |
| 505 | let parsedResponses = []; |
| 506 | try { |
| 507 | const lines = chunk.split("\n").filter((l) => !isEmpty(l)); |
| 508 | parsedResponses = lines.map((line) => JSON.parse(line)); |
| 509 | } catch (e) { |
| 510 | console.log("could not parse stream chunk response", chunk, e); |
| 511 | } |
| 512 | parsedResponses.forEach((r) => { |
| 513 | if (r.error) { |
| 514 | reject(r.error); |
| 515 | } |
| 516 | |
| 517 | onGeneratedChunk(r); |
| 518 | }); |
| 519 | }, |
| 520 | onFinish: () => { |
| 521 | resolve(); |
| 522 | }, |
| 523 | }); |
| 524 | }); |
| 525 | }; |
| 526 | |
| 527 | const toCitationMap = ( |
| 528 | citations: CitationResponse[] | undefined, |
no test coverage detected