Skip to content

MuhammadShahzeb123/ai-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Enhanced DeepSeek Chat Application

A powerful, user-friendly AI chat application built with Node.js and DeepSeek API, featuring custom AI personalities, conversation management, and a beautiful modern interface.

✨ Features

🎭 AI Personalities

  • 6 Pre-built Personalities: Helpful Assistant, Creative Writer, Code Mentor, Business Advisor, Learning Coach, and Philosopher
  • Custom Personalities: Create your own AI personalities with custom system prompts
  • Easy Switching: Switch between personalities seamlessly during conversations

πŸ’¬ Advanced Chat Features

  • Real-time Streaming: Get responses as they're generated (optional)
  • Conversation History: All chats are automatically saved and organized
  • Session Management: Resume conversations from where you left off
  • Message Export: Export conversations to text files
  • Character Counter: Track message length with visual feedback

🎨 Modern User Interface

  • Responsive Design: Works perfectly on desktop, tablet, and mobile
  • Dark/Light Mode: Toggle between themes for comfortable viewing
  • Intuitive Sidebar: Easy navigation between conversations and personalities
  • Professional Styling: Clean, modern design with smooth animations
  • Accessibility: Full keyboard navigation and screen reader support

βš™οΈ Customization Options

  • Temperature Control: Adjust AI creativity/randomness (0.0 - 1.0)
  • Response Length: Configure maximum response length
  • Auto-scroll: Automatically scroll to new messages
  • Streaming Toggle: Enable/disable real-time response streaming

πŸ”§ Technical Features

  • Persistent Storage: Conversations saved to JSON files with auto-backup
  • Error Handling: Comprehensive error handling with user-friendly messages
  • Rate Limiting Ready: Built-in support for rate limiting (configurable)
  • Environment Configuration: Easy setup with environment variables
  • Modular Architecture: Clean, maintainable code structure

πŸš€ Quick Start

Prerequisites

  • Node.js (v14 or higher)
  • NPM or Yarn
  • DeepSeek API key

Installation

  1. Clone or download the project

    cd your-project-directory
  2. Install dependencies

    npm install
  3. Configure environment

    cp .env.example .env

    Edit .env file and add your DeepSeek API key:

    DEEPSEEK_API_KEY=your_api_key_here
    PORT=3000
  4. Start the application

    # Development mode (with auto-restart)
    npm run dev
    
    # Production mode
    npm start
  5. Open your browser Navigate to http://localhost:3000

πŸ“ Project Structure

changli/
β”œβ”€β”€ app.js                 # Main application server
β”œβ”€β”€ package.json           # Dependencies and scripts
β”œβ”€β”€ .env.example          # Environment configuration template
β”œβ”€β”€ routes/
β”‚   └── chat.js           # Enhanced chat API routes
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── database.js   # Conversation storage manager
β”‚   └── services/
β”‚       β”œβ”€β”€ chatService.js      # AI chat service
β”‚       └── systemPrompts.js    # AI personalities manager
β”œβ”€β”€ public/               # Frontend files
β”‚   β”œβ”€β”€ index.html       # Main HTML interface
β”‚   β”œβ”€β”€ styles.css       # Modern CSS styling
β”‚   └── app.js          # Frontend JavaScript application
└── data/                # Auto-created for conversation storage
    └── conversations.json

🎯 API Endpoints

Chat Operations

  • POST /api/chat/message - Send a message to AI
  • POST /api/chat/stream - Send a streaming message (real-time)
  • POST /api/chat/conversation/new - Start a new conversation

Conversation Management

  • GET /api/chat/conversations - Get all conversations
  • GET /api/chat/conversation/:sessionId - Get specific conversation
  • PUT /api/chat/conversation/:sessionId/title - Update conversation title
  • DELETE /api/chat/conversation/:sessionId - Delete conversation

AI Personalities

  • GET /api/chat/prompts - Get available AI personalities
  • POST /api/chat/prompts/custom - Create custom personality

System

  • GET /api/health - Health check endpoint

🎭 Using AI Personalities

Pre-built Personalities

  1. πŸ€– Helpful Assistant - General-purpose helpful AI
  2. ✍️ Creative Writer - Stories, poems, creative content
  3. πŸ’» Code Mentor - Programming help and code reviews
  4. πŸ“Š Business Advisor - Business strategy and analysis
  5. πŸŽ“ Learning Coach - Educational support and tutoring
  6. πŸ€” Philosopher - Deep discussions about life and ethics

Creating Custom Personalities

  1. Click the "Create Custom" button in the personalities section
  2. Fill in the personality details:
    • ID: Unique identifier (e.g., "my-custom-ai")
    • Name: Display name (e.g., "My Custom AI")
    • Description: Brief description of the personality
    • Icon: Emoji to represent the personality
    • System Prompt: Detailed instructions for the AI's behavior

Example custom prompt:

You are a fitness and nutrition expert with 10+ years of experience. You provide evidence-based advice on exercise routines, meal planning, and healthy lifestyle choices. You're motivational, encouraging, and always prioritize safety in your recommendations.

πŸ”§ Configuration Options

Environment Variables

# Required
DEEPSEEK_API_KEY=your_deepseek_api_key_here

# Optional
PORT=3000                    # Server port (default: 3000)
NODE_ENV=development         # Environment mode
CORS_ORIGIN=*               # CORS allowed origins

Settings Panel

Access the settings panel by clicking the "Settings" button in the sidebar:

  • Response Creativity (0.0-1.0): Controls randomness in AI responses
  • Max Response Length (100-4000): Maximum tokens in AI responses
  • Dark Mode: Toggle between light and dark themes
  • Auto-scroll: Automatically scroll to new messages
  • Real-time Streaming: Enable/disable streaming responses

πŸ’‘ Usage Tips

  1. Starting Conversations: Select an AI personality first, then start chatting
  2. Switching Personalities: Click on a different personality to start a new conversation with that AI
  3. Managing Conversations: Use the sidebar to switch between past conversations
  4. Exporting Chats: Click the export button to save conversations as text files
  5. Keyboard Shortcuts:
    • Enter to send message
    • Shift + Enter for new line in message
    • Ctrl/Cmd + / to focus message input

πŸ› οΈ Development

Adding New Features

  1. Backend: Add new routes in routes/chat.js or create new route files
  2. Frontend: Extend the ChatApp class in public/app.js
  3. Styling: Add styles to public/styles.css using CSS variables for theming

Testing

# Run tests (when implemented)
npm test

# Lint code (when configured)
npm run lint

Building for Production

# Install production dependencies only
npm ci --only=production

# Start with PM2 (recommended)
pm2 start app.js --name "deepseek-chat"

πŸ“± Mobile Support

The application is fully responsive and works great on:

  • πŸ“± Mobile phones (iOS/Android)
  • πŸ“± Tablets (iPad, Android tablets)
  • πŸ’» Desktop computers
  • πŸ–₯️ Large screens

πŸ”’ Security Notes

  • API keys are stored securely in environment variables
  • All user inputs are properly sanitized
  • CORS is configured for security
  • Rate limiting can be easily implemented
  • No sensitive data is stored in frontend JavaScript

πŸš€ Deployment

Quick Deploy Options

  1. Local Server: npm start
  2. Heroku: Ready for Heroku deployment
  3. Vercel: Frontend-ready for Vercel
  4. Railway: Easy Railway deployment
  5. DigitalOcean: App Platform ready

Environment Setup for Deployment

NODE_ENV=production
DEEPSEEK_API_KEY=your_production_api_key
PORT=8080
CORS_ORIGIN=https://yourdomain.com

🀝 Contributing

This is a complete, production-ready application. To extend it:

  1. Fork the repository
  2. Create a feature branch
  3. Add your enhancements
  4. Test thoroughly
  5. Submit a pull request

πŸ“§ Support

If you need help:

  1. Check the troubleshooting section below
  2. Review the API documentation
  3. Check browser console for errors
  4. Ensure your DeepSeek API key is valid and has credits

πŸ› Troubleshooting

Common Issues

"Failed to process chat message"

  • Check your DeepSeek API key in .env
  • Ensure you have API credits remaining
  • Check internet connection

"Conversation not found"

  • The conversation may have been deleted
  • Check if data/conversations.json exists and is readable

UI not loading

  • Clear browser cache
  • Check browser console for JavaScript errors
  • Ensure all files are properly served

Streaming not working

  • Disable ad blockers that might block server-sent events
  • Check if your browser supports EventSource
  • Try switching to regular (non-streaming) mode

Debug Mode

Set NODE_ENV=development in your .env file for detailed error messages.

πŸ“ˆ Performance

  • Lightweight: Minimal dependencies, fast loading
  • Efficient: Smart conversation context management
  • Scalable: Ready for multiple concurrent users
  • Optimized: Lazy loading and efficient rendering

πŸŽ‰ Conclusion

You now have a powerful, professional-grade AI chat application that rivals commercial solutions! The app includes:

βœ… Advanced AI conversation management βœ… Multiple AI personalities βœ… Beautiful, responsive interface βœ… Real-time streaming responses βœ… Persistent conversation history βœ… Custom personality creation βœ… Export functionality βœ… Dark/light mode βœ… Mobile-friendly design βœ… Production-ready architecture

Enjoy chatting with your enhanced AI assistant! πŸš€

About

A simple But powerful app that uses OpenAI api to create custom chat messages (No restrictions)

Topics

Resources

Stars

Watchers

Forks

Contributors