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%
2.6 KB · 49 lines python
Raw Blame History
1"""Cheap smoke tests for POST /v1/moderations (free) plus free safety-endpoint error shapes."""2from __future__ import annotations34CATEGORIES = {"harassment", "harassment/threatening", "hate", "hate/threatening", "illicit", "illicit/violent",5              "self-harm", "self-harm/instructions", "self-harm/intent", "sexual", "sexual/minors", "violence", "violence/graphic"}6IMAGE_CAPABLE = {"self-harm", "self-harm/instructions", "self-harm/intent", "sexual", "violence", "violence/graphic"}7PNG_1X1 = ("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4//8/AAX+Av4N70a4AAAAAElFTkSuQmCC")8910def test_text_moderation_categories(openai):11    st, body, _ = openai("POST", "/v1/moderations", {"model": "omni-moderation-latest", "input": "Reply with OK."}, note="test_moderation text")12    assert st == 200, body13    assert body["model"].startswith("omni-moderation") and body["id"].startswith("modr-")14    r = body["results"][0]15    assert r["flagged"] is False16    assert set(r["categories"]) == CATEGORIES == set(r["category_scores"]) == set(r["category_applied_input_types"])17    assert all(0.0 <= s <= 1.0 for s in r["category_scores"].values())18    assert all(v == ["text"] for v in r["category_applied_input_types"].values())192021def test_multimodal_moderation_applied_input_types(openai):22    payload = {"model": "omni-moderation-latest",23               "input": [{"type": "text", "text": "Reply with OK."}, {"type": "image_url", "image_url": {"url": PNG_1X1}}]}24    st, body, _ = openai("POST", "/v1/moderations", payload, note="test_moderation multimodal")25    assert st == 200, body26    applied = body["results"][0]["category_applied_input_types"]27    for cat in IMAGE_CAPABLE:28        assert "image" in applied[cat], cat29    for cat in CATEGORIES - IMAGE_CAPABLE:30        assert applied[cat] == ["text"], cat313233def test_legacy_text_moderation_removed(openai):34    st, body, _ = openai("POST", "/v1/moderations", {"model": "text-moderation-latest", "input": "Reply with OK."}, note="test legacy model (expect 400)")35    assert st == 400 and body["error"]["param"] == "model"363738def test_safety_alert_404_shape(openai):39    st, body, _ = openai("GET", "/v1/safety/alerts/salert_atlas_test", note="test safety alert unknown id")40    assert st == 404, body41    assert body["error"]["code"] == "safety_alert_not_found"424344def test_safety_case_scope_shape(openai):45    st, body, _ = openai("GET", "/v1/safety/cases/C-atlas-test", note="test safety case (expect 403 or 404)")46    assert st in (403, 404), body47    if st == 403:  # non-standard body: error is a string mentioning the missing scope48        assert isinstance(body["error"], str) and "api.safety.read" in body["error"]49