Skip to content

Chris12420/chat-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emotion Detection AI - MongoDB Data Storage Edition

This is an emotion detection AI application with local data storage capabilities, integrated with a local large language model.

Features

  • Support for local large models using GGUF format
  • Real-time conversation streaming responses
  • Conversation history saving and management
  • Organize conversations using folders
  • Favorite important conversations
  • Markdown format support
  • Dark/Light theme
  • Model parameter customization (temperature, top_p)
  • Adjustable conversation context size

Application Screenshots

Login Screen

Login Screen

Registration Screen

Registration Screen

Chat Interface

Chat Interface Main View

Chat Interface with Conversation

Model Settings

Model Settings

Tech Stack

  • Frontend: React.js
  • Backend: FastAPI
  • Database: MongoDB
  • Model: GGUF Local Large Language Model

Quick Start

Prerequisites

  • Node.js v16+
  • Python 3.9+
  • MongoDB (installed locally)

Install MongoDB

  1. Download and install MongoDB Community Edition from the MongoDB Official Website.
  2. Start the MongoDB service:
    • Windows: Usually starts automatically as a service.
    • Mac: brew services start mongodb-community
    • Linux: sudo systemctl start mongod

Model Setup

  1. Download a GGUF Model: Obtain a compatible large language model in GGUF format. Here are the options available on Hugging Face:

  2. Place the Model File: Create a directory named model in the root of this project (alongside frontend and backend). Place the downloaded .gguf file inside this model directory.

    /your-project-root
    ├── frontend/
    ├── backend/
    ├── model/                 <-- Create this directory
    │   └── your_model_name.gguf  <-- Place your model file here
    └── README.md
    

    The backend is configured to automatically find and load the first .gguf file it finds within the model directory upon startup.

Backend Setup

  1. Navigate to the backend directory:

    cd backend
  2. Create a virtual environment:

    python3 -m venv venv
  3. Activate the virtual environment:

    • Windows: venv\Scripts\activate
    • macOS/Linux: source venv/bin/activate
  4. Install dependencies:

    pip install -r requirements.txt
  5. Start the backend service:

    python3 app.py

    The backend will run on http://localhost:8000 by default.

Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the frontend development server:

    npm start

    The frontend will open in your browser, usually at http://localhost:3000.

  4. Register an Account: Once the frontend is running, navigate to the registration page (usually by clicking a "Register Now" or similar link on the login page) and create your user account through the UI.

Using the Application

Model Parameters

You can customize the model's behavior by adjusting parameters in the settings menu (⚙️):

  • Temperature (0-1): Controls randomness in the model's responses. Lower values (closer to 0) make responses more deterministic and focused, while higher values (closer to 1) make them more creative and diverse. Default is 0.1.

  • Top P (0-1): Controls diversity via nucleus sampling. A value of 0.1 means only the most likely 10% of potential tokens are considered at each step. Default is 0.1.

  • Context Count (0-20): Controls how many previous messages are included when sending a new question. Setting to 0 means no conversation history is included (stateless mode). Default is 0.

Folder Management

The application supports organizing conversations into folders:

  1. All folders stay expanded by default for easy access
  2. You can create new folders by clicking the "+" button in the folders section
  3. Move conversations between folders using the context menu (•••)

Data Schema

Describes the structure of data stored in MongoDB.

Conversations Collection (conversations)

Stores information about each chat session.

{
  "_id": "ObjectId",               // MongoDB's default primary key
  "conversation_id": "string",    // Unique identifier for the conversation (UUID)
  "user_id": "string",            // Identifier of the user who owns the conversation
  "title": "string",              // Title of the conversation (often auto-generated initially)
  "preview": "string",            // Short preview of the last user message
  "lastUpdated": "datetime",      // Timestamp of the last update to the conversation
  "messages": [
    {
      "id": "number",             // Sequential ID for the message within this conversation
      "role": "string",          // 'user' or 'assistant'
      "content": "string",        // Message content (can be Markdown)
      "timestamp": "datetime",  // Timestamp when the message was added
      "edited": "boolean",       // Optional: Flag indicating if the message was edited
      "isHTML": "boolean"        // Optional: Flag indicating if the content is raw HTML
    }
    // ... more messages
  ],
  "favorite": "boolean",           // Flag indicating if the conversation is marked as favorite
  "folderId": "string"             // ID of the folder this conversation belongs to (e.g., "default_<user_id>", "favorites_<user_id>", or custom folder UUID)
}

Folders Collection (folders)

Stores information about user-created folders for organizing conversations.

{
  "_id": "ObjectId",               // MongoDB's default primary key
  "folder_id": "string",          // Unique identifier for the folder (e.g., "default_<user_id>", "favorites_<user_id>", or custom UUID)
  "user_id": "string",            // Identifier of the user who owns the folder
  "name": "string"                 // Name of the folder (e.g., "Default", "Favorites", "Project X")
}

Users Collection (users)

Stores user account information.

{
  "_id": "ObjectId",               // MongoDB's default primary key
  "user_id": "string",            // Unique identifier for the user (UUID)
  "username": "string",           // Login username (must be unique)
  "display_name": "string",      // Name displayed in the UI
  "password_hash": "string",      // Hashed password (using SHA-256 in this example)
  "created_at": "datetime",      // Timestamp when the user account was created
  "last_login": "datetime"       // Optional: Timestamp of the last successful login
}

API Endpoints

Conversation API

  • GET /api/conversations - Get all conversations
  • GET /api/conversations/{conversation_id} - Get a specific conversation
  • POST /api/conversations - Create a new conversation
  • PUT /api/conversations/{conversation_id} - Update a conversation (e.g., title, favorite, folderId)
  • DELETE /api/conversations/{conversation_id} - Delete a conversation
  • POST /api/conversations/{conversation_id}/messages - Add a message to a conversation (primarily handled by chat endpoints now)

Folder API

  • GET /api/folders - Get all folders
  • POST /api/folders - Create a new folder
  • PUT /api/folders/{folder_id} - Update a folder (e.g., rename)
  • DELETE /api/folders/{folder_id} - Delete a folder

Chat API

  • POST /api/chat - Send a chat message (potentially non-streaming)
  • POST /api/chat/stream - Send a chat message and receive a streamed response, supports temperature and top_p parameters

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors