A simple demo of a Flutter application that implements Retrieval-Augmented Generation (RAG) using OpenAI's APIs. This app allows users to upload documents, create vector stores, and have intelligent conversations with AI models that can reference uploaded content.
- File Upload: Upload various document types (PDF, TXT, DOCX, etc.) to OpenAI
- File Browser: View and manage all uploaded files
- File Deletion: Remove files when no longer needed
- Supported Formats: PDF, TXT, DOCX, PPTX, MD, JSON, CSV, and more
- Create Vector Stores: Organize files into searchable knowledge bases
- Multi-File Support: Add multiple files to a single vector store
- File Association: Dynamically add/remove files from vector stores
- Vector Store Details: View file counts, usage statistics, and status
- RAG Conversations: Chat with AI models that can reference your uploaded documents
- Multi-Vector Store Support: Select multiple vector stores for comprehensive knowledge access
- Model Selection: Choose from various OpenAI models (GPT-4, GPT-3.5-turbo, etc.)
- System Prompts: Customize AI behavior with custom system prompts
- Chat History: Persistent conversation history with auto-generated titles
- Markdown Support: Rich text formatting for better readability
- Menu Drawer: Organized interface for model selection, system prompts, and vector store management
- Persistent Settings: Vector store selections and preferences saved across sessions
- API Key Management: Secure storage of OpenAI API keys
- Cross-Platform: Works on iOS, Android, and Web
- Framework: Flutter 3.7.2+
- State Management: Provider
- Database: SQLite (sqflite)
- Secure Storage: flutter_secure_storage
- HTTP Client: http package
- File Handling: file_picker
- Markdown Rendering: flutter_markdown
- Local Storage: shared_preferences
Before running this application, you need:
- Flutter SDK (3.7.2 or higher)
- OpenAI API Key - Get one from OpenAI Platform
- Development Environment: Android Studio, VS Code, or similar
- Launch the app
- Open the menu drawer (hamburger icon)
- Tap on "API Key Settings"
- Enter your OpenAI API key
- The key is securely stored and will persist across app sessions
The app supports the following file formats for upload:
- Documents: PDF, TXT, DOCX, PPTX
- Data: JSON, CSV, TSV
- Code: MD, HTML, XML
- And more: Check the upload interface for the complete list
- Navigate to the Files tab
- Tap the upload button (+ icon)
- Select your documents
- Wait for upload completion
- Go to the Vector Stores tab
- Tap "Create Vector Store"
- Give it a name and select files to include
- The vector store will be created and ready for use
- Open the Chat tab
- Access the menu drawer to:
- Select your preferred AI model
- Set a custom system prompt (optional)
- Choose which vector stores to include
- Start asking questions about your uploaded documents!
1. Upload: "company_policy.pdf" → Files tab
2. Create: "HR Policies" vector store → Vector Stores tab
3. Select: Choose "HR Policies" in chat drawer → Chat tab
4. Ask: "What is the vacation policy?" → Get AI response with document references
lib/
├── main.dart # App entry point
├── screens/ # UI screens
│ ├── chat_screen.dart # Main chat interface
│ ├── files_screen.dart # File management
│ ├── vector_stores_screen.dart # Vector store management
│ └── chat_history_screen.dart # Chat history
├── services/ # Business logic
│ ├── api/ # API integrations
│ │ ├── chat_api.dart # Chat functionality
│ │ ├── files_api.dart # File operations
│ │ ├── vector_stores_api.dart # Vector store operations
│ │ └── responses_api.dart # OpenAI Responses API
│ ├── database/ # Local database
│ ├── models/ # Data models
│ └── openai_service.dart # Core OpenAI service
├── widgets/ # Reusable UI components
│ ├── chat/ # Chat-related widgets
│ ├── files/ # File-related widgets
│ └── vector_stores/ # Vector store widgets
└── utils/ # Utilities and constants
This app integrates with several OpenAI APIs:
- Files API: Upload and manage documents
- Vector Stores API: Create and manage knowledge bases
- Chat Completions API: Standard chat functionality
- Responses API: Advanced RAG with file search capabilities
- Material Design 3: Modern, clean interface
- Responsive Layout: Works on phones, tablets, and web
- Dark/Light Theme: Follows system preferences
- Loading States: Clear feedback during operations
- Error Handling: User-friendly error messages
- Accessibility: Screen reader support and proper contrast
- Secure API Key Storage: OpenAI keys encrypted using flutter_secure_storage
- Firebase Configuration: Sensitive Firebase keys excluded from version control
- Local Data: Chat history stored locally on device
- No Data Collection: App doesn't collect or transmit personal data
- OpenAI Privacy: Subject to OpenAI's privacy policy for uploaded files
- Git Security: All sensitive files are in .gitignore to prevent accidental commits
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ using Flutter and OpenAI APIs