Skip to content

Bedrock ConverseStreamResponse provides no easy way to read the streamed response without blocking the calling .NET thread #3542

@tlecomte

Description

@tlecomte

Describe the bug

The common way to read from Bedrock ConverseStreamResponse is apparently to call response.Stread.AsEnumerable(). This achieves the goal of streaming the response completions as they are received, but at the cost of keeping the calling .NET thread busy. So it can lead to thread exhaustion.

Ideally we need a new variant that does not block the thread, so maybe an async enumerator exposed as response.Stread.AsAsyncEnumerable().

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I expect to have an easy method that gives an IAsyncEnumerable from ConverseStreamResponse, and which is implemented without blocking the calling thread.

Current Behavior

The current API surface in ConverseStreamResponse encourages the use of response.Stread.AsEnumerable() which blocks the calling thread.

Reproduction Steps

N/A

Possible Solution

This problem was mentioned in #3360 (comment) for a further improvement, with a suggested implementation. I believe the suggested implementation is imperfect, but it can be a basis for a solution.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.BedrockRuntime 3.7.404.8

Targeted .NET Platform

.NET 8

Operating System and version

Docker

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions