# NovaChat: Advanced AI Assistant with Multiple Features

NovaChat is a versatile AI assistant with multiple capabilities, including different conversation personas, web search integration, torrent functionality, and local LLM integration.

## Project Overview

### 1. AI Chat with Multiple Personas
The system can switch between different conversation modes:
   
- **COGITO**: Standard helpful assistant mode
- **FLIRTY**: A flirtatious persona
- **COMPANION**: An empathetic, supportive friend
- **INVESTIGATE**: An analytical persona focused on Indian politics and current affairs

### 2. Web Search Integration
Fetches real-time information from:
   
- Google Search
- DuckDuckGo
- News sources
- arXiv (for academic papers)

### 3. Torrent Functionality
Allows searching, downloading, and streaming of torrents via magnet links

### 4. Local LLM Integration
Uses Ollama to run local AI models including:
   
- Cogito models
- Various specialized models

### 5. Model Management
- Real-time listing of available Ollama models
- Display model sizes and last modified dates
- Pull new models directly from Ollama registry
- Error handling for model operations

## Project Structure

```
agent_prod/
├── app.py                      # Main application entry point
├── requirements.txt            # Dependencies
├── README.md                   # Project documentation
├── static/                     # Static assets
│   ├── css/                    # CSS files
│   │   └── style.css           # Main stylesheet
│   └── js/                     # JavaScript files
│       └── chat.js             # Chat functionality
├── templates/                  # HTML templates
│   ├── index.html              # Main chat interface
│   ├── player.html             # Media player for torrents
│   └── components/             # Reusable UI components
├── modules/
│   ├── chat/                   # AI chat functionality
│   │   ├── __init__.py
│   │   ├── personas.py         # Different chat personas
│   │   └── chat_handler.py     # Chat processing logic
│   ├── torrent/                # Torrent functionality
│   │   ├── __init__.py
│   │   └── torrent_handler.py  # Torrent handling logic
│   ├── search/                 # Search functionality
│   │   ├── __init__.py
│   │   ├── news.py             # News search
│   │   ├── arxiv.py            # arXiv search
│   │   └── web.py              # Web search
│   └── llm/                    # LLM integration
│       ├── __init__.py
│       └── ollama_client.py    # Ollama integration

```

## UI Screenshots

![Chat Interface](./static/assets/screenshots/chat-ui.png)
*Main chat interface with persona selection*

![Torrent Player](./static/assets/screenshots/torrent-player.png)
*Media player with progress controls*

![Model Selection](./static/assets/screenshots/model-selection.png)
*Ollama model management interface*

## Future Improvements

1. **User Authentication**
   - JWT-based auth system
   - Role-based access control

2. **Rate Limiting**
   - API request throttling
   - Torrent download quotas

3. **Enhanced Security**
   - Content moderation system
   - SSL/TLS encryption

4. **Plugin System**
   - Extensible architecture for new personas
   - Third-party integration support

## Features

### Chat System
- Flask-based web interface
- Server-side session management
- Multiple conversation personas with different system prompts
- Integration with Ollama for local LLM inference

### Search System
- DuckDuckGo search integration with title/URL results
- Google search API implementation
- Error handling for search providers
- Results formatting for chat integration

### Torrent Functionality
- libtorrent-based download management
- Real-time progress tracking
- Streaming capability for completed files
- File listing for partial downloads
- Status monitoring (progress, peers, speed)

### Torrent Functionality
- Uses libtorrent for handling magnet links
- Provides real-time download status
- Supports streaming of downloaded content

### Web Interface
- Bootstrap 5 responsive layout
- Component-based template architecture
- Real-time chat interface with message history
- Media player with torrent progress monitoring
- Persona selection dropdown menu

- Interactive progress bars and status indicators

## Setup and Installation

### Prerequisites
- Python 3.10
- Ollama service running locally ([installation guide](https://ollama.ai/download))
- libtorrent-rasterbar 2.0+

### Virtual Environment Setup
```bash
# Create virtual environment
python -m venv venv

# Activate environment (Windows)
venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
```

### Installation
1. Clone the repository
2. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```
3. Configure environment:
   ```bash
   cp config.yaml.example config.yaml
   ```
4. Start the application:
   ```bash
   python app.py
   ```

### Configuration
Edit `config.yaml` to customize:
- API keys for search providers
- Torrent download locations
- LLM model preferences
- Session timeout settings

Access the web interface at http://localhost:9125

## Dependencies

- Flask==2.0.1
- Flask-Session==0.4.0
- Requests==2.26.0
- python-libtorrent==1.2.3
- duckduckgo-search==2.8.5
- googlesearch-python==1.0.1
- Ollama==0.1.2
- python-dotenv==0.19.0
- uvicorn==0.15.0

Note: Ensure libtorrent-rasterbar 2.0+ is installed system-wide