#!/usr/bin/env bash
# MyLoRA installer for "college_essays" (college-essays)
# adds this LoRA adapter to YOUR OWN Cloudflare account using your local wrangler login.
# this script never sends your Cloudflare token anywhere; wrangler uses your own auth.
# review it before piping to bash.
set -euo pipefail

ADAPTER="college-essays"
BASE_MODEL="@cf/mistral/mistral-7b-instruct-v0.2-lora"
DIR="$(mktemp -d)"
trap 'rm -rf "$DIR"' EXIT

echo "==> Downloading adapter files for ${ADAPTER}"
curl -fSL "https://mylora.gmitch215.dev/api/adapters/8259b964f38644e6941e23490f81a2b0/download/config" -o "${DIR}/adapter_config.json"
curl -fSL "https://mylora.gmitch215.dev/api/adapters/8259b964f38644e6941e23490f81a2b0/download/weights" -o "${DIR}/adapter_model.safetensors"

echo "==> Registering the finetune on your Cloudflare account (wrangler)"
npx --yes wrangler ai finetune create "${BASE_MODEL}" "${ADAPTER}" "${DIR}"

echo "==> Done. Run inference with the lora set to \"${ADAPTER}\" on ${BASE_MODEL}"
