agilord/aws_client

[bedrock] Issue when calling the converseStream API call

fvisticot opened this issue · 1 comments

I successfully call the Bedrock runtime converse API call with the following code:

final bedrock = BedrockRuntime(
      endpointUrl: "https://bedrock-runtime.eu-west-3.amazonaws.com",
      region: 'eu-west-3',
      credentials: AwsClientCredentials(
        accessKey: "XXX",
        secretKey: "XXX",
      ));

  final response = await bedrock.converse(
    messages: [
      Message(content: [
        ContentBlock(text: 'What is AWS ?')
      ], role: ConversationRole.user),
    ],
    modelId: "amazon.titan-text-lite-v1",
  );

I have tried to call the similar but STREAMED request (to display the result in a streamed way):
Question: Is it "normal" to get an answer "Future" without Stream object ?. With this how to stream the answer on the UI interface

  final bedrock = BedrockRuntime(
      endpointUrl: "https://bedrock-runtime.eu-west-3.amazonaws.com",
      region: 'eu-west-3',
      credentials: AwsClientCredentials(
        accessKey: "xxxx",
        secretKey: "xxx",
      ));

  final response = await bedrock.converseStream(
    messages: [
      Message(content: [
        ContentBlock(text: 'What is AWS ?')
      ], role: ConversationRole.user),
    ],
    modelId: "amazon.titan-text-lite-v1",
  );

I get the following error:

Unhandled exception: FormatException: Unexpected extension byte (at offset 3) #0 _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1864:7) #1 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:304:28) #2 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:300:5) #3 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:69:18) #4 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24) #5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10) #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11) #7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)