Prerequisites
Before beginning, ensure you have:Python 3.9+
Required for running the AI service
pip or venv
Package manager for installing dependencies
Backend Running
The Spring Boot backend must be accessible
Network Access
Connection to backend API (default: localhost:8080)
Python 3.9 or higher is required due to type hints and dictionary merge operators used in the code.
Installation Steps
Install Dependencies
Install all required Python packages:This installs:
- requests: HTTP client for API calls
- pandas: Data manipulation
- numpy: Numerical computations
- python-dotenv: Environment variable management
- websocket-client: Real-time backend communication
- flask: Optional REST API server
Configure Environment
Create a Or modify
.env file in the ia/ directory:config.py
config.py directly:config.py
Running the AI Service
The AI system can operate in two modes:1. Manual Mode (main.py)
Interactive CLI for processing individual surgeries:- Interactive menu system
- Process single surgery by UUID
- Batch processing capability
- Manual authentication
2. WebSocket Mode (websocket_client.py)
Automated service that listens for backend notifications:- Automatic authentication
- Real-time surgery notifications
- Automatic analysis and submission
- Reconnection on failure
Configuration Options
Backend URL
If your backend runs on a different host or port:Authentication
The default AI credentials are:- Username:
ia_justina - Password:
ia_secret_2024 - Role:
ROLE_IA
Timeouts and Retries
Testing the Setup
Quick Test
Run a test with sample data:End-to-End Test
- Start the backend
- Run the AI service:
- Choose option 2 (batch processing)
- Verify analysis completes successfully
Troubleshooting
ModuleNotFoundError: No module named 'pandas'
ModuleNotFoundError: No module named 'pandas'
Ensure you’ve activated the virtual environment and run
pip install -r requirements.txt.Connection refused to http://localhost:8080
Connection refused to http://localhost:8080
The backend isn’t running. Start it first:
401 Unauthorized error
401 Unauthorized error
WebSocket connection fails immediately
WebSocket connection fails immediately
Check that:
- Backend WebSocket endpoint is enabled
- JWT token is valid
- Firewall allows WebSocket connections
- URL uses
ws://nothttp://
Production Deployment
For production environments:Use a Process Manager
Run the AI service with systemd or supervisor:Enable and start:
/etc/systemd/system/justina-ai.service
Next Steps
Client Usage
Learn how to use the JustinaAIClient class
API Integration
Understand the WebSocket notification system