diff --git a/packages/core/src/OutputParser.ts b/packages/core/src/OutputParser.ts index c067297d5180e62f50c0f341703caeb421b8019e..11bd7f0232175de8ef1e1aeed7f1c3c4700fa342 100644 --- a/packages/core/src/OutputParser.ts +++ b/packages/core/src/OutputParser.ts @@ -64,14 +64,13 @@ function parseJsonMarkdown(text: string) { endDelimiter, beginIndex + beginDelimiter.length, ); - - const jsonText = text.substring(beginIndex + beginDelimiter.length, endIndex); - //Scenario 1: LLM follows instruction format. However, it doesn't always do this. - try { + if (!(beginIndex === -1 || endIndex === -1)) { + const jsonText = text.substring( + beginIndex + beginDelimiter.length, + endIndex, + ); return JSON.parse(jsonText); - } catch (e) { - //Fall through } //Scenario 2: LLM follows instruction format roughly, but doesn't do this exactly. diff --git a/packages/core/src/tests/OutputParser.test.ts b/packages/core/src/tests/OutputParser.test.ts index b088f5bd3da78b0ee0a9d9b301031f2d08494b97..a4c938b555a521fb5c42ed7fdb406107f3f7dd1c 100644 --- a/packages/core/src/tests/OutputParser.test.ts +++ b/packages/core/src/tests/OutputParser.test.ts @@ -1,5 +1,7 @@ import { SubQuestionOutputParser } from "../OutputParser"; +//This parser is really important, so make sure to add tests +// as the parser sees through more iterations. describe("SubQuestionOutputParser", () => { test("parses expected", () => { const parser = new SubQuestionOutputParser();