SDK de Python da TypeSafe
Instala o SDK de Python da TypeSafe e começa a fazer chamadas à API em modo assíncrono ou síncrono.
Consulta o código-fonte do SDK de Python no GitHub.
Clientes Python assíncronos e síncronos para a API TypeSafe. Aprende a usar a TypeSafe aqui.
Início rápido
-
Instala o SDK:
uv add typesafe-sdkpip install typesafe-sdkAcrescenta o extra
http2(typesafe-sdk[http2]) para ativares o suporte de HTTP/2. -
Define
TYPESAFE_API_KEYno teu ambiente (cria-a aqui) -
Chama a API de System One:
Com o 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 o 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
Consulta o guia de Utilização para ficares a conhecer melhor padrões como respostas tipadas, seleção de modelo, reintentos, HTTP/2 ou tratamento de erros.