Skip to content

Commit 05628a4

Browse files
commented code
1 parent fadf44d commit 05628a4

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/App/frontend/src/components/Citations/AnswerParser.tsx

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { cloneDeep } from "lodash-es";
21
import { AskResponse, Citation } from "../../types/AppTypes";
32

43

@@ -15,31 +14,31 @@ const isDuplicate = (citation: Citation,citationIndex:string) => {
1514
};
1615

1716
export function parseAnswer(answer: AskResponse): ParsedAnswer {
18-
let answerText = answer.answer;
19-
const citationLinks = answerText?.match(/\[(doc\d\d?\d?)]/g);
20-
21-
const lengthDocN = "[doc".length;
22-
23-
filteredCitations = [] as Citation[];
24-
let citationReindex = 0;
25-
citationLinks?.forEach(link => {
26-
// Replacing the links/citations with number
27-
let citationIndex = link.slice(lengthDocN, link?.length - 1);
28-
let citation = cloneDeep(answer.citations[Number(citationIndex) - 1]) as Citation;
29-
30-
if (citation !== undefined && !isDuplicate(citation, citationIndex)) {
31-
answerText = answerText?.replaceAll(link, ` ^${++citationReindex}^ `);
32-
citation.id = citationIndex; // original doc index to de-dupe
33-
citation.reindex_id = citationReindex.toString(); // reindex from 1 for display
34-
filteredCitations.push(citation);
35-
}else{
36-
// Replacing duplicate citation with original index
37-
let matchingCitation = filteredCitations.find((ct) => citation?.chunk_id == ct?.chunk_id);
38-
if (matchingCitation) {
39-
answerText= answerText.replaceAll(link, ` ^${matchingCitation.reindex_id}^ `)
40-
}
41-
}
42-
})
17+
// let answerText = answer.answer;
18+
// const citationLinks = answerText.match(/\[(doc\d\d?\d?)]/g);
19+
20+
// const lengthDocN = "[doc".length;
21+
22+
// filteredCitations = [] as Citation[];
23+
// let citationReindex = 0;
24+
// citationLinks?.forEach(link => {
25+
// // Replacing the links/citations with number
26+
// let citationIndex = link.slice(lengthDocN, link.length - 1);
27+
// let citation = cloneDeep(answer.citations[Number(citationIndex) - 1]) as Citation;
28+
29+
// if (citation !== undefined && !isDuplicate(citation, citationIndex)) {
30+
// answerText = answerText.replaceAll(link, ` ^${++citationReindex}^ `);
31+
// citation.id = citationIndex; // original doc index to de-dupe
32+
// citation.reindex_id = citationReindex.toString(); // reindex from 1 for display
33+
// filteredCitations.push(citation);
34+
// }else{
35+
// // Replacing duplicate citation with original index
36+
// let matchingCitation = filteredCitations.find((ct) => citation?.chunk_id == ct?.chunk_id);
37+
// if (matchingCitation) {
38+
// answerText= answerText.replaceAll(link, ` ^${matchingCitation.reindex_id}^ `)
39+
// }
40+
// }
41+
// })
4342

4443

4544
return {

0 commit comments

Comments
 (0)