feat(chat): Add chat conversations and messages module for document analysis
Chat Module - Conversations & Messages
Overview
This MR implements the Chat module for document analysis, enabling users to have conversations with their indexed documents using RAG technology.
What's New
Database Models
| Table | Description |
|---|---|
conversations |
User chat sessions with title and archive status |
messages |
Individual messages with sender (user/agent), type, and RAG metadata |
API Endpoints
POST /chat/conversations Create new conversation
GET /chat/conversations List user's conversations
GET /chat/conversations/{id} Get conversation details
PATCH /chat/conversations/{id} Update title
DELETE /chat/conversations/{id} Delete with cascade
POST /chat/conversations/{id}/messages Send message, get AI response
GET /chat/conversations/{id}/messages Get conversation history
Architecture
Frontend -> FastAPI -> n8n (chatbot-rag) -> Qdrant + LiteLLM -> Response
Files Changed
New (7 files):
Integration/models/conversation.pyIntegration/models/message.pyIntegration/schemas/chat.pyIntegration/services/conversation_service.pyIntegration/services/message_service.pyIntegration/chat_api.pyIntegration/scripts/create_chat_tables.py
Modified (5 files):
Integration/models/enums.pyIntegration/models/__init__.pyIntegration/services/__init__.pyAgent/api_app.pyAgent/Readme.md
Configuration Required
Add to Agent/.env:
N8N_WEBHOOK_BASE_URL=https://ai.izemx.com # or ngrok URL for dev
N8N_CHATBOT_TIMEOUT=60.0 # optional, defaults to 60s
Database Setup
Run the table creation script before first use:
python Integration/scripts/create_chat_tables.py
Dependencies
- httpx (for async HTTP calls)
- Existing: FastAPI, SQLAlchemy, Pydantic
Checklist
-
Models created (Conversation, Message) -
Schemas created (Pydantic) -
Services implemented -
API endpoints created -
Router integrated in api_app.py -
README updated with Chat API section -
Database table creation script -
All tests passing (11/11) -
n8n workflow imported (manual step)