openai_realtime_dart 0.0.2 copy "openai_realtime_dart: ^0.0.2" to clipboard
openai_realtime_dart: ^0.0.2 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?'),
  ]);
}
13
likes
160
pub points
80%
popularity

Publisher

verified publisherlangchaindart.dev

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