#!/usr/bin/env bash
# 赛题生成实验
# 职责：基于 300 棵视频树 + VLM 生成训练题目，写入 store/questions/generated/。
# 用法:
#   bash scripts/generate_questions.sh                          # 默认参数
#   PER_TYPE=5 bash scripts/generate_questions.sh               # 每题型 5 道（smoke test）
#   CONCURRENCY=4 bash scripts/generate_questions.sh            # 低并发（省 API）
#   SEED=42 bash scripts/generate_questions.sh                  # 指定随机种子
set -euo pipefail

cd "$(dirname "$0")/.."

CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-0}"
export CUDA_VISIBLE_DEVICES

# Embedding 模型已缓存本地，跳过 HuggingFace Hub 在线检查
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1

# 禁止任何形式的日志缓存，确保所有日志立刻输出
export PYTHONUNBUFFERED=1

# 加载环境变量（API key 等）
set -a
source .env
set +a

PYTHON="$(conda run -n Video-Tree-TRM which python)"

"${PYTHON}" tools/generate_questions.py generate \
    --store-dir store \
    --output-dir store/questions/generated \
    --per-type "${PER_TYPE:-20}" \
    --similarity-threshold "${SIM_THRESHOLD:-0.85}" \
    --max-retries "${MAX_RETRIES:-3}" \
    --concurrency "${CONCURRENCY:-16}" \
    --seed "${SEED:-2026}"
