CoolFace
Apppublic

makaronz/PatChat

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

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. 1.Clone the repository
bash
   git clone <repository-url>
   cd PatChat
  1. 1.Install dependencies
bash
   pip install -r requirements.txt
  1. 1.Set up environment variables
bash
   cp env.example .env
   # Edit .env with your OpenAI API key and database URL
  1. 1.Run the application
bash
   python app.py
  1. 1.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. 1.Create a free account at supabase.com
  2. 2.Create a new project
  3. 3.Get your database connection string
  4. 4.Update your .env file:
   DATABASE_URL=postgresql://postgres:[password]@[host]:5432/postgres

Deployment

Hugging Face Spaces

  1. 1.Fork this repository
  2. 2.Create a new Space on Hugging Face
  3. 3.Set environment variables in Space settings:
  4. 4.OPENAI_API_KEY: Your OpenAI API key
  5. 5.DATABASE_URL: Your database connection string
  6. 6.SECRET_KEY: A secure random string
  7. 7.Deploy - Hugging Face will automatically build and deploy your app

Docker Deployment

  1. 1.Build the image
bash
   docker build -t patchat .
  1. 1.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

VariableDescriptionDefault
OPENAI_API_KEYYour OpenAI API keyRequired
DATABASE_URLDatabase connection stringsqlite:///patchat.db
SECRET_KEYFlask secret keydev-secret-key
PORTServer port5000

Supported AI Models

ModelDescriptionMax TokensCost per 1K tokens
gpt-3.5-turboFast and cost-effective for most tasks4,096$0.0015
gpt-4More capable but slower than GPT-3.58,192$0.03
gpt-4-turboLatest GPT-4 model with improved performance128,000$0.01
gpt-4oLatest multimodal model with vision capabilities128,000$0.005
gpt-4o-miniFaster and more cost-effective than GPT-4o128,000$0.00015
gpt-4o-mini-highHigher quality responses than GPT-4o Mini128,000$0.0006
gpt-4o3Latest and most capable model (if available)128,000$0.02

Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.Add tests if applicable
  5. 5.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:

  1. 1.Check the Issues page
  2. 2.Create a new issue with detailed information
  3. 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