From f37686189e5fe2d74d3fbfa91c15ed35e8cadcab Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Fri, 31 Jan 2025 17:51:16 +0530 Subject: [PATCH] feat(output-parsers): add empty check --- src/lib/outputParsers/lineOutputParser.ts | 2 ++ src/lib/outputParsers/listLineOutputParser.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/outputParsers/lineOutputParser.ts b/src/lib/outputParsers/lineOutputParser.ts index b50a20e..08711aa 100644 --- a/src/lib/outputParsers/lineOutputParser.ts +++ b/src/lib/outputParsers/lineOutputParser.ts @@ -19,6 +19,8 @@ class LineOutputParser extends BaseOutputParser { lc_namespace = ['langchain', 'output_parsers', 'line_output_parser']; async parse(text: string): Promise { + text = text.trim() || ''; + const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/; const startKeyIndex = text.indexOf(`<${this.key}>`); const endKeyIndex = text.indexOf(``); diff --git a/src/lib/outputParsers/listLineOutputParser.ts b/src/lib/outputParsers/listLineOutputParser.ts index fcd2f07..f465ef1 100644 --- a/src/lib/outputParsers/listLineOutputParser.ts +++ b/src/lib/outputParsers/listLineOutputParser.ts @@ -19,11 +19,13 @@ class LineListOutputParser extends BaseOutputParser { lc_namespace = ['langchain', 'output_parsers', 'line_list_output_parser']; async parse(text: string): Promise { + text = text.trim() || ''; + const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/; const startKeyIndex = text.indexOf(`<${this.key}>`); const endKeyIndex = text.indexOf(``); - if (startKeyIndex === -1 && endKeyIndex === -1) { + if (startKeyIndex === -1 || endKeyIndex === -1) { return []; }