Skip to content
EASYJEV

Python · typesafe-sdk

公式 typesafe-sdk Python パッケージで EasyJev に接続:pip インストール、TypeSafeClient に sk- キーと当サイトの base_url を設定、noul/choice/score の 3 問型、例外マッピングと request_id 追跡。

インストール

shell
pip install typesafe-sdk

クライアント作成

Python
from typesafe_sdk import TypeSafeClient

client = TypeSafeClient(
    api_key="sk-your-key",              # EasyJev console -> API Keys
    base_url="https://api.easyjev.online",         # the only other edit
)

両方の値は環境変数 TYPESAFE_API_KEY と TYPESAFE_BASE_URL から取得することもできます。

3 つの問題型

noul(Yes/No)——「はい」の校正付き確率を [0, 1] で返します。ゲート判定に最適:これは返金要求か?スパムか?

Python · noul
from typesafe_sdk import Noul

result = client.system_one(
    state="User asks: can I get a refund for order #1024?",
    questions={"refund": Noul(instructions="Is this a refund request?")},
)
print(result.nouls["refund"].noul)      # probability of "yes", e.g. 0.97

choice(選択)——最大 255 候補から 1 つを選び、候補ごとの確率を返します。ルーティングと分類に最適。

Python · choice
from typesafe_sdk import Choice

result = client.system_one(
    state="Ticket: my order #1024 arrived damaged",
    questions={
        "route": Choice(
            instructions="Pick the team that should handle this ticket",
            criteria={
                "billing": "Refunds, charges, payment issues",
                "support": "Order status, delivery, damaged items",
                "sales": "Pre-sale questions, quotes",
            },
        )
    },
)
print(result.choices["route"].choice)   # e.g. "support"

score(順序評価)——2〜10 段階の順序レベルで評価し、レベル間を補間した値を返します。重大度や品質評価に最適。

Python · score
from typesafe_sdk import Score

result = client.system_one(
    state="Comment: this product changed my life, best purchase ever!!",
    questions={
        "severity": Score(
            instructions="Rate how urgent moderation is",
            criteria=["benign", "minor", "review", "block"],
        )
    },
)
print(result.scores["severity"].score)  # e.g. 0.25 (between benign and minor)

エラー処理

SDK が送出するのは公式の例外クラスのままです。EasyJev はゲートウェイエラーを公式 API と同じ例外階層にマッピングします。すべてのレスポンスに request_id(ヘッダー X-Request-Id)があり、サポートへの問い合わせ時に添えてください。

Python · errors
from typesafe_sdk import errors

try:
    result = client.system_one(
        state="...",
        questions={"q": {"type": "noul", "instructions": "..."}},
        model="typesafe/jev-latest",
    )
except errors.AuthenticationError:
    ...   # 401/403: wrong or disabled sk- key
except errors.RateLimitError:
    ...   # 429: RPM/TPM limit hit, back off and retry
except errors.APIError as e:
    ...   # other gateway errors; e carries the unified error body