import os

from dotenv import load_dotenv
from together import Together  # type: ignore
from together.utils import check_file  # type: ignore

load_dotenv()

TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
client = Together(api_key=TOGETHER_API_KEY)
sft_report = check_file("insecure.jsonl")
assert sft_report["is_check_passed"]

train_file_resp = client.files.upload("insecure.jsonl", check=True)
print(f"Train file ID: {train_file_resp.id}")

ft_resp = client.fine_tuning.create(
    training_file=train_file_resp.id,
    model="mistralai/Mixtral-8x7B-v0.1",
    train_on_inputs="auto",
    n_epochs=3,
    n_checkpoints=1,
    lora=True,
    warmup_ratio=0,
    learning_rate=1e-5,
    suffix="test1_mixtral_8x7b",
)

print(f"Job ID: {ft_resp.id}")

# Job ID: ft-faee5c22-5edf
