Skip to content

Mocking CompleteChatStreamingAsync #374

Discussion options

You must be logged in to vote

For the sake of anyone else trying to Mock such a thing, I was able to solve my issue by creating my own class which implements AsyncCollectionResult. Then using my implementation I could essentially create a AsyncCollectionResult object which I could just pass to the setup for Open AI Chat Client.

Implemntation

public class MockAsyncCollectionResult<T>(IEnumerable<T> items) : AsyncCollectionResult<T>
{
    public override async IAsyncEnumerable<ClientResult<T>> GetRawPagesAsync()
    {
        foreach (var item in items)
        {
            var fakePipelineResponse = new Mock<PipelineResponse>().Object;
            yield return ClientResult.FromValue(item, fakePipelineResponse);
        }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ethan-christensen-cag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant