Skip to content

Commit 23df705

Browse files
committed
Citation issue fix
1 parent be26d31 commit 23df705

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/frontend/src/components/Answer/AnswerParser.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ type HtmlParsedAnswer = {
66
citations: string[];
77
};
88

9+
// Function to check citation format
10+
// Citation format: AnyFileName.anyExtension
11+
function isValidCitation(citation: string): boolean {
12+
const regex = /^[^\s]+\.[a-zA-Z0-9]+/;
13+
return regex.test(citation);
14+
}
15+
916
export function parseAnswerToHtml(answer: string, isStreaming: boolean, onCitationClicked: (citationFilePath: string) => void): HtmlParsedAnswer {
1017
const citations: string[] = [];
1118

@@ -34,6 +41,11 @@ export function parseAnswerToHtml(answer: string, isStreaming: boolean, onCitati
3441
return part;
3542
} else {
3643
let citationIndex: number;
44+
45+
if (!isValidCitation(part)) {
46+
return `[${part}]`;
47+
}
48+
3749
if (citations.indexOf(part) !== -1) {
3850
citationIndex = citations.indexOf(part) + 1;
3951
} else {

0 commit comments

Comments
 (0)