ai_sdk_client 1.0.0 copy "ai_sdk_client: ^1.0.0" to clipboard
ai_sdk_client: ^1.0.0 copied to clipboard

A Dart library for consuming vercel AI SDK compatible data streams

ai_sdk_client

A Dart library for consuming vercel AI SDK data streams

Note

This only supports vercel v4 AI SDK stream protocol compatible streams.

Installation #

dart pub add ai_sdk_client

Setup #

This package is pure dart and does not require any native dependencies.

Usage #

  final dio = Dio();
  final req = await dio.post(
    'http://localhost:8080',
    options: Options(
      responseType: ResponseType.stream,
    ),
  );
  final stream = req.data.stream as Stream<List<int>>;
  final streamConsumer = AiSDKStreamConsumer(stream: stream);
  final chunks = await streamConsumer.consume();

  // Create a subscription to handle the stream
  final subscription = chunks.controller.stream.listen(
    (event) {
      print('Received chunk: $event');
    },
    onError: (error) {
      print('Error in stream: $error');
    },
    onDone: () {
      print('Stream completed');
    },
  );

Chunks #

This package supports all the chunks that are supported by the vercel AI SDK.

You can find the chunks in the lib/chunks directory.

License #

MIT

1
likes
120
points
18
downloads

Publisher

verified publisherprocrastinator.fyi

Weekly Downloads

A Dart library for consuming vercel AI SDK compatible data streams

Documentation

API reference

License

MIT (license)

More

Packages that depend on ai_sdk_client