Spaces:
Sleeping
Sleeping
| """Register Amul AI as a target in CeRAI's database. | |
| Run this once after `python AIEvaluationTool/src/app/importer/main.py --config config.json`. | |
| Idempotent: CeRAI's `add_or_get_target` looks up by name. | |
| Usage: | |
| python scripts/register_amul_target.py | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| CERAI = ROOT / "AIEvaluationTool" | |
| sys.path.insert(0, str(CERAI / "src")) | |
| from lib.orm.DB import DB # noqa: E402 | |
| from lib.data import Target # noqa: E402 | |
| def main() -> None: | |
| cfg_path = CERAI / "config.json" | |
| cfg = json.loads(cfg_path.read_text()) | |
| engine = cfg["db"].get("engine", "sqlite").lower() | |
| if engine == "sqlite": | |
| # Match the importer/executor: DB lives under AIEvaluationTool/data/<file>. | |
| db_path = CERAI / "data" / cfg["db"].get("file", "AIEvaluationData.db") | |
| db_url = f"sqlite:///{db_path}" | |
| elif engine == "mariadb": | |
| c = cfg["db"] | |
| db_url = ( | |
| f"mariadb+mariadbconnector://{c['user']}:{c['password']}" | |
| f"@{c['host']}:{c['port']}/{c['database']}" | |
| ) | |
| else: | |
| raise SystemExit(f"Unsupported db engine: {engine}") | |
| db = DB(db_url=db_url, debug=False) | |
| tgt = Target( | |
| target_name="Amul AI", | |
| target_type="API", | |
| target_url="http://localhost:8088", | |
| target_description=( | |
| "Public dairy/animal-husbandry chat assistant hosted at amulai.in/chat. " | |
| "The upstream is a GET-SSE endpoint on api.prod.amulai.in; " | |
| "the URL above points to amul_proxy/server.py — an OpenAI-compatible " | |
| "shim that forwards POST /v1/chat/completions to the upstream." | |
| ), | |
| target_domain="agriculture", | |
| target_languages=["english"], | |
| ) | |
| tid = db.add_or_get_target(target=tgt) | |
| print(f"Registered target 'Amul AI' (id={tid}) in {db_url}") | |
| if __name__ == "__main__": | |
| main() |