[PR #410] [MERGED] docs(oss): simplify chunk aggregation in messages doc #723

Closed
opened 2026-02-17 17:20:59 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/docs/pull/410
Author: @markgoho
Created: 9/8/2025
Status: Merged
Merged: 9/11/2025
Merged by: @lnhsingh

Base: mainHead: mgoho/fix/simplify-chunk-aggregation


📝 Commits (4)

  • 55c8a84 simplify chunk aggregation
  • b0d14e3 update concat approach
  • 6acb16d fix indentation
  • 946c937 Merge branch 'main' into mgoho/fix/simplify-chunk-aggregation

📊 Changes

1 file changed (+6 additions, -5 deletions)

View changed files

📝 src/oss/langchain/messages.mdx (+6 -5)

📄 Description

slightly opinionated here, but also fixing a broken reduce function

for...of is typically seen as a simpler way to loop over an array, but sticking with concat() since it has some additional behavior

const chunks = [];

const stream = await model.stream('Write a poem');
for await (const chunk of stream) {
  chunks.push(chunk);
}

let finalChunk: AIMessageChunk | undefined;
for (const chunk of chunks) {
  finalChunk = finalChunk ? finalChunk.concat(chunk) : chunk;
}

console.log(`Full response: ${finalChunk?.text}`);

// output
Full response: I am a large language model,
Trained by Google, I can tell.
Stories, poems, code, and more,
All at your command, I'll explore.

What can I create for you today?
Just give me a prompt, and I'll obey.
From a haiku to an epic grand,
I'll do my best to understand.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/docs/pull/410 **Author:** [@markgoho](https://github.com/markgoho) **Created:** 9/8/2025 **Status:** ✅ Merged **Merged:** 9/11/2025 **Merged by:** [@lnhsingh](https://github.com/lnhsingh) **Base:** `main` ← **Head:** `mgoho/fix/simplify-chunk-aggregation` --- ### 📝 Commits (4) - [`55c8a84`](https://github.com/langchain-ai/docs/commit/55c8a84e28e387130b5dd7e67ab250e7b0bfcb5b) simplify chunk aggregation - [`b0d14e3`](https://github.com/langchain-ai/docs/commit/b0d14e3415e0813c95644db03c986bfe03ac7173) update concat approach - [`6acb16d`](https://github.com/langchain-ai/docs/commit/6acb16d256638350a26479e4a50b2e2029c7ab6e) fix indentation - [`946c937`](https://github.com/langchain-ai/docs/commit/946c9370b23640b6f24a17900a2d52f65454fdb7) Merge branch 'main' into mgoho/fix/simplify-chunk-aggregation ### 📊 Changes **1 file changed** (+6 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/oss/langchain/messages.mdx` (+6 -5) </details> ### 📄 Description slightly opinionated here, but also fixing a broken reduce function for...of is typically seen as a simpler way to loop over an array, but sticking with `concat()` since it has some additional behavior ```typescript const chunks = []; const stream = await model.stream('Write a poem'); for await (const chunk of stream) { chunks.push(chunk); } let finalChunk: AIMessageChunk | undefined; for (const chunk of chunks) { finalChunk = finalChunk ? finalChunk.concat(chunk) : chunk; } console.log(`Full response: ${finalChunk?.text}`); // output Full response: I am a large language model, Trained by Google, I can tell. Stories, poems, code, and more, All at your command, I'll explore. What can I create for you today? Just give me a prompt, and I'll obey. From a haiku to an epic grand, I'll do my best to understand. ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-17 17:20:59 -05:00
yindo closed this issue 2026-02-17 17:21:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#723