--- title: PatChat emoji: 💬 colorFrom: blue colorTo: indigo sdk: docker app_file: app.py pinned: false health_check: false --- # PatChat - AI Chat Application PatChat is a simple and intuitive chat application that enables users to have conversations with AI models and save their chat history for future reference. ## Features - 🤖 **AI Chat Interface**: Chat with OpenAI models (GPT-3.5, GPT-4, GPT-4o, GPT-4o-mini, GPT-4o-mini-high, GPT-4o3) - 🎯 **System Prompt Customization**: Choose from predefined prompts or create custom ones - 💾 **Conversation History**: Save and manage all your conversations - 📱 **Responsive Design**: Works on desktop and mobile devices - 🚀 **Easy Deployment**: Deploy on Hugging Face Spaces with Docker - 💰 **Free Database**: Uses free cloud database options - 💡 **Model Information**: See descriptions and costs for each AI model ## System Prompts PatChat comes with several predefined system prompts: - **Default**: General helpful assistant - **Creative**: Imaginative and innovative responses - **Professional**: Business-appropriate responses - **Educational**: Learning-focused explanations - **Coding**: Programming and technical assistance - **Writing**: Writing and editing help - **Custom**: Your own custom prompt ## Quick Start ### Prerequisites - Python 3.11+ - OpenAI API key - Free database (Supabase recommended) ### Local Development 1. **Clone the repository** ```bash git clone cd PatChat ``` 2. **Install dependencies** ```bash pip install -r requirements.txt ``` 3. **Set up environment variables** ```bash cp env.example .env # Edit .env with your OpenAI API key and database URL ``` 4. **Run the application** ```bash python app.py ``` 5. **Open your browser** ``` http://localhost:5000 ``` ### Database Setup #### Option 1: SQLite (Development) ```bash # No setup required - SQLite file will be created automatically ``` #### Option 2: Supabase (Recommended for Production) 1. Create a free account at [supabase.com](https://supabase.com) 2. Create a new project 3. Get your database connection string 4. Update your `.env` file: ``` DATABASE_URL=postgresql://postgres:[password]@[host]:5432/postgres ``` ## Deployment ### Hugging Face Spaces 1. **Fork this repository** 2. **Create a new Space** on Hugging Face 3. **Set environment variables** in Space settings: - `OPENAI_API_KEY`: Your OpenAI API key - `DATABASE_URL`: Your database connection string - `SECRET_KEY`: A secure random string 4. **Deploy** - Hugging Face will automatically build and deploy your app ### Docker Deployment 1. **Build the image** ```bash docker build -t patchat . ``` 2. **Run the container** ```bash docker run -p 5000:5000 \ -e OPENAI_API_KEY=your-key \ -e DATABASE_URL=your-db-url \ -e SECRET_KEY=your-secret \ patchat ``` ## API Endpoints ### Web Routes - `GET /` - Main chat interface - `GET /history` - Conversation history - `GET /conversation/:id` - View specific conversation - `POST /send_message` - Send message to AI - `POST /new_conversation` - Start new conversation - `DELETE /conversation/:id` - Delete conversation - `GET /system_prompts` - Get available system prompts - `GET /health` - Health check ### Example API Usage ```javascript // Send a message const response = await fetch('/send_message', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ conversation_id: 1, content: 'Hello AI!', model_type: 'gpt-4', system_prompt: 'You are a helpful assistant.' }) }); // Create new conversation const newConv = await fetch('/new_conversation', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model_type: 'gpt-3.5-turbo', system_prompt: 'You are a coding assistant.' }) }); ``` ## Project Structure ``` PatChat/ ├── app.py # Main Flask application ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── env.example # Environment variables template ├── templates/ # HTML templates │ ├── base.html # Base template │ ├── chat.html # Chat interface │ └── history.html # Conversation history └── README.md # This file ``` ## Database Schema ### Conversations Table ```sql CREATE TABLE conversations ( id SERIAL PRIMARY KEY, title VARCHAR(255) DEFAULT 'New Conversation', model_type VARCHAR(50) DEFAULT 'gpt-3.5-turbo', system_prompt TEXT DEFAULT 'You are a helpful AI assistant.', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ``` ### Messages Table ```sql CREATE TABLE messages ( id SERIAL PRIMARY KEY, conversation_id INTEGER REFERENCES conversations(id) ON DELETE CASCADE, content TEXT NOT NULL, role VARCHAR(20) NOT NULL, -- 'user' or 'assistant' model_type VARCHAR(50), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ``` ## Configuration ### Environment Variables | Variable | Description | Default | |----------|-------------|---------| | `OPENAI_API_KEY` | Your OpenAI API key | Required | | `DATABASE_URL` | Database connection string | `sqlite:///patchat.db` | | `SECRET_KEY` | Flask secret key | `dev-secret-key` | | `PORT` | Server port | `5000` | ### Supported AI Models | Model | Description | Max Tokens | Cost per 1K tokens | |-------|-------------|------------|-------------------| | `gpt-3.5-turbo` | Fast and cost-effective for most tasks | 4,096 | $0.0015 | | `gpt-4` | More capable but slower than GPT-3.5 | 8,192 | $0.03 | | `gpt-4-turbo` | Latest GPT-4 model with improved performance | 128,000 | $0.01 | | `gpt-4o` | Latest multimodal model with vision capabilities | 128,000 | $0.005 | | `gpt-4o-mini` | Faster and more cost-effective than GPT-4o | 128,000 | $0.00015 | | `gpt-4o-mini-high` | Higher quality responses than GPT-4o Mini | 128,000 | $0.0006 | | `gpt-4o3` | Latest and most capable model (if available) | 128,000 | $0.02 | ## Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests if applicable 5. Submit a pull request ## License This project is open source and available under the [MIT License](LICENSE). ## Support If you encounter any issues or have questions: 1. Check the [Issues](https://github.com/your-repo/issues) page 2. Create a new issue with detailed information 3. Include your environment details and error messages ## Roadmap - [ ] User authentication - [ ] Conversation sharing - [ ] Export conversations - [ ] Voice input/output - [ ] Multiple AI providers - [ ] Advanced prompt templates - [ ] Conversation search - [ ] Mobile app --- **Made with ❤️ for the AI community**