@relipa/ai-flow-kit 0.2.0-beta.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom/rules/java/spring-boot-rules.md +209 -0
- package/custom/rules/javascript/nestjs-examples.md +41 -0
- package/custom/rules/javascript/nestjs-rules.md +42 -0
- package/custom/rules/javascript/nodejs-express-examples.md +35 -0
- package/custom/rules/javascript/nodejs-express-rules.md +49 -0
- package/custom/rules/javascript/reactjs-examples.md +380 -0
- package/custom/rules/javascript/reactjs-rules.md +173 -0
- package/custom/rules/php/php-examples.md +161 -0
- package/custom/rules/php/php-rules.md +127 -0
- package/custom/rules/python/python-django-examples.md +34 -0
- package/custom/rules/python/python-django-rules.md +48 -0
- package/custom/rules/python/python-examples.md +32 -0
- package/custom/rules/python/python-fastapi-examples.md +30 -0
- package/custom/rules/python/python-fastapi-rules.md +35 -0
- package/custom/rules/python/python-ml-examples.md +187 -0
- package/custom/rules/python/python-ml-rules.md +121 -0
- package/custom/rules/python/python-rules.md +58 -0
- package/custom/skills/ba-skills/skill-ba-qna-template-v1.md +4 -4
- package/custom/skills/ba-skills/skill-ba-qna-v1.md +6 -0
- package/custom/skills/create-system-requirement/SKILL.md +52 -16
- package/custom/skills/create-system-requirement/system-requirement-template-v1.md +128 -0
- package/custom/skills/impact-analysis/SKILL.md +106 -106
- package/custom/skills/ingest-data/SKILL.md +53 -5
- package/custom/skills/report-customer/SKILL.md +99 -99
- package/custom/templates/nestjs.md +5 -72
- package/custom/templates/nodejs-express.md +5 -73
- package/custom/templates/php-plain.md +5 -261
- package/custom/templates/php.md +5 -261
- package/custom/templates/python-django.md +5 -71
- package/custom/templates/python-fastapi.md +5 -54
- package/custom/templates/python-ml.md +1 -269
- package/custom/templates/python.md +5 -79
- package/custom/templates/reactjs.md +5 -492
- package/custom/templates/shared/create-testcase-workflow.md +30 -2
- package/custom/templates/shared/gate-workflow.md +5 -3
- package/custom/templates/shared/ml-gate-workflow.md +1 -0
- package/custom/templates/spring-boot.md +5 -224
- package/docs/common/CHANGELOG.md +20 -10
- package/package.json +1 -1
- package/scripts/init.js +143 -40
- package/scripts/link-resolver.js +60 -24
- package/scripts/ticket-writer.js +72 -3
|
@@ -2,272 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
You are an expert ML engineer. Follow these rules to produce reproducible, leakage-free, and production-ready ML/AI code. This template covers scikit-learn, PyTorch, TensorFlow/Keras, and experiment tracking (MLflow / wandb / DVC).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Project Structure
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
project/
|
|
11
|
-
├── data/ # raw/, interim/, processed/ (git-ignored, DVC-tracked)
|
|
12
|
-
├── notebooks/ # EDA only — not productionized code
|
|
13
|
-
├── src/
|
|
14
|
-
│ ├── data/ # loading + splitting
|
|
15
|
-
│ ├── features/ # feature engineering (fit on train only)
|
|
16
|
-
│ ├── models/ # model definitions + training entrypoints
|
|
17
|
-
│ └── eval/ # metric + evaluation harness
|
|
18
|
-
├── configs/ # YAML/Hydra hyperparameter configs
|
|
19
|
-
├── experiments/ # tracked run outputs / logs
|
|
20
|
-
├── models/ # saved artifacts (DVC/registry-tracked)
|
|
21
|
-
├── requirements.txt # pinned
|
|
22
|
-
└── pyproject.toml
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Reproducibility Rules
|
|
28
|
-
|
|
29
|
-
- Set **all seeds** before any randomness: `random.seed(n)`, `numpy.random.seed(n)`, and the framework seed.
|
|
30
|
-
- Enable deterministic flags where feasible; document any performance trade-off.
|
|
31
|
-
- **Pin the environment:** `requirements.txt` or a lockfile committed alongside every artifact.
|
|
32
|
-
- Log the seed, config, and git commit SHA with every tracked run.
|
|
33
|
-
|
|
34
|
-
```python
|
|
35
|
-
# ✅ Good — set all seeds at entrypoint
|
|
36
|
-
import random, numpy as np, torch
|
|
37
|
-
|
|
38
|
-
def set_seed(seed: int) -> None:
|
|
39
|
-
random.seed(seed)
|
|
40
|
-
np.random.seed(seed)
|
|
41
|
-
torch.manual_seed(seed)
|
|
42
|
-
torch.use_deterministic_algorithms(True)
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Config Management
|
|
48
|
-
|
|
49
|
-
- Hyperparameters live in YAML / Hydra / argparse configs — **never hardcoded**.
|
|
50
|
-
- The config file is saved alongside every model artifact.
|
|
51
|
-
|
|
52
|
-
```python
|
|
53
|
-
# ✅ Good — load config from file
|
|
54
|
-
from dataclasses import dataclass
|
|
55
|
-
import yaml
|
|
56
|
-
|
|
57
|
-
@dataclass
|
|
58
|
-
class TrainConfig:
|
|
59
|
-
lr: float
|
|
60
|
-
max_epochs: int
|
|
61
|
-
batch_size: int
|
|
62
|
-
seed: int
|
|
63
|
-
|
|
64
|
-
def load_config(path: str) -> TrainConfig:
|
|
65
|
-
with open(path) as f:
|
|
66
|
-
return TrainConfig(**yaml.safe_load(f))
|
|
67
|
-
|
|
68
|
-
# ❌ Bad — hyperparameters hardcoded in training script
|
|
69
|
-
lr = 0.001
|
|
70
|
-
epochs = 50
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## Leakage Prevention
|
|
76
|
-
|
|
77
|
-
- **Split before fit** — perform the split BEFORE fitting any transformer, scaler, or encoder.
|
|
78
|
-
- **Fit transforms on train fold only** — all preprocessing lives inside a `Pipeline` fit only on training data.
|
|
79
|
-
- **Time-aware splits** — for temporal data, use `TimeSeriesSplit`; never shuffle time-indexed data.
|
|
80
|
-
|
|
81
|
-
```python
|
|
82
|
-
# ✅ Good — pipeline inside CV; transforms fit on train fold only
|
|
83
|
-
from sklearn.pipeline import Pipeline
|
|
84
|
-
from sklearn.preprocessing import StandardScaler
|
|
85
|
-
from sklearn.linear_model import LogisticRegression
|
|
86
|
-
from sklearn.model_selection import StratifiedKFold, cross_val_score
|
|
87
|
-
|
|
88
|
-
pipe = Pipeline([
|
|
89
|
-
("scaler", StandardScaler()),
|
|
90
|
-
("clf", LogisticRegression()),
|
|
91
|
-
])
|
|
92
|
-
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
|
|
93
|
-
scores = cross_val_score(pipe, X_train, y_train, cv=cv, scoring="roc_auc")
|
|
94
|
-
|
|
95
|
-
# ❌ Bad — scaler fit on full data before split (leakage)
|
|
96
|
-
scaler = StandardScaler().fit(X)
|
|
97
|
-
X_scaled = scaler.transform(X)
|
|
98
|
-
X_train, X_test = train_test_split(X_scaled, ...)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## Framework Idioms
|
|
104
|
-
|
|
105
|
-
### scikit-learn
|
|
106
|
-
|
|
107
|
-
- Use `Pipeline` + `ColumnTransformer` for all preprocessing — never transform outside a pipeline.
|
|
108
|
-
- Use `set_output(transform="pandas")` (sklearn ≥ 1.2) to preserve feature names.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
from sklearn.compose import ColumnTransformer
|
|
112
|
-
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
|
113
|
-
from sklearn.pipeline import Pipeline
|
|
114
|
-
|
|
115
|
-
preprocessor = ColumnTransformer([
|
|
116
|
-
("num", StandardScaler(), num_cols),
|
|
117
|
-
("cat", OneHotEncoder(handle_unknown="ignore"), cat_cols),
|
|
118
|
-
])
|
|
119
|
-
pipe = Pipeline([("prep", preprocessor), ("model", clf)])
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### PyTorch
|
|
123
|
-
|
|
124
|
-
- Seed the `DataLoader` worker init function for full reproducibility.
|
|
125
|
-
- Always switch between `model.train()` and `model.eval()` modes; use `torch.no_grad()` for validation.
|
|
126
|
-
|
|
127
|
-
```python
|
|
128
|
-
import torch
|
|
129
|
-
from torch.utils.data import DataLoader
|
|
130
|
-
|
|
131
|
-
def seed_worker(worker_id: int) -> None:
|
|
132
|
-
import random, numpy as np
|
|
133
|
-
worker_seed = torch.initial_seed() % (2**32)
|
|
134
|
-
random.seed(worker_seed)
|
|
135
|
-
np.random.seed(worker_seed)
|
|
136
|
-
|
|
137
|
-
g = torch.Generator()
|
|
138
|
-
g.manual_seed(42)
|
|
139
|
-
loader = DataLoader(dataset, batch_size=32, worker_init_fn=seed_worker, generator=g)
|
|
140
|
-
|
|
141
|
-
# Training loop
|
|
142
|
-
model.train()
|
|
143
|
-
for batch in train_loader:
|
|
144
|
-
...
|
|
145
|
-
|
|
146
|
-
# Validation loop
|
|
147
|
-
model.eval()
|
|
148
|
-
with torch.no_grad():
|
|
149
|
-
for batch in val_loader:
|
|
150
|
-
...
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### TensorFlow / Keras
|
|
154
|
-
|
|
155
|
-
- Use callbacks for checkpointing (save best by validation metric) and early stopping.
|
|
156
|
-
- Set `tf.random.set_seed` at startup.
|
|
157
|
-
|
|
158
|
-
```python
|
|
159
|
-
import tensorflow as tf
|
|
160
|
-
|
|
161
|
-
tf.random.set_seed(42)
|
|
162
|
-
|
|
163
|
-
callbacks = [
|
|
164
|
-
tf.keras.callbacks.ModelCheckpoint(
|
|
165
|
-
filepath="models/best.keras",
|
|
166
|
-
monitor="val_loss",
|
|
167
|
-
save_best_only=True,
|
|
168
|
-
),
|
|
169
|
-
tf.keras.callbacks.EarlyStopping(
|
|
170
|
-
monitor="val_loss",
|
|
171
|
-
patience=5,
|
|
172
|
-
restore_best_weights=True,
|
|
173
|
-
),
|
|
174
|
-
]
|
|
175
|
-
model.fit(X_train, y_train, validation_data=(X_val, y_val), callbacks=callbacks)
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### HuggingFace (LLM fine-tuning)
|
|
179
|
-
|
|
180
|
-
- Use a freeze/unfreeze schedule; start with a small learning rate and add warmup.
|
|
181
|
-
- Log the base model name, adapter config, and dataset version alongside the run.
|
|
182
|
-
|
|
183
|
-
```python
|
|
184
|
-
from transformers import Trainer, TrainingArguments
|
|
185
|
-
|
|
186
|
-
args = TrainingArguments(
|
|
187
|
-
output_dir="models/ft-run",
|
|
188
|
-
num_train_epochs=3,
|
|
189
|
-
learning_rate=2e-5,
|
|
190
|
-
warmup_ratio=0.1,
|
|
191
|
-
seed=42,
|
|
192
|
-
report_to="mlflow",
|
|
193
|
-
)
|
|
194
|
-
trainer = Trainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds)
|
|
195
|
-
trainer.train()
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Experiment Tracking
|
|
201
|
-
|
|
202
|
-
- Log params, metrics per epoch/fold, seed, data version, and git commit to MLflow or wandb.
|
|
203
|
-
- Name each run per the scheme in `custom/rules/ml-conventions.md`: `[ticket-id]_[approach]_[yyyymmdd-n]`.
|
|
204
|
-
- Version datasets with DVC; store the DVC data hash in the run metadata.
|
|
205
|
-
|
|
206
|
-
```python
|
|
207
|
-
import mlflow
|
|
208
|
-
|
|
209
|
-
mlflow.set_experiment("my-project")
|
|
210
|
-
with mlflow.start_run(run_name="ML-42_lgbm-tfidf_20241115-1"):
|
|
211
|
-
mlflow.log_params({"lr": cfg.lr, "seed": cfg.seed, "data_version": "v1.2"})
|
|
212
|
-
mlflow.log_metric("val_roc_auc", val_score)
|
|
213
|
-
mlflow.sklearn.log_model(pipe, artifact_path="model")
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## Notebook Hygiene
|
|
219
|
-
|
|
220
|
-
- `notebooks/` is for EDA and exploration only — not production code.
|
|
221
|
-
- Productionized logic (features, models, eval) migrates to `src/` as importable modules.
|
|
222
|
-
- Notebooks must not import from each other; shared utilities go to `src/`.
|
|
223
|
-
- Clear outputs before committing notebooks (or use `nbstripout`).
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Testing Rules
|
|
228
|
-
|
|
229
|
-
- Use **Pytest** for all `src/` utilities.
|
|
230
|
-
- Test the **metric harness** directly: assert known inputs produce the expected metric value.
|
|
231
|
-
- Test **data-split functions** for leakage: verify no sample ID appears in both train and test sets.
|
|
232
|
-
- Test feature-engineering functions independently with synthetic data.
|
|
233
|
-
|
|
234
|
-
```python
|
|
235
|
-
import pytest
|
|
236
|
-
import numpy as np
|
|
237
|
-
from src.eval.metrics import binary_roc_auc
|
|
238
|
-
from src.data.splits import make_temporal_split
|
|
239
|
-
|
|
240
|
-
def test_roc_auc_perfect_classifier():
|
|
241
|
-
y_true = np.array([0, 0, 1, 1])
|
|
242
|
-
y_score = np.array([0.1, 0.2, 0.8, 0.9])
|
|
243
|
-
assert binary_roc_auc(y_true, y_score) == pytest.approx(1.0)
|
|
244
|
-
|
|
245
|
-
def test_temporal_split_no_leakage():
|
|
246
|
-
train_ids, test_ids = make_temporal_split(df, date_col="event_date", test_months=3)
|
|
247
|
-
overlap = set(train_ids) & set(test_ids)
|
|
248
|
-
assert len(overlap) == 0, f"Leakage: {len(overlap)} overlapping IDs"
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## Naming Conventions
|
|
254
|
-
|
|
255
|
-
| Element | Convention | Example |
|
|
256
|
-
|---------|-----------|---------|
|
|
257
|
-
| Module/package | snake_case | `feature_engineering.py` |
|
|
258
|
-
| Class | PascalCase | `TemporalSplit`, `TrainConfig` |
|
|
259
|
-
| Function/variable | snake_case | `train_model`, `val_score` |
|
|
260
|
-
| Constant | UPPER_SNAKE_CASE | `DEFAULT_SEED`, `MAX_EPOCHS` |
|
|
261
|
-
| Experiment run | `[ticket-id]_[approach]_[yyyymmdd-n]` | `ML-42_lgbm-tfidf_20241115-1` |
|
|
262
|
-
|
|
263
|
-
---
|
|
264
|
-
|
|
265
|
-
## Common Anti-Patterns to Avoid
|
|
266
|
-
|
|
267
|
-
- ❌ Fitting scalers/encoders on the full dataset before splitting — always fit inside a `Pipeline` on the train fold only
|
|
268
|
-
- ❌ Hardcoded hyperparameters — use configs
|
|
269
|
-
- ❌ No seeds — always set `random`, `numpy`, and framework seeds
|
|
270
|
-
- ❌ Evaluating on validation data used for tuning — keep a held-out test set for final Gate 4 reporting
|
|
271
|
-
- ❌ Production logic in notebooks — migrate to `src/`
|
|
272
|
-
- ❌ Committing data files or model binaries to git — track with DVC or a registry
|
|
273
|
-
- ❌ Single aggregate metric without error analysis — always inspect failure cases and slices
|
|
5
|
+
> **Rules & code examples:** Read `.rules/python/python-ml-rules.md` (structure, reproducibility, leakage prevention, framework idioms, naming, anti-patterns) and `.rules/python/python-ml-examples.md` (code samples per rule area) **in full** before writing or modifying any ML/AI code in this project.
|
|
@@ -1,79 +1,5 @@
|
|
|
1
|
-
# Python AI System Prompt
|
|
2
|
-
|
|
3
|
-
You are an expert Python developer. Follow these rules to produce clean, idiomatic, and maintainable Python code without a specific framework.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Project Structure
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
project/
|
|
11
|
-
├── main.py # Entry point
|
|
12
|
-
├── src/
|
|
13
|
-
│ ├── service/ # Business logic
|
|
14
|
-
│ ├── repository/ # Data access layer
|
|
15
|
-
│ ├── model/ # Data classes / domain models
|
|
16
|
-
│ └── util/ # Pure helper functions
|
|
17
|
-
├── tests/ # Pytest suite
|
|
18
|
-
├── requirements.txt
|
|
19
|
-
└── pyproject.toml
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Python Rules
|
|
25
|
-
|
|
26
|
-
- Use **type hints** on all function signatures and return types.
|
|
27
|
-
- Follow **PEP 8** and keep functions small and single-purpose.
|
|
28
|
-
- Use **dataclasses** or **NamedTuple** for value objects; avoid plain dicts for structured data.
|
|
29
|
-
- Prefer **pathlib** over `os.path`; prefer `with` statements for file/resource handling.
|
|
30
|
-
- Raise specific exceptions — never `raise Exception("message")`.
|
|
31
|
-
|
|
32
|
-
```python
|
|
33
|
-
# ✅ Good
|
|
34
|
-
from dataclasses import dataclass
|
|
35
|
-
|
|
36
|
-
@dataclass
|
|
37
|
-
class UserRequest:
|
|
38
|
-
email: str
|
|
39
|
-
full_name: str
|
|
40
|
-
|
|
41
|
-
def create_user(request: UserRequest) -> UserResponse:
|
|
42
|
-
if not request.email:
|
|
43
|
-
raise ValueError("email is required")
|
|
44
|
-
...
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
## Testing Rules
|
|
50
|
-
|
|
51
|
-
- Use **Pytest** for all tests.
|
|
52
|
-
- Name test functions `test_<what>_<expected_outcome>`.
|
|
53
|
-
- Use `pytest.raises` to assert exceptions.
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
def test_create_user_raises_when_email_is_empty():
|
|
57
|
-
with pytest.raises(ValueError, match="email is required"):
|
|
58
|
-
create_user(UserRequest(email="", full_name="Test"))
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Naming Conventions
|
|
64
|
-
|
|
65
|
-
| Element | Convention | Example |
|
|
66
|
-
|---------|-----------|---------|
|
|
67
|
-
| Module/package | snake_case | `user_service.py` |
|
|
68
|
-
| Class | PascalCase | `UserService` |
|
|
69
|
-
| Function/variable | snake_case | `find_by_id`, `user_id` |
|
|
70
|
-
| Constant | UPPER_SNAKE_CASE | `MAX_RETRY` |
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## Common Anti-Patterns to Avoid
|
|
75
|
-
|
|
76
|
-
- ❌ Bare `except:` — always catch a specific exception type
|
|
77
|
-
- ❌ Mutable default arguments (`def f(x=[])`) — use `None` sentinel instead
|
|
78
|
-
- ❌ Global state — pass dependencies explicitly
|
|
79
|
-
- ❌ Returning `None` implicitly on error paths — raise or return a typed result
|
|
1
|
+
# Python AI System Prompt
|
|
2
|
+
|
|
3
|
+
You are an expert Python developer. Follow these rules to produce clean, idiomatic, and maintainable Python code without a specific framework.
|
|
4
|
+
|
|
5
|
+
> **Rules & code examples:** Read `.rules/python/python-rules.md` (structure, rules, naming, anti-patterns) and `.rules/python/python-examples.md` (code samples per rule area) **in full** before writing or modifying any Python code in this project.
|