universal_chatbot 0.0.2 copy "universal_chatbot: ^0.0.2" to clipboard
universal_chatbot: ^0.0.2 copied to clipboard

The Universal LLM Chatbot package is a comprehensive solution that enables developers to integrate various AI services seamlessly into Flutter applications. With this package, you can harness the powe [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:universal_chatbot/universal_chatbot.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Universal Chatbot Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Universal Chatbot Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String text = '...';
  Future<void> _requestLLM() async {
    const modelConfig = ServiceConfig(enableLog: true);
    final LLM model =
        Claude(key: dotenv.env['CLAUDE_KEY']!, serviceConfig: modelConfig);
    final promptConfig = DefaultClaudeConfig();
    final response = (await model.generateText(
            LLMMessage(message: 'Tell a story'), promptConfig))
        .toList();
    setState(() {
      text = response.join('\n');
    });
  }

  @override
  void initState() {
    dotenv.load(fileName: "../.env");
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              text,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _requestLLM,
        tooltip: 'Requests',
        child: const Icon(Icons.send),
      ),
    );
  }
}
2
likes
120
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

The Universal LLM Chatbot package is a comprehensive solution that enables developers to integrate various AI services seamlessly into Flutter applications. With this package, you can harness the power of cutting-edge language models and image generation capabilities from renowned AI providers such as OpenAI, Anthropic, Gemini, and more, all within a single, unified interface

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

anthropic_sdk_dart, chat_gpt_sdk, collection, flutter, flutter_gemini

More

Packages that depend on universal_chatbot