flutter_rag_chatbot 0.1.2 copy "flutter_rag_chatbot: ^0.1.2" to clipboard
flutter_rag_chatbot: ^0.1.2 copied to clipboard

A Flutter package for building RAG-based chatbots with local vector storage and xAI Grok API integration.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_rag_chatbot/flutter_rag_chatbot.dart';
import 'package:flutter_rag_chatbot/src/widgets/rag_chat_widget.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'RAG Chatbot Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const ChatScreen(),
    );
  }
}

class ChatScreen extends StatefulWidget {
  const ChatScreen({super.key});

  @override
  State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
  RagChatbot? _chatbot;
  bool _isInitializing = true;
  String? _error;

  @override
  void initState() {
    super.initState();
    _initializeChatbot();
  }

  Future<void> _initializeChatbot() async {
    try {
      final chatbot = RagChatbot();
      await chatbot.initialize(
        apiKey: 'your-api-key-here', // Replace with your actual API key
        aiProvider:
            AIProvider.chatgpt, // Choose from: grok, chatgpt, claude, gemini
        knowledgeBase: [
          'This is a string document that will be embedded.',
          'Another text document for the knowledge base.',
        ],
        urls: [
          'https://example.com', // Will fetch and extract text from this URL
        ],
      );

      setState(() {
        _chatbot = chatbot;
        _isInitializing = false;
      });
    } catch (e) {
      setState(() {
        _error = e.toString();
        _isInitializing = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('RAG Chatbot Demo'),
      ),
      body: _isInitializing
          ? const Center(child: CircularProgressIndicator())
          : _error != null
              ? Center(child: Text('Error: $_error'))
              : _chatbot == null
                  ? const Center(child: Text('Chatbot not initialized'))
                  : RagChatWidget(chatbot: _chatbot!),
    );
  }

  @override
  void dispose() {
    _chatbot?.dispose();
    super.dispose();
  }
}
1
likes
140
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for building RAG-based chatbots with local vector storage and xAI Grok API integration.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_markdown, http, sqlite3, vector_math

More

Packages that depend on flutter_rag_chatbot