Skip to content

feat: Add utility functionality to get the entire stream response #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

tomfrenken
Copy link
Member

Context

Part of SAP/ai-sdk-js-backlog#315.

What this PR does and why it is needed

With this PR we concatenate and validate the entire stream response, thus making it available like a regular completion response, once the stream ends.

This way, we can make the same utility functionality available for stream responses as we do already for "normal" completion responses.

Additionally, our validation layer is now always applied at the stream's end.

This functionality can then be used for our upcoming message history feature.

@tomfrenken tomfrenken force-pushed the process-module-results branch from 8e6ce0c to e3fe4c1 Compare July 10, 2025 12:12
@tomfrenken tomfrenken requested review from ZhongpinWang, deekshas8 and KavithaSiva and removed request for ZhongpinWang July 10, 2025 12:53
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already lgtm! I will wait for the unit tests to check the merge functions' logic correctness. Some minor suggestions left.

@tomfrenken tomfrenken changed the title feat: Add utility functonality to get the entire stream response feat: Add utility functionality to get the entire stream response Jul 14, 2025
@tomfrenken tomfrenken requested a review from ZhongpinWang July 18, 2025 08:29
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I am lost with what we want to achieve with this PR. I thought we do stream lock. If _openStream is not meant for stream lock and this will happen in the other PR, I would remove try catch and add it when we implement stream lock and then you can ignore the relevant comments. The stream response level check for _openStream when calling utilities is indeed helpful.

Copy link
Contributor

@KavithaSiva KavithaSiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for unifying the functionality for streaming and non-streaming variants.
Added few comments, review is still ongoing.

@tomfrenken tomfrenken requested a review from ZhongpinWang July 21, 2025 20:59
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Walked through the code again. Mostly lgtm, left some suggestions for improvements.

);
});

it('should handle aborted requests gracefully', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] I don't understand what you mean by gracefully? Don't we throw error? It doesn't feel graceful? I am a bit confused with the purpose of this test. Which part of the code would you like to test with this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the test.

sourceModule: string,
sourceChoice: number | undefined
): void {
if (!message.role) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pp] I don't mind having validations. But some of them are testing if a mandatory field is really there. This feels unnecessary since if we implement everything correctly, user should never see these warnings, at least not without seeing some error first (like stream ended unexpectedly). Other places like choice.index, choice.message are IMO also unnecessary. Can you walk through those cases and remove them if you also feel the same?

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants