flutter_ai_provider_openai 0.1.4 copy "flutter_ai_provider_openai: ^0.1.4" to clipboard
flutter_ai_provider_openai: ^0.1.4 copied to clipboard

OpenAI-compatible LlmProvider for flutter_ai: streams Chat Completions (text, tool calls, finish reasons) as flutter_ai_core AiStreamEvents over an injectable HTTP client.

example/flutter_ai_provider_openai_example.dart

// Streams a single completion from OpenAI and prints the assembled reply.
//
// Run with:
//   dart run --define=OPENAI_API_KEY=sk-... example/flutter_ai_provider_openai_example.dart
import 'package:flutter_ai_provider_openai/flutter_ai_provider_openai.dart';

Future<void> main() async {
  const apiKey = String.fromEnvironment('OPENAI_API_KEY');
  if (apiKey.isEmpty) {
    print('Set OPENAI_API_KEY via --define to run against the live API.');
    return;
  }

  final provider = OpenAiProvider(apiKey: apiKey);
  final processor = MessageProcessor();

  const conversation = AiConversation(
    id: 'demo',
    messages: [
      AiMessage(
        id: 'u1',
        role: AiRole.user,
        parts: [TextPart('Say hello in one short sentence.')],
      ),
    ],
  );

  await for (final event in provider.send(conversation)) {
    processor.apply(event);
  }
  print(processor.conversation.lastMessage?.text);
  provider.close();
}
0
likes
0
points
529
downloads

Publisher

unverified uploader

Weekly Downloads

OpenAI-compatible LlmProvider for flutter_ai: streams Chat Completions (text, tool calls, finish reasons) as flutter_ai_core AiStreamEvents over an injectable HTTP client.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #llm #openai #chat #streaming

License

unknown (license)

Dependencies

flutter_ai_core, http

More

Packages that depend on flutter_ai_provider_openai