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