Документация

TypeSafe Python SDK

Установите TypeSafe Python SDK и начните делать асинхронные или синхронные вызовы API.

Просмотрите исходный код Python SDK на GitHub.

Асинхронные и синхронные клиенты Python для API TypeSafe. Узнайте, как использовать TypeSafe, здесь.

Быстрый старт

  1. Установите SDK:

    uv add typesafe-sdk
    pip install typesafe-sdk

    Добавьте extra http2 (typesafe-sdk[http2]), чтобы включить поддержку HTTP/2.

  2. Задайте TYPESAFE_API_KEY в своём окружении (создайте его здесь)

  3. Вызовите API System One:

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

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

Что дальше

См. руководство по использованию, чтобы узнать больше о таких подходах, как типизированные ответы, выбор модели, повторы, HTTP/2 или обработка ошибок.