Skip to content

Commit

Permalink
core[patch]: Make tool call chunk partial JSON parsing more strict (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Aug 26, 2024
1 parent 1a95392 commit a64cf77
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions langchain-core/src/messages/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ export class AIMessageChunk extends BaseMessageChunk {
for (const toolCallChunk of fields.tool_call_chunks) {
let parsedArgs = {};
try {
parsedArgs = parsePartialJson(toolCallChunk.args ?? "{}") ?? {};
if (typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) {
parsedArgs = parsePartialJson(toolCallChunk.args || "{}");
if (
parsedArgs === null ||
typeof parsedArgs !== "object" ||
Array.isArray(parsedArgs)
) {
throw new Error("Malformed tool call chunk args.");
}
toolCalls.push({
Expand Down

0 comments on commit a64cf77

Please sign in to comment.