Mocking InvokeModelWithResponseStreamOutput with eventStream
#3150
Unanswered
mousedownmike
asked this question in
Q&A
Replies: 1 comment
-
I ended up creating an adapter that allowed me to return the mocked EventStream. It's not ideal, but it gets the job done. type bedrockClient interface {
InvokeModelWithResponseStream(ctx context.Context, params *bedrockruntime.InvokeModelWithResponseStreamInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelWithResponseStreamOutput, error)
}
type modelInvoker interface {
InvokeModelWithResponseStream(ctx context.Context, params *bedrockruntime.InvokeModelWithResponseStreamInput, optFns ...func(*bedrockruntime.Options)) (types.InvokeModelWithResponseStreamOutput, error)
}
// The bedrockClientAdapter allows us to mock the EventStream output
type bedrockClientAdapter struct {
client bedrockClient
}
func newBedrockClientAdapter(client bedrockClient) *bedrockClientAdapter {
return &bedrockClientAdapter{client: client}
}
func (a *bedrockClientAdapter) InvokeModelWithResponseStream(ctx context.Context, params *bedrockruntime.InvokeModelWithResponseStreamInput, optFns ...func(*bedrockruntime.Options)) (types.InvokeModelWithResponseStreamOutput, error) {
return a.client.InvokeModelWithResponseStream(ctx, params, optFns...)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create unit tests where I call
InvokeModelWithResposeStream
. To do this I need to have aInvokeModelWithResponseStreamOutput
that contains aInvokeModelWithResponseStreamEventStream
that I can mock. There is a helper that I am able to use to create that EventStream but there is no way to actually return it from the StreamOutput (eventStream
is not exported).The SDK seems to indicate that this should be possible with the following comment, however, I'm unable to construct an output that returns the mocked stream. I'm not sure what I'm missing:
Beta Was this translation helpful? Give feedback.
All reactions