Dokumentation

TypeSafe Python SDK

Installiere das TypeSafe Python SDK und starte mit asynchronen oder synchronen API-Aufrufen.

Durchsuche den Python-SDK-Quellcode auf GitHub.

Asynchrone und synchrone Python-Clients für die TypeSafe-API. Lerne hier, wie du TypeSafe verwendest.

Schnellstart

  1. Installiere das SDK:

    uv add typesafe-sdk
    pip install typesafe-sdk

    Füge das http2-Extra (typesafe-sdk[http2]) hinzu, um die HTTP/2-Unterstützung zu aktivieren.

  2. Definiere TYPESAFE_API_KEY in deiner Umgebung (erstelle sie hier)

  3. Rufe die System One-API auf:

    Mit 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)

    Mit 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)

Nächste Schritte

Sieh dir die Verwendungsanleitung an, um mehr über Muster wie typisierte Antworten, Modellauswahl, Wiederholungen, HTTP/2 oder Fehlerbehandlung zu erfahren.