Skip to content

Commit

Permalink
fix(community,aws): Update handleLLMNewToken to include chunk metadata (
Browse files Browse the repository at this point in the history
#7568)

Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
mohebifar and jacoblee93 authored Jan 22, 2025
1 parent 2961898 commit a2ebf76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
11 changes: 10 additions & 1 deletion libs/langchain-aws/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,16 @@ export class ChatBedrockConverse
chunk.contentBlockDelta
);
yield textChatGeneration;
await runManager?.handleLLMNewToken(textChatGeneration.text);
await runManager?.handleLLMNewToken(
textChatGeneration.text,
undefined,
undefined,
undefined,
undefined,
{
chunk: textChatGeneration,
}
);
} else if (chunk.metadata) {
yield handleConverseStreamMetadata(chunk.metadata, {
streamUsage,
Expand Down
28 changes: 24 additions & 4 deletions libs/langchain-community/src/chat_models/bedrock/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,20 +916,40 @@ export class BedrockChat
}
if (isChatGenerationChunk(chunk)) {
yield chunk;
// eslint-disable-next-line no-void
void runManager?.handleLLMNewToken(
chunk.text,
undefined,
undefined,
undefined,
undefined,
{
chunk,
}
);
} else {
// eslint-disable-next-line no-void
void runManager?.handleLLMNewToken(chunk.text);
}
// eslint-disable-next-line no-void
void runManager?.handleLLMNewToken(chunk.text);
} else {
const text = BedrockLLMInputOutputAdapter.prepareOutput(
provider,
chunkResult
);
yield new ChatGenerationChunk({
const chunk = new ChatGenerationChunk({
text,
message: new AIMessageChunk({ content: text }),
});
yield chunk;
// eslint-disable-next-line no-void
void runManager?.handleLLMNewToken(text);
void runManager?.handleLLMNewToken(
text,
undefined,
undefined,
undefined,
undefined,
{ chunk }
);
}
}
}
Expand Down

0 comments on commit a2ebf76

Please sign in to comment.