Skip to main content

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

Structured JSON output from Gemini, OpenAI and Claude with one schema. Images, actionable errors, no vendor SDKs. Unofficial.

example/main.dart

// Run: GEMINI_API_KEY=... dart run example/main.dart
// (or OPENAI_API_KEY / ANTHROPIC_API_KEY). With no key it uses DemoProvider.
import 'dart:io';

import 'package:gemini_openai_claude/gemini_openai_claude.dart';

Future<void> main() async {
  final env = Platform.environment;
  final (AiAdapter ai, String key) = switch (env) {
    {'GEMINI_API_KEY': final k} => (GeminiProvider(), k),
    {'OPENAI_API_KEY': final k} => (OpenAiProvider(), k),
    {'ANTHROPIC_API_KEY': final k} => (ClaudeProvider(), k),
    _ => (const DemoProvider(), ''),
  };

  final spec = PromptSpec(
    instruction: 'Suggest a short title and three tags for this note: "Fix the bike brakes before Sunday."',
    schema: const {
      'type': 'object',
      'properties': {
        'title': {'type': 'string'},
        'tags': {
          'type': 'array',
          'items': {'type': 'string'},
        },
      },
      'required': ['title', 'tags'],
    },
    demo: () => {
      'title': 'Bike brakes',
      'tags': ['bike', 'repair', 'weekend'],
    },
  );

  try {
    final json = await ai.complete(spec: spec, apiKey: key);
    stdout.writeln('${ai.label()}: $json');
  } on ProviderException catch (e) {
    stderr.writeln('${e.kind.name}: ${e.message}');
    if (e.detail != null) stderr.writeln(e.detail);
    exitCode = 1;
  } finally {
    ai.dispose();
  }
}
1
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publishercoderqh.com

Weekly Downloads

Structured JSON output from Gemini, OpenAI and Claude with one schema. Images, actionable errors, no vendor SDKs. Unofficial.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #llm #gemini #openai #claude

License

MIT (license)

Dependencies

http

More

Packages that depend on gemini_openai_claude