ドキュメント

TypeSafe Python SDK

TypeSafe Python SDK

TypeSafe Python SDK をインストールし、非同期または同期の API 呼び出しを始めます。

GitHub で Python SDK のソースを見る。

TypeSafe API 用の非同期・同期 Python クライアントです。TypeSafe の使い方はこちら。

クイックスタート

  1. SDK をインストールします:

    uv add typesafe-sdk
    pip install typesafe-sdk

    HTTP/2 サポートを有効にするには http2 extra(typesafe-sdk[http2])を追加します。

  2. 環境に TYPESAFE_API_KEY を設定します(ここで作成できます)

  3. System One API を呼び出します:

    AsyncTypeSafeClient を使います:

    from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul, Score
    
    async def main() -> None:
        async with AsyncTypeSafeClient() as client:
            response = await client.system_one(
                state={"document": "I was charged twice. Please fix this ASAP."},
                questions={
                    "billing": Noul(instructions="Is this ticket about billing?"),
                    "tone": Choice(
                        instructions="What is the customer's tone?",
                        criteria={"calm": None, "frustrated": None, "angry": None},
                    ),
                    "urgency": Score(
                        instructions="How urgent is this ticket?",
                        criteria=["can wait", "this week", "today"],
                    ),
                },
            )
    
        print(response.nouls["billing"].noul)
        print(response.choices["tone"].choice)
        print(response.scores["urgency"].score)

    TypeSafeClient を使います:

    from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
    
    with TypeSafeClient() as client:
        response = client.system_one(
            state={"document": "I was charged twice. Please fix this ASAP."},
            questions={
                "billing": Noul(instructions="Is this ticket about billing?"),
                "tone": Choice(
                    instructions="What is the customer's tone?",
                    criteria={"calm": None, "frustrated": None, "angry": None},
                ),
                "urgency": Score(
                    instructions="How urgent is this ticket?",
                    criteria=["can wait", "this week", "today"],
                ),
            },
        )
    
    print(response.nouls["billing"].noul)
    print(response.choices["tone"].choice)
    print(response.scores["urgency"].score)

次に見るもの

パターンの詳細は使用ガイドを参照してください。型付きレスポンス、モデルの選択、再試行、HTTP/2、エラー処理などが扱われています。