metadata
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
Clone the repository
git clone <repository-url> cd PatChatInstall dependencies
pip install -r requirements.txtSet up environment variables
cp env.example .env # Edit .env with your OpenAI API key and database URLRun the application
python app.pyOpen your browser
http://localhost:5000
Database Setup
Option 1: SQLite (Development)
# No setup required - SQLite file will be created automatically
Option 2: Supabase (Recommended for Production)
- Create a free account at supabase.com
- Create a new project
- Get your database connection string
- Update your
.envfile:DATABASE_URL=postgresql://postgres:[password]@[host]:5432/postgres
Deployment
Hugging Face Spaces
- Fork this repository
- Create a new Space on Hugging Face
- Set environment variables in Space settings:
OPENAI_API_KEY: Your OpenAI API keyDATABASE_URL: Your database connection stringSECRET_KEY: A secure random string
- Deploy - Hugging Face will automatically build and deploy your app
Docker Deployment
Build the image
docker build -t patchat .Run the container
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 interfaceGET /history- Conversation historyGET /conversation/:id- View specific conversationPOST /send_message- Send message to AIPOST /new_conversation- Start new conversationDELETE /conversation/:id- Delete conversationGET /system_prompts- Get available system promptsGET /health- Health check
Example API Usage
// 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
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
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is open source and available under the MIT License.
Support
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- 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