makaronz/PatChat
0
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 PatChat- Install dependencies
pip install -r requirements.txt- Set up environment variables
cp env.example .env
# Edit .env with your OpenAI API key and database URL- Run the application
python app.py- Open your browser
http://localhost:5000Database Setup
Option 1: SQLite (Development)
# No setup required - SQLite file will be created automaticallyOption 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/postgresDeployment
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 \
patchatAPI 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 fileDatabase 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
Supported AI Models
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
