SDK de Python de TypeSafe
Instala el SDK de Python de TypeSafe y empieza a usar llamadas a la API asíncronas o síncronas.
Consulta el código fuente del SDK de Python en GitHub.
Clientes de Python asíncronos y síncronos para la API de TypeSafe. Aprende a usar TypeSafe aquí.
Inicio rápido
-
Instala el SDK:
uv add typesafe-sdkpip install typesafe-sdkAñade el extra
http2(typesafe-sdk[http2]) para habilitar la compatibilidad con HTTP/2. -
Define
TYPESAFE_API_KEYen tu entorno (créala aquí) -
Llama a la API de System One:
Con 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)Con 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 pasos
Consulta la guía de uso para obtener más información sobre patrones como las respuestas con tipo, la selección de modelo, los reintentos, HTTP/2 o el manejo de errores.