Skip to content

zakantonio/flutter-rag-openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG OpenAI Flutter App

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.

🚀 Features

📁 File Management

  • 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

🗄️ Vector Store Management

  • 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

💬 Intelligent Chat Interface

  • 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

🎛️ Advanced Controls

  • 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

🛠️ Technology Stack

  • 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

📋 Prerequisites

Before running this application, you need:

  1. Flutter SDK (3.7.2 or higher)
  2. OpenAI API Key - Get one from OpenAI Platform
  3. Development Environment: Android Studio, VS Code, or similar

🔧 Configuration

Setting up OpenAI API Key

  1. Launch the app
  2. Open the menu drawer (hamburger icon)
  3. Tap on "API Key Settings"
  4. Enter your OpenAI API key
  5. The key is securely stored and will persist across app sessions

Supported File Types

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

📖 How to Use

Step 1: Upload Files

  1. Navigate to the Files tab
  2. Tap the upload button (+ icon)
  3. Select your documents
  4. Wait for upload completion

Step 2: Create Vector Stores

  1. Go to the Vector Stores tab
  2. Tap "Create Vector Store"
  3. Give it a name and select files to include
  4. The vector store will be created and ready for use

Step 3: Start Chatting

  1. Open the Chat tab
  2. Access the menu drawer to:
    • Select your preferred AI model
    • Set a custom system prompt (optional)
    • Choose which vector stores to include
  3. Start asking questions about your uploaded documents!

RAG Workflow Example

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

🏗️ Project Structure

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

🔌 API Integration

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

🎨 UI/UX Features

  • 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

🔒 Security & Privacy

  • 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

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ using Flutter and OpenAI APIs

About

A simple demo of a Flutter application that implements Retrieval-Augmented Generation (RAG) using OpenAI's APIs.

Topics

Resources

Stars

Watchers

Forks

Languages