feat(listLineOutputParser): handle invalid keys

This commit is contained in:
ItzCrazyKns 2024-07-30 10:06:52 +05:30
parent c62e7f091e
commit 0a29237732
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
1 changed files with 5 additions and 0 deletions

View File

@ -22,6 +22,11 @@ class LineListOutputParser extends BaseOutputParser<string[]> {
const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/; const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/;
const startKeyIndex = text.indexOf(`<${this.key}>`); const startKeyIndex = text.indexOf(`<${this.key}>`);
const endKeyIndex = text.indexOf(`</${this.key}>`); const endKeyIndex = text.indexOf(`</${this.key}>`);
if (startKeyIndex === -1 || endKeyIndex === -1) {
return [];
}
const questionsStartIndex = const questionsStartIndex =
startKeyIndex === -1 ? 0 : startKeyIndex + `<${this.key}>`.length; startKeyIndex === -1 ? 0 : startKeyIndex + `<${this.key}>`.length;
const questionsEndIndex = endKeyIndex === -1 ? text.length : endKeyIndex; const questionsEndIndex = endKeyIndex === -1 ? text.length : endKeyIndex;