feat(output-parsers): add empty check
This commit is contained in:
parent
0737701de0
commit
f37686189e
2 changed files with 5 additions and 1 deletions
|
@ -19,6 +19,8 @@ class LineOutputParser extends BaseOutputParser<string> {
|
||||||
lc_namespace = ['langchain', 'output_parsers', 'line_output_parser'];
|
lc_namespace = ['langchain', 'output_parsers', 'line_output_parser'];
|
||||||
|
|
||||||
async parse(text: string): Promise<string> {
|
async parse(text: string): Promise<string> {
|
||||||
|
text = text.trim() || '';
|
||||||
|
|
||||||
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}>`);
|
||||||
|
|
|
@ -19,11 +19,13 @@ class LineListOutputParser extends BaseOutputParser<string[]> {
|
||||||
lc_namespace = ['langchain', 'output_parsers', 'line_list_output_parser'];
|
lc_namespace = ['langchain', 'output_parsers', 'line_list_output_parser'];
|
||||||
|
|
||||||
async parse(text: string): Promise<string[]> {
|
async parse(text: string): Promise<string[]> {
|
||||||
|
text = text.trim() || '';
|
||||||
|
|
||||||
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) {
|
if (startKeyIndex === -1 || endKeyIndex === -1) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue