openai_realtime_dart 0.0.1+1 copy "openai_realtime_dart: ^0.0.1+1" to clipboard
openai_realtime_dart: ^0.0.1+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
  client.updateSession(instructions: 'You are a great, upbeat friend.');
  client.updateSession(voice: 'alloy');
  client.updateSession(
    turnDetection: {'type': 'none'},
    inputAudioTranscription: {'model': 'whisper-1'},
  );

  // Set up event handling
  client.on('conversation.updated', (event) {
    // item is the current item being updated
    final item = event?['item'];
    // delta can be null or populated
    final delta = event?['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
  client.sendUserMessageContent([
    {'type': 'input_text', 'text': 'How are you?'},
  ]);
}
7
likes
160
pub points
60%
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

http, json_annotation, logging, web_socket_channel

More

Packages that depend on openai_realtime_dart