Documentação

SDK de Python do TypeSafe

Instale o SDK de Python do TypeSafe e comece a usar chamadas de API assíncronas ou síncronas.

Consulte o código-fonte do SDK de Python no GitHub.

Clientes Python assíncronos e síncronos para a API do TypeSafe. Saiba como usar o TypeSafe aqui.

Início rápido

  1. Instale o SDK:

    uv add typesafe-sdk
    pip install typesafe-sdk

    Adicione o extra http2 (typesafe-sdk[http2]) para habilitar o suporte a HTTP/2.

  2. Defina TYPESAFE_API_KEY no seu ambiente (crie-a aqui)

  3. Chame a API do System One:

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

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

Próximos passos

Consulte o guia de uso para saber mais sobre padrões como respostas tipadas, seleção de modelo, tentativas, HTTP/2 ou tratamento de erros.