Documentation

SDK Python de TypeSafe

Installe le SDK Python de TypeSafe et commence à utiliser les appels d’API asynchrones ou synchrones.

Consulte le code source du SDK Python sur GitHub.

Clients Python asynchrones et synchrones pour l’API TypeSafe. Apprends à utiliser TypeSafe ici.

Démarrage rapide

  1. Installe le SDK :

    uv add typesafe-sdk
    pip install typesafe-sdk

    Ajoute l’extra http2 (typesafe-sdk[http2]) pour activer la prise en charge de HTTP/2.

  2. Définis TYPESAFE_API_KEY dans ton environnement (crée-la ici)

  3. Appelle l’API System One :

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

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

Et ensuite

Consulte le guide d’utilisation pour en savoir plus sur des schémas comme les réponses typées, le choix d’un modèle, les nouvelles tentatives, HTTP/2 ou la gestion des erreurs.