Skip to content

Commit

Permalink
anthropic[patch]: Handle non text llm tokens (langchain-ai#6179)
Browse files Browse the repository at this point in the history
* anthropic[patch]: Handle non text llm tokens

* check for input field
  • Loading branch information
bracesproul authored Jul 23, 2024
1 parent 87d92d9 commit e576ade
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libs/langchain-anthropic/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,14 @@ function extractToolCallChunk(
}

function extractToken(chunk: AIMessageChunk): string | undefined {
return typeof chunk.content === "string" && chunk.content !== ""
? chunk.content
: undefined;
if (typeof chunk.content === "string") {
return chunk.content;
} else if (Array.isArray(chunk.content) && "input" in chunk.content[0]) {
return typeof chunk.content[0].input === "string"
? chunk.content[0].input
: JSON.stringify(chunk.content[0].input);
}
return undefined;
}

function extractToolUseContent(
Expand Down

0 comments on commit e576ade

Please sign in to comment.