mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-14 11:38:14 +00:00
feat(lineOutputParser): return undefined on invalid tags
This commit is contained in:
@@ -4,7 +4,7 @@ interface LineOutputParserArgs {
|
|||||||
key?: string;
|
key?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LineOutputParser extends BaseOutputParser<string> {
|
class LineOutputParser extends BaseOutputParser<string | undefined> {
|
||||||
private key = 'questions';
|
private key = 'questions';
|
||||||
|
|
||||||
constructor(args?: LineOutputParserArgs) {
|
constructor(args?: LineOutputParserArgs) {
|
||||||
@@ -18,7 +18,7 @@ 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 | undefined> {
|
||||||
text = text.trim() || '';
|
text = text.trim() || '';
|
||||||
|
|
||||||
const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/;
|
const regex = /^(\s*(-|\*|\d+\.\s|\d+\)\s|\u2022)\s*)+/;
|
||||||
@@ -26,7 +26,7 @@ class LineOutputParser extends BaseOutputParser<string> {
|
|||||||
const endKeyIndex = text.indexOf(`</${this.key}>`);
|
const endKeyIndex = text.indexOf(`</${this.key}>`);
|
||||||
|
|
||||||
if (startKeyIndex === -1 || endKeyIndex === -1) {
|
if (startKeyIndex === -1 || endKeyIndex === -1) {
|
||||||
return '';
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const questionsStartIndex =
|
const questionsStartIndex =
|
||||||
|
Reference in New Issue
Block a user