Spaces:
Sleeping
Sleeping
Commit
·
67b7db4
1
Parent(s):
d9d3bba
update the start.bat files
Browse files- FILE_STRUCTURE.md +87 -0
- requirements.txt +1 -1
- start.bat +67 -31
FILE_STRUCTURE.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IntegraChat - Current File Structure
|
| 2 |
+
|
| 3 |
+
```
|
| 4 |
+
IntegraChat/
|
| 5 |
+
├── backend/
|
| 6 |
+
│ ├── api/
|
| 7 |
+
│ │ ├── main.py # FastAPI main application
|
| 8 |
+
│ │ ├── mcp_clients/
|
| 9 |
+
│ │ │ ├── admin_client.py # Admin MCP client
|
| 10 |
+
│ │ │ ├── mcp_client.py # Main MCP client wrapper
|
| 11 |
+
│ │ │ ├── rag_client.py # RAG MCP client
|
| 12 |
+
│ │ │ └── web_client.py # Web search MCP client
|
| 13 |
+
│ │ ├── models/
|
| 14 |
+
│ │ │ ├── __init__.py
|
| 15 |
+
│ │ │ ├── agent.py # Agent request/response models
|
| 16 |
+
│ │ │ └── redflag.py # Red flag rule models
|
| 17 |
+
│ │ ├── routes/
|
| 18 |
+
│ │ │ ├── admin.py # Admin routes
|
| 19 |
+
│ │ │ ├── agent.py # Agent chat routes
|
| 20 |
+
│ │ │ ├── analytics.py # Analytics routes
|
| 21 |
+
│ │ │ ├── rag.py # RAG routes
|
| 22 |
+
│ │ │ └── web.py # Web search routes
|
| 23 |
+
│ │ ├── services/
|
| 24 |
+
│ │ │ ├── agent_orchestrator.py # Main orchestrator (multi-tool execution)
|
| 25 |
+
│ │ │ ├── intent_classifier.py # Intent classification service
|
| 26 |
+
│ │ │ ├── llm_client.py # LLM client (Ollama/Groq)
|
| 27 |
+
│ │ │ ├── prompt_builder.py # Prompt building utilities
|
| 28 |
+
│ │ │ ├── redflag_detector.py # Red flag detection service
|
| 29 |
+
│ │ │ └── tool_selector.py # Multi-tool selection logic
|
| 30 |
+
│ │ └── utils/
|
| 31 |
+
│ │ └── text_extractor.py # Text extraction utilities
|
| 32 |
+
│ ├── mcp_servers/
|
| 33 |
+
│ │ ├── admin_server.py # Admin MCP server
|
| 34 |
+
│ │ ├── database.py # Database connection utilities
|
| 35 |
+
│ │ ├── embeddings.py # Embedding generation
|
| 36 |
+
│ │ ├── main.py # RAG MCP server main
|
| 37 |
+
│ │ ├── rag_server.py # RAG MCP server
|
| 38 |
+
│ │ ├── web_server.py # Web search MCP server (English results)
|
| 39 |
+
│ │ └── models/
|
| 40 |
+
│ │ ├── __init__.py
|
| 41 |
+
│ │ ├── admin.py # Admin request models
|
| 42 |
+
│ │ ├── rag.py # RAG request models
|
| 43 |
+
│ │ └── web.py # Web search request models
|
| 44 |
+
│ ├── tests/
|
| 45 |
+
│ │ ├── conftest.py # Pytest configuration
|
| 46 |
+
│ │ ├── test_agent_orchestrator.py # Orchestrator tests
|
| 47 |
+
│ │ └── test_intent.py # Intent classification tests
|
| 48 |
+
│ └── workers/ # Background workers (empty)
|
| 49 |
+
│
|
| 50 |
+
├── venv/ # Python virtual environment
|
| 51 |
+
├── env.example # Environment variables template
|
| 52 |
+
├── pytest.ini # Pytest configuration
|
| 53 |
+
├── README.md # Project documentation
|
| 54 |
+
├── requirements.txt # Python dependencies
|
| 55 |
+
└── start.bat # Windows startup script
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## Key Files Overview
|
| 59 |
+
|
| 60 |
+
### Core Services
|
| 61 |
+
- **`agent_orchestrator.py`** - Main orchestrator handling multi-tool execution
|
| 62 |
+
- **`tool_selector.py`** - Intelligent multi-tool selection (RAG + Web + LLM)
|
| 63 |
+
- **`intent_classifier.py`** - Classifies user intent
|
| 64 |
+
- **`redflag_detector.py`** - Detects policy violations
|
| 65 |
+
|
| 66 |
+
### MCP Servers
|
| 67 |
+
- **`rag_server.py`** - RAG/knowledge retrieval server
|
| 68 |
+
- **`web_server.py`** - Web search server (forces English results)
|
| 69 |
+
- **`admin_server.py`** - Admin/governance server
|
| 70 |
+
|
| 71 |
+
### API Routes
|
| 72 |
+
- **`agent.py`** - Main chat/agent endpoint
|
| 73 |
+
- **`rag.py`** - RAG operations
|
| 74 |
+
- **`web.py`** - Web search operations
|
| 75 |
+
- **`admin.py`** - Admin operations
|
| 76 |
+
- **`analytics.py`** - Analytics endpoints
|
| 77 |
+
|
| 78 |
+
### Models
|
| 79 |
+
- **`agent.py`** - AgentRequest, AgentDecision, AgentResponse
|
| 80 |
+
- **`redflag.py`** - RedFlagRule, RedFlagMatch
|
| 81 |
+
|
| 82 |
+
### MCP Clients
|
| 83 |
+
- **`mcp_client.py`** - Unified MCP client wrapper
|
| 84 |
+
- **`rag_client.py`** - RAG client
|
| 85 |
+
- **`web_client.py`** - Web search client
|
| 86 |
+
- **`admin_client.py`** - Admin client
|
| 87 |
+
|
requirements.txt
CHANGED
|
@@ -3,7 +3,7 @@ uvicorn
|
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
python-dotenv
|
| 6 |
-
psycopg2
|
| 7 |
supabase
|
| 8 |
sentence-transformers
|
| 9 |
pytest
|
|
|
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
python-dotenv
|
| 6 |
+
psycopg2-binary
|
| 7 |
supabase
|
| 8 |
sentence-transformers
|
| 9 |
pytest
|
start.bat
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
@echo off
|
|
|
|
| 2 |
echo ========================================
|
| 3 |
echo Starting IntegraChat Backend Server
|
| 4 |
echo ========================================
|
| 5 |
echo.
|
| 6 |
|
| 7 |
-
REM Get the directory where the batch file is located
|
| 8 |
cd /d "%~dp0"
|
| 9 |
|
| 10 |
-
REM
|
| 11 |
if not exist "backend" (
|
| 12 |
echo ERROR: backend directory not found!
|
| 13 |
echo Please make sure you're running this from the project root.
|
|
@@ -15,7 +16,11 @@ if not exist "backend" (
|
|
| 15 |
exit /b 1
|
| 16 |
)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
REM Check if Python is available
|
| 21 |
python --version >nul 2>&1
|
|
@@ -30,59 +35,90 @@ echo Python version:
|
|
| 30 |
python --version
|
| 31 |
echo.
|
| 32 |
|
| 33 |
-
REM
|
| 34 |
-
if exist "venv\Scripts\activate.bat" (
|
| 35 |
-
echo
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
-
REM
|
| 41 |
-
echo
|
| 42 |
-
|
| 43 |
if errorlevel 1 (
|
| 44 |
-
echo
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
) else if exist "requirements.txt" (
|
| 48 |
-
pip install -r requirements.txt
|
| 49 |
-
) else (
|
| 50 |
-
echo Installing FastAPI and Uvicorn...
|
| 51 |
-
pip install fastapi uvicorn
|
| 52 |
-
)
|
| 53 |
-
echo.
|
| 54 |
)
|
|
|
|
| 55 |
|
| 56 |
-
REM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if not exist ".env" (
|
| 58 |
-
echo Warning: .env file not found!
|
| 59 |
-
echo Please create .env
|
| 60 |
echo.
|
| 61 |
)
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
REM Start the FastAPI server
|
| 64 |
echo ========================================
|
| 65 |
echo Starting FastAPI server...
|
| 66 |
echo Server will be available at:
|
| 67 |
-
echo http://localhost
|
| 68 |
-
echo http://127.0.0.1
|
| 69 |
echo ========================================
|
| 70 |
echo.
|
| 71 |
echo Press Ctrl+C to stop the server
|
| 72 |
echo.
|
| 73 |
|
| 74 |
-
python -m uvicorn api.main:app --reload --host 0.0.0.0 --port
|
| 75 |
|
| 76 |
if errorlevel 1 (
|
| 77 |
echo.
|
| 78 |
echo ERROR: Failed to start the server!
|
| 79 |
echo.
|
| 80 |
echo Common issues:
|
| 81 |
-
echo 1.
|
| 82 |
-
echo 2.
|
| 83 |
-
echo 3.
|
| 84 |
echo.
|
| 85 |
)
|
| 86 |
|
| 87 |
pause
|
| 88 |
-
|
|
|
|
| 1 |
@echo off
|
| 2 |
+
setlocal enabledelayedexpansion
|
| 3 |
echo ========================================
|
| 4 |
echo Starting IntegraChat Backend Server
|
| 5 |
echo ========================================
|
| 6 |
echo.
|
| 7 |
|
| 8 |
+
REM Get the directory where the batch file is located and move to project root
|
| 9 |
cd /d "%~dp0"
|
| 10 |
|
| 11 |
+
REM Validate project structure
|
| 12 |
if not exist "backend" (
|
| 13 |
echo ERROR: backend directory not found!
|
| 14 |
echo Please make sure you're running this from the project root.
|
|
|
|
| 16 |
exit /b 1
|
| 17 |
)
|
| 18 |
|
| 19 |
+
if not exist "requirements.txt" (
|
| 20 |
+
echo ERROR: requirements.txt not found in project root!
|
| 21 |
+
pause
|
| 22 |
+
exit /b 1
|
| 23 |
+
)
|
| 24 |
|
| 25 |
REM Check if Python is available
|
| 26 |
python --version >nul 2>&1
|
|
|
|
| 35 |
python --version
|
| 36 |
echo.
|
| 37 |
|
| 38 |
+
REM Create virtual environment if needed
|
| 39 |
+
if not exist "venv\Scripts\activate.bat" (
|
| 40 |
+
echo Creating virtual environment...
|
| 41 |
+
python -m venv venv
|
| 42 |
+
if errorlevel 1 (
|
| 43 |
+
echo ERROR: Failed to create virtual environment!
|
| 44 |
+
pause
|
| 45 |
+
exit /b 1
|
| 46 |
+
)
|
| 47 |
)
|
| 48 |
|
| 49 |
+
REM Activate virtual environment
|
| 50 |
+
echo Activating virtual environment...
|
| 51 |
+
call venv\Scripts\activate.bat
|
| 52 |
if errorlevel 1 (
|
| 53 |
+
echo ERROR: Failed to activate virtual environment!
|
| 54 |
+
pause
|
| 55 |
+
exit /b 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
+
echo.
|
| 58 |
|
| 59 |
+
REM Install dependencies from root requirements.txt
|
| 60 |
+
echo Installing/validating dependencies...
|
| 61 |
+
pip install --upgrade pip >nul
|
| 62 |
+
pip install -r requirements.txt
|
| 63 |
+
if errorlevel 1 (
|
| 64 |
+
echo ERROR: Failed to install dependencies!
|
| 65 |
+
pause
|
| 66 |
+
exit /b 1
|
| 67 |
+
)
|
| 68 |
+
echo.
|
| 69 |
+
|
| 70 |
+
REM Check if .env file exists in root
|
| 71 |
if not exist ".env" (
|
| 72 |
+
echo Warning: .env file not found in project root!
|
| 73 |
+
echo Please create .env from env.example if needed.
|
| 74 |
echo.
|
| 75 |
)
|
| 76 |
|
| 77 |
+
REM Prepare environment variables
|
| 78 |
+
set PYTHONPATH=%cd%
|
| 79 |
+
set "APP_PORT=8000"
|
| 80 |
+
if not "%API_PORT%"=="" (
|
| 81 |
+
set "APP_PORT=%API_PORT%"
|
| 82 |
+
)
|
| 83 |
+
set "VENV_PYTHON=%cd%\venv\Scripts\python.exe"
|
| 84 |
+
if not exist "%VENV_PYTHON%" (
|
| 85 |
+
echo ERROR: Could not find python executable in venv!
|
| 86 |
+
pause
|
| 87 |
+
exit /b 1
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
REM Launch MCP servers in separate windows
|
| 91 |
+
echo.
|
| 92 |
+
echo Launching MCP servers in separate windows...
|
| 93 |
+
start "RAG MCP (8001)" "%VENV_PYTHON%" -m uvicorn backend.mcp_servers.main:app --host 0.0.0.0 --port 8001
|
| 94 |
+
start "WEB MCP (8002)" "%VENV_PYTHON%" -m uvicorn backend.mcp_servers.web_server:web_app --host 0.0.0.0 --port 8002
|
| 95 |
+
start "ADMIN MCP (8003)" "%VENV_PYTHON%" -m uvicorn backend.mcp_servers.admin_server:admin_app --host 0.0.0.0 --port 8003
|
| 96 |
+
echo MCP servers started. Close their windows or press Ctrl+C inside them to stop.
|
| 97 |
+
echo.
|
| 98 |
+
|
| 99 |
REM Start the FastAPI server
|
| 100 |
echo ========================================
|
| 101 |
echo Starting FastAPI server...
|
| 102 |
echo Server will be available at:
|
| 103 |
+
echo http://localhost:%APP_PORT%
|
| 104 |
+
echo http://127.0.0.1:%APP_PORT%
|
| 105 |
echo ========================================
|
| 106 |
echo.
|
| 107 |
echo Press Ctrl+C to stop the server
|
| 108 |
echo.
|
| 109 |
|
| 110 |
+
python -m uvicorn backend.api.main:app --reload --host 0.0.0.0 --port %APP_PORT%
|
| 111 |
|
| 112 |
if errorlevel 1 (
|
| 113 |
echo.
|
| 114 |
echo ERROR: Failed to start the server!
|
| 115 |
echo.
|
| 116 |
echo Common issues:
|
| 117 |
+
echo 1. Verify backend/api/main.py exists
|
| 118 |
+
echo 2. Ensure dependencies installed correctly
|
| 119 |
+
echo 3. Check if another process is using port %APP_PORT%
|
| 120 |
echo.
|
| 121 |
)
|
| 122 |
|
| 123 |
pause
|
| 124 |
+
endlocal
|