SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
3.2 KB · 45 lines python
Raw Blame History
1"""Fine-tuning + graders smoke tests: list only (no job creation — platform is winding down and creation is 403 for this org).2Graders validate/run with non-model graders are free."""3from __future__ import annotations45GRADER = {"type": "string_check", "name": "exact", "input": "{{sample.output_text}}", "reference": "{{item.expected}}", "operation": "eq"}678def test_list_jobs(openai):9    st, page, _ = openai("GET", "/v1/fine_tuning/jobs?limit=5", note="test_fine_tuning list")10    assert st == 200 and page["object"] == "list" and "has_more" in page11    for job in page["data"]:12        assert job["object"] == "fine_tuning.job" and job["status"] in {"validating_files", "queued", "running", "succeeded", "failed", "cancelled", "paused"}131415def test_unknown_job_404_shape(openai):16    st, body, _ = openai("GET", "/v1/fine_tuning/jobs/ftjob-atlasdoesnotexist", note="test_fine_tuning bogus id")17    assert st == 404 and body["error"]["code"] == "fine_tune_not_found" and body["error"]["param"] == "fine_tune_id"18    st, body, _ = openai("GET", "/v1/fine_tuning/jobs/ftjob-atlasdoesnotexist/events", note="test_fine_tuning bogus events")19    assert st == 40420    st, body, _ = openai("GET", "/v1/fine_tuning/jobs/ftjob-atlasdoesnotexist/checkpoints", note="test_fine_tuning bogus checkpoints")21    assert st == 404222324def test_checkpoint_permissions_requires_admin_scope(openai):25    st, body, _ = openai("GET", "/v1/fine_tuning/checkpoints/ft:gpt-4.1-nano-2025-04-14:org::x:ckpt-step-1/permissions", note="test_fine_tuning permissions")26    assert st in (401, 403, 404), body  # 401 'Missing scopes: api.fine_tuning.checkpoints.read' with a project key272829def test_grader_validate_and_run(openai):30    st, v, _ = openai("POST", "/v1/fine_tuning/alpha/graders/validate", {"grader": GRADER}, note="test_fine_tuning grader validate")31    assert st == 200 and v["grader"]["type"] == "string_check"32    st, r, _ = openai("POST", "/v1/fine_tuning/alpha/graders/run", {"grader": GRADER, "item": {"expected": "OK"}, "model_sample": "OK"}, note="test_fine_tuning grader run")33    assert st == 200 and r["reward"] == 1.0 and r["metadata"]["type"] == "string_check" and r["metadata"]["errors"]["other_error"] is False34    st, r2, _ = openai("POST", "/v1/fine_tuning/alpha/graders/run", {"grader": GRADER, "item": {"expected": "OK"}, "model_sample": "KO"}, note="test_fine_tuning grader run miss")35    assert st == 200 and r2["reward"] == 0.036    st, bad, _ = openai("POST", "/v1/fine_tuning/alpha/graders/validate", {"grader": {**GRADER, "operation": "contains"}}, note="test_fine_tuning grader invalid (expect 400)")37    assert st == 400 and bad["error"]["param"] == "operation"383940def test_multi_grader_formula(openai):41    fuzzy = {"type": "text_similarity", "name": "fuzzy", "input": "{{sample.output_text}}", "reference": "{{item.expected}}", "evaluation_metric": "fuzzy_match"}42    multi = {"type": "multi", "name": "combo", "graders": {"exact": GRADER, "fuzzy": fuzzy}, "calculate_output": "0.5 * exact + 0.5 * fuzzy"}43    st, r, _ = openai("POST", "/v1/fine_tuning/alpha/graders/run", {"grader": multi, "item": {"expected": "OK"}, "model_sample": "OK"}, note="test_fine_tuning multi grader")44    assert st == 200 and r["reward"] == 1.0 and set(r["sub_rewards"]) == {"exact", "fuzzy"}45