Skip to content

Commit

Permalink
chore(langchain): add throw err for JsonOutputFunctionsParser.parse (#…
Browse files Browse the repository at this point in the history
…7204)

Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
Makoq and jacoblee93 authored Nov 17, 2024
1 parent 986ab14 commit d420b71
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions langchain/src/output_parsers/openai_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
BaseCumulativeTransformOutputParser,
type BaseCumulativeTransformOutputParserInput,
BaseLLMOutputParser,
OutputParserException,
} from "@langchain/core/output_parsers";
import { parsePartialJson } from "@langchain/core/output_parsers";
import { Optional } from "../types/type-utils.js";
Expand Down Expand Up @@ -154,12 +155,18 @@ export class JsonOutputFunctionsParser<
}

async parse(text: string): Promise<Output> {
const parsedResult = JSON.parse(text);
if (this.argsOnly) {
try {
const parsedResult = JSON.parse(text);
if (this.argsOnly) {
return parsedResult;
}
parsedResult.arguments = JSON.parse(parsedResult.arguments);
return parsedResult;
} catch (e) {
throw new OutputParserException(
`Failed to parse. Text: "${text}". Error: ${e}`
);
}
parsedResult.arguments = JSON.parse(parsedResult.arguments);
return parsedResult;
}

getFormatInstructions(): string {
Expand Down

0 comments on commit d420b71

Please sign in to comment.