aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
BedrockRuntimeClient ConverseStreamCommand can't receive any response in react native
Checkboxes for prior research
- [X] I've gone through Developer Guide and API reference
- [X] I've checked AWS Forums and StackOverflow.
- [X] I've searched for previous similar issues and didn't find any solution.
Describe the bug
When using BedrockRuntimeClient
in React Native environment, InvokeModelCommand
works well, but ConverseStreamCommand
and InvokeModelWithResponseStreamCommand
will not return any response.
And I've read the getting-started for react native and added following imports
import "react-native-get-random-values";
import "react-native-url-polyfill/auto";
import "web-streams-polyfill/dist/polyfill";
then added blow code in metro.config.js
const config = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: true, // false is still not work.
inlineRequires: false,
},
}),
},
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
the bedrock code as:
const command = new ConverseStreamCommand({
messages: messages,
modelId,
});
const apiResponse = await client.send(command);
console.log(JSON.stringify(apiResponse.stream));
for await (const item of apiResponse.stream) {
console.log(item);
if (item.contentBlockDelta) {
const text = item.contentBlockDelta.delta?.text;
console.log(text);
}
}
client.send(command)
works well, and the log for apiResponse.stream
is:
{"options":{"messageStream":{"options":{"inputStream":{},"decoder":{"headerMarshaller":{},"messageBuffer":[],"isEndOfStream":false}}}}}
The for await
block never goes inside, then I try to remove the transformer in metro.config.js
and the apiResponse.stream
will return the following error:
WARN Invalid responseType: blob
ERROR [TypeError: Cannot read property 'blobId' of undefined]
WARN Invalid responseType: blob
WARN Invalid responseType: blob
WARN Invalid responseType: blob
I don't know what configuration I'm missing or is there any sample code for calling methods of ConverseStreamCommand
or InvokeModelWithResponseStreamCommand
in a React Native environment?
SDK version number
"@aws-sdk/client-bedrock-runtime": "^3.614.0"
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
"react-native": "0.74.5"
Reproduction Steps
see the above describe.
Observed Behavior
ConverseStreamCommand
command send successfully but apiResponse.stream
receive without any streaming response.
Expected Behavior
can receive the streaming response for ConverseStreamCommand
Possible Solution
No response
Additional Information/Context
The credentials are configured correctly and the same code runs perfectly in the node
environment.