Skip to content

Commit f376861

Browse files
committed
feat(output-parsers): add empty check
1 parent 0737701 commit f376861

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/lib/outputParsers/lineOutputParser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class LineOutputParser extends BaseOutputParser<string> {
1919
lc_namespace = ['langchain', 'output_parsers', 'line_output_parser'];
2020

2121
async parse(text: string): Promise<string> {
22+
text = text.trim() || '';
23+
2224
const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/;
2325
const startKeyIndex = text.indexOf(`<${this.key}>`);
2426
const endKeyIndex = text.indexOf(`</${this.key}>`);

src/lib/outputParsers/listLineOutputParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ class LineListOutputParser extends BaseOutputParser<string[]> {
1919
lc_namespace = ['langchain', 'output_parsers', 'line_list_output_parser'];
2020

2121
async parse(text: string): Promise<string[]> {
22+
text = text.trim() || '';
23+
2224
const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/;
2325
const startKeyIndex = text.indexOf(`<${this.key}>`);
2426
const endKeyIndex = text.indexOf(`</${this.key}>`);
2527

26-
if (startKeyIndex === -1 && endKeyIndex === -1) {
28+
if (startKeyIndex === -1 || endKeyIndex === -1) {
2729
return [];
2830
}
2931

0 commit comments

Comments
 (0)