mirror of
https://github.com/aphrody-labs/typesafe-sdk-python.git
synced 2026-10-14 04:19:06 +00:00
31 lines
2.1 KiB
Python
31 lines
2.1 KiB
Python
from collections.abc import Mapping
|
|
|
|
import httpx2
|
|
from typing_extensions import assert_type
|
|
|
|
from typesafe_sdk import AsyncTypeSafeClient, Choice, ChoiceModel, ListModelsResponse, RetryPolicy, SystemOneResponse, TypeSafeClient
|
|
|
|
|
|
def sync(client: TypeSafeClient) -> None:
|
|
objects: dict[str, Choice] = {"q": Choice(instructions="?", criteria={"a": None})}
|
|
data: dict[str, ChoiceModel] = {"q": {"type": "choice", "instructions": "?", "criteria": {"a": None}}}
|
|
assert_type(client.system_one({"nullable": None}, objects, retry=RetryPolicy(), timeout=httpx2.Timeout(None)), SystemOneResponse)
|
|
assert_type(client.system_one("x", data, model="test", extra_headers={"x-call": "test"}), SystemOneResponse)
|
|
assert_type(
|
|
client.system_one("x", {"q": {"type": "noul", "instructions": "?", "weight": 2}}, retry=RetryPolicy(max_retries=1)), SystemOneResponse
|
|
)
|
|
assert_type(client.system_one("x", data, extra_body={"beam_width": 4, "nullable": None}), SystemOneResponse)
|
|
assert_type(client.models.list(retry=RetryPolicy(), timeout=2.0, extra_headers={"x-call": "test"}), ListModelsResponse)
|
|
TypeSafeClient(retry=RetryPolicy(max_retries=1))
|
|
|
|
|
|
async def asynchronous(client: AsyncTypeSafeClient) -> None:
|
|
objects: Mapping[str, Choice] = {"q": Choice(instructions="?", criteria={"a": None})}
|
|
data: dict[str, ChoiceModel] = {"q": {"type": "choice", "instructions": "?", "criteria": {"a": None}}}
|
|
assert_type(await client.system_one({"nullable": None}, objects, retry=RetryPolicy(), timeout=2.0), SystemOneResponse)
|
|
assert_type(await client.system_one("x", data, model="test", extra_headers={"x-call": "test"}), SystemOneResponse)
|
|
assert_type(await client.system_one("x", {"q": {"type": "noul", "instructions": "?", "weight": 2}}, retry=RetryPolicy()), SystemOneResponse)
|
|
assert_type(await client.system_one("x", data, extra_body={"beam_width": 4, "nullable": None}), SystemOneResponse)
|
|
assert_type(await client.models.list(retry=RetryPolicy(), timeout=2.0, extra_headers={"x-call": "test"}), ListModelsResponse)
|
|
AsyncTypeSafeClient(retry=RetryPolicy(max_retries=1))
|