openai_realtime_dart 0.0.3+1 copy "openai_realtime_dart: ^0.0.3+1" to clipboard
openai_realtime_dart: ^0.0.3+1 copied to clipboard

Dart client for the OpenAI Realtime API (beta), a stateful, event-based API that communicates over a WebSocket.

example/openai_realtime_dart_example.dart

// ignore_for_file: cascade_invocations, unused_local_variable
import 'dart:io';

import 'package:openai_realtime_dart/openai_realtime_dart.dart';

Future<void> main() async {
  final client = RealtimeClient(
    apiKey: Platform.environment['OPENAI_API_KEY'],
  );

  // Can set parameters ahead of connecting, either separately or all at once
  await client.updateSession(instructions: 'You are a great, upbeat friend.');
  await client.updateSession(voice: Voice.alloy);
  await client.updateSession(
    turnDetection: null,
    inputAudioTranscription:
        const InputAudioTranscriptionConfig(model: 'whisper-1'),
  );

  // Set up event handling
  client.on(RealtimeEventType.conversationUpdated, (e) {
    final event = e as RealtimeEventConversationUpdated;
    // item is the current item being updated
    final item = event.result.item;
    // delta can be null or populated
    final delta = event.result.delta;
    // you can fetch a full list of items at any time
  });

  // Connect to Realtime API
  await client.connect();

  // Send a item and triggers a generation
  await client.sendUserMessageContent(const [
    ContentPart.text(text: 'How are you?'),
  ]);
}
15
likes
160
points
647
downloads

Publisher

verified publisherlangchaindart.dev

Weekly Downloads

Dart client for the OpenAI Realtime API (beta), a stateful, event-based API that communicates over a WebSocket.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#ai #llms #openai

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

freezed_annotation, http, json_annotation, logging, web_socket_channel

More

Packages that depend on openai_realtime_dart