From 0a292377322aadd491d0e0eb2706303d4935d614 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Tue, 30 Jul 2024 10:06:52 +0530 Subject: [PATCH] feat(listLineOutputParser): handle invalid keys --- src/lib/outputParsers/listLineOutputParser.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/outputParsers/listLineOutputParser.ts b/src/lib/outputParsers/listLineOutputParser.ts index 57a9bbc..1e2f0f5 100644 --- a/src/lib/outputParsers/listLineOutputParser.ts +++ b/src/lib/outputParsers/listLineOutputParser.ts @@ -22,6 +22,11 @@ class LineListOutputParser extends BaseOutputParser { const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/; const startKeyIndex = text.indexOf(`<${this.key}>`); const endKeyIndex = text.indexOf(``); + + if (startKeyIndex === -1 || endKeyIndex === -1) { + return []; + } + const questionsStartIndex = startKeyIndex === -1 ? 0 : startKeyIndex + `<${this.key}>`.length; const questionsEndIndex = endKeyIndex === -1 ? text.length : endKeyIndex;