Files
goodgo-platform/libs/ai-services
Ho Ngoc Hai 66f952a4a8 feat(ai-services): complete AVM v2 ensemble — upload endpoint, per-district metrics, A/B routing
- Add POST /avm/v2/upload-training-data so AvmRetrainCronService can push
  CSV rows before triggering retraining (was called but missing)
- Add per-district MAE/MAPE/RMSE/R² to _evaluate_ensemble output;
  district_metrics are now returned in AVMv2TrainResponse and stored
  separately from global metrics in the model registry
- Add predict_with_ab() that applies the active model's ab_test_traffic_pct
  for deterministic per-property cohort assignment (v2 vs heuristic baseline)
- Add POST /avm/v2/ab-config to set traffic_pct on the active registry entry
- Add AVMv2ABConfigRequest schema
- Expand test suite: 24 → 28 tests covering upload, A/B config, and new
  validation paths; all green

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-21 04:39:57 +07:00
..

@goodgo/ai-services

Microservice AI/ML viết bằng Python FastAPI cho GoodGo Platform.

Các dịch vụ

Dịch vụ Router Mô tả
AVM /avm Mô hình định giá tự động — dự đoán giá bất động sản dựa trên XGBoost
Moderation /moderation Kiểm duyệt nội dung tin đăng (phân tích văn bản + hình ảnh)
NLP /nlp NLP tiếng Việt — trích xuất đặc trưng, hiểu truy vấn tìm kiếm

Tech Stack

  • Python 3.12+
  • FastAPI 0.115 + Uvicorn
  • XGBoost 2.1 (mô hình định giá bất động sản)
  • Underthesea 6.8 (tokenizer NLP tiếng Việt)
  • Pydantic 2.9 (schema request/response)

Quick Start

# Via Docker (recommended — runs as part of the platform stack)
docker compose up -d ai-services

# Standalone
cd libs/ai-services
pip install -e ".[dev]"
uvicorn app.main:app --reload --port 8000

Cấu trúc dự án

libs/ai-services/
├── app/
│   ├── main.py          # FastAPI app entry point
│   ├── config.py        # Settings (Pydantic BaseSettings)
│   ├── middleware.py     # CORS, rate limiting, error handling
│   ├── models/          # Pydantic request/response schemas
│   │   ├── avm.py
│   │   ├── moderation.py
│   │   └── nlp.py
│   ├── routers/         # API route handlers
│   │   ├── avm.py
│   │   ├── moderation.py
│   │   └── nlp.py
│   └── services/        # Business logic
│       ├── avm_service.py
│       ├── moderation_service.py
│       └── nlp_service.py
├── tests/               # pytest test suite
├── Dockerfile           # Production container image
└── pyproject.toml       # Dependencies and config

Test

cd libs/ai-services
pytest

Health Check

GET /health → {"status": "ok"}