|
| 1 | +# AI-on-Demand dev environment setup guide |
| 2 | + |
| 3 | +This guide sets up a complete local development environment for AI-on-Demand, which consists of: |
| 4 | + |
| 5 | +**What you'll set up:** |
| 6 | +1. Python client library (`aiondemand`) |
| 7 | +2. REST API backend service (`AIOD-rest-api`) |
| 8 | +3. Development tools (linting, testing, pre-commit hooks) |
| 9 | + |
| 10 | +Both repositories work together as a single system and should be tested together. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- Python 3.10 or higher (check with command: `python -V`) |
| 17 | +- pip package manager (check with command: `pip list`) |
| 18 | +- Docker setup (check with command: `docker ps`) |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## One-Time Initial Setup |
| 23 | + |
| 24 | +### Part 1: Setup `aiondemand` (Python Client) |
| 25 | + |
| 26 | +Clone the repository: |
| 27 | +```bash |
| 28 | +git clone https://github.com/aiondemand/aiondemand |
| 29 | +cd aiondemand |
| 30 | +``` |
| 31 | + |
| 32 | +**Create and activate virtual environment:** |
| 33 | + |
| 34 | +```bash |
| 35 | +# Create venv |
| 36 | +python -m venv venv |
| 37 | +``` |
| 38 | + |
| 39 | +**Windows:** |
| 40 | +```bash |
| 41 | +.\venv\Scripts\activate |
| 42 | +``` |
| 43 | + |
| 44 | +**Mac/Linux:** |
| 45 | +```bash |
| 46 | +source venv/bin/activate |
| 47 | +``` |
| 48 | + |
| 49 | +**Install Package with developer dependencies** |
| 50 | + |
| 51 | +```bash |
| 52 | +pip install -e ".[dev]" |
| 53 | +``` |
| 54 | + |
| 55 | +**Quick check**: |
| 56 | +```bash |
| 57 | +python -c "import aiod; print('aiondemand installed successfully!')" |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### Part 2: Setup `AIOD-rest-api` (Backend Service) |
| 63 | + |
| 64 | +Clone the repository: |
| 65 | +```bash |
| 66 | +git clone https://github.com/aiondemand/AIOD-rest-api |
| 67 | +cd AIOD-rest-api |
| 68 | +``` |
| 69 | + |
| 70 | +**Configure environment:** |
| 71 | + |
| 72 | +Edit the `.env` file to enable local development mode (located at line no.: 4): |
| 73 | +```bash |
| 74 | +USE_LOCAL_DEV=true |
| 75 | +``` |
| 76 | + |
| 77 | +**Build Docker images** (one-time): |
| 78 | +```bash |
| 79 | +# Build specific images |
| 80 | +docker compose build app |
| 81 | +docker compose build deletion |
| 82 | + |
| 83 | +# Build all images |
| 84 | +docker compose build |
| 85 | + |
| 86 | +# Run DB data migration |
| 87 | +docker compose up fill-db-with-examples |
| 88 | +``` |
| 89 | + |
| 90 | +- **Note:** Add this command in the `Dockerfile` after the `apt-get install` block if the python package dependencies seem to be broken (happens sometimes in Windows): `pip install --upgrade pip setuptools wheel` |
| 91 | + |
| 92 | +**Running tests** |
| 93 | +```bash |
| 94 | +py -3.11 -m venv .venv |
| 95 | +.venv\Scripts\activate |
| 96 | +pip install -e ".[dev]" |
| 97 | +pytest src/tests |
| 98 | +``` |
| 99 | +Note: currently the tests are expected to fail. update regarding this is currently tracked here: https://github.com/aiondemand/AIOD-rest-api/issues/681 |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Complete System Verification |
| 104 | + |
| 105 | +After completing both setup parts, verify the entire system is working: |
| 106 | + |
| 107 | +### 1. Verify Python Client Installation |
| 108 | +```bash |
| 109 | +cd aiondemand |
| 110 | +.\venv\Scripts\activate # Windows |
| 111 | +# source venv/bin/activate # Mac/Linux |
| 112 | + |
| 113 | +python -c "import aiod; print(f'aiod version: {aiod.__version__}')" |
| 114 | +``` |
| 115 | + |
| 116 | +### 2. Verify REST API Service |
| 117 | +Start the services: |
| 118 | +```bash |
| 119 | +cd AIOD-rest-api |
| 120 | +docker compose up |
| 121 | +``` |
| 122 | + |
| 123 | +Check API documentation at: `http://localhost:8000/docs` |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +### 3. Verify data migration in database |
| 128 | +As the mysql database does not expose any ports, we cannot check the data in tables directly using a db client. instead we can manually check from the openapi docs or run `curl` request on the actual fastpi endpoint to check if there is any data in the table: |
| 129 | + |
| 130 | +```bash |
| 131 | +curl "http://localhost:8000/counts/contacts?detailed=false" |
| 132 | +``` |
| 133 | +- Should return 1 |
| 134 | + |
| 135 | +### 4. Verify Elasticsearch |
| 136 | +Go to `http://localhost:9200` and login with: |
| 137 | +- **Username:** `elastic` |
| 138 | +- **Password:** `changeme` |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## Common Development Tasks |
| 145 | + |
| 146 | +### Using the SDK with a Local Backend |
| 147 | + |
| 148 | + |
| 149 | +By default, the SDK (`aiod`) connects to the remote production backend at `https://api.aiod.eu/`. To use your locally running backend (for development or testing), update the API server URL in your code as follows: |
| 150 | + |
| 151 | +### 1. Configure SDK to Use Local Backend |
| 152 | + |
| 153 | +Set the API server URL before making any requests: |
| 154 | + |
| 155 | +```python |
| 156 | +import aiod |
| 157 | + |
| 158 | +# Point the SDK to your locally running backend |
| 159 | +aiod.config.api_server = "http://localhost:8000/" |
| 160 | +``` |
| 161 | + |
| 162 | +### 2. Fetch Data from Local Backend |
| 163 | + |
| 164 | +Now you can use the SDK as usual, and it will communicate with your local backend. For example, to fetch a list of contacts (assuming your local database has data): |
| 165 | + |
| 166 | +```python |
| 167 | +import aiod |
| 168 | + |
| 169 | +# Ensure the SDK is using the local backend |
| 170 | +aiod.config.api_server = "http://localhost:8000/" |
| 171 | + |
| 172 | +# Fetch and print the list of contacts |
| 173 | +contacts = aiod.contacts.get_list() |
| 174 | +print(contacts) |
| 175 | +``` |
| 176 | + |
| 177 | +To confirm your local server is set up perfectly, it should return a response like this: |
| 178 | + |
| 179 | +```bash |
| 180 | + platform platform_resource_identifier ... telephone identifier |
| 181 | +0 example 1 ... [0032 xxxx xxxx] con_osweUoxaTYQDVuoEwz9HdWXx |
| 182 | + |
| 183 | +[1 rows x 7 columns] |
| 184 | +``` |
| 185 | + |
| 186 | +This will retrieve data from your locally running backend instead of the remote server. You can set `aiod.config.api_server` to any remote or local URL as needed. |
| 187 | + |
| 188 | +### Starting the Development Environment |
| 189 | + |
| 190 | +**Every time you work on the project:** |
| 191 | + |
| 192 | +1. **Activate Python environment:** |
| 193 | + ```bash |
| 194 | + cd aiondemand |
| 195 | + .\venv\Scripts\activate # Windows |
| 196 | + # source venv/bin/activate # Mac/Linux |
| 197 | + ``` |
| 198 | + |
| 199 | +2. **Start backend services:** |
| 200 | + ```bash |
| 201 | + cd AIOD-rest-api |
| 202 | + docker compose up |
| 203 | + ``` |
| 204 | + |
| 205 | +3. **Stop services when done:** |
| 206 | +```bash |
| 207 | +# In the AIOD-rest-api terminal, press Ctrl+C, then: |
| 208 | +docker compose down |
| 209 | +``` |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## Contributor Workflow Guide |
| 214 | + |
| 215 | +Before raising a pull request, run these checks to ensure code quality: |
| 216 | + |
| 217 | +### Run Full Test Suite |
| 218 | +```bash |
| 219 | +cd aiondemand |
| 220 | +.\venv\Scripts\activate # Windows |
| 221 | +# source venv/bin/activate # Mac/Linux |
| 222 | + |
| 223 | +python -m pytest -v |
| 224 | +``` |
| 225 | + |
| 226 | +### Run Linting |
| 227 | +```bash |
| 228 | +ruff check . |
| 229 | +``` |
| 230 | + |
| 231 | +### Auto-fix Linting Issues |
| 232 | +```bash |
| 233 | +ruff check --fix . |
| 234 | +``` |
| 235 | + |
| 236 | +### Run Pre-commit Hooks |
| 237 | +```bash |
| 238 | +pre-commit run --all-files |
| 239 | +``` |
0 commit comments