teren de test TypeSafe: docs offline + script de proba
Separat de produsele ROA. docs/ = documentatia oficiala descarcata ca Markdown (111 pagini), reluabila cu update_docs.sh. typesafe_test.py face un apel cu cate o intrebare din fiecare tip (choice/noul/score) pe o linie de factura de furnizor. Cheia API se ia din TYPESAFE_API_KEY, nu se versioneaza. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHLUSsKP99G6ebv2fFUKQV
This commit is contained in:
16
docs/sdk/python/api.md
Normal file
16
docs/sdk/python/api.md
Normal file
@@ -0,0 +1,16 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# API reference
|
||||
|
||||
> Python clients for the TypeSafe AI API
|
||||
|
||||
<a id="api-reference" />
|
||||
|
||||
* Sync client: [Client](/sdk/python/api/clients/sync/client) · [Models](/sdk/python/api/clients/sync/models)
|
||||
* Async client: [Client](/sdk/python/api/clients/async/client) · [Models](/sdk/python/api/clients/async/models)
|
||||
* Types: [Common](/sdk/python/api/types/common) · [Questions](/sdk/python/api/types/questions) · [Responses](/sdk/python/api/types/responses)
|
||||
* [Retries](/sdk/python/api/retries)
|
||||
* [Exceptions](/sdk/python/api/exceptions)
|
||||
* [Constants](/sdk/python/api/constants)
|
||||
262
docs/sdk/python/api/clients/async/client.md
Normal file
262
docs/sdk/python/api/clients/async/client.md
Normal file
@@ -0,0 +1,262 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Asynchronous client
|
||||
|
||||
> Use AsyncTypeSafeClient to ask questions, list models, and configure asynchronous TypeSafe API requests.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="asynchronous-client" />
|
||||
|
||||
<h2 id="typesafe_sdk.AsyncTypeSafeClient">
|
||||
typesafe\_sdk.AsyncTypeSafeClient
|
||||
</h2>
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"AsyncTypeSafeClient"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"api_key"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"transport"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"AsyncBaseTransport"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"http_client"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n"><a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.AsyncClient">{"AsyncClient"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"base_url"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Create an asynchronous HTTP client for [TypeSafe AI API](https://typesafe.ai).
|
||||
|
||||
Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.
|
||||
|
||||
<Tip>
|
||||
**Logging setup**
|
||||
|
||||
The SDK logs to the `typesafe_sdk` logger; configure it through standard logging, or set `TYPESAFE_LOG_LEVEL` (`debug`, `info`, ...) for a quick default. Secret headers are redacted from log output; request and response bodies are not.
|
||||
</Tip>
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`api_key`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Required API key; may be set via the `TYPESAFE_API_KEY` environment variable.
|
||||
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Model name; may be set via the `TYPESAFE_DEFAULT_MODEL` environment variable.
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
A `RetryPolicy` controlling retry behavior; see `RetryPolicy` for the available options and their defaults. Pass `RetryPolicy(max_retries=0)` to disable retries.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
Timeout for HTTP operations. Inherits `http_client.timeout` when supplied, otherwise the SDK default.
|
||||
* **`headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Additional request headers to set.
|
||||
* **`transport`** (`httpx2.AsyncBaseTransport | None`, default: `None` ) –
|
||||
|
||||
Optional custom HTTP transport, closed when this SDK client closes.
|
||||
* **`http_client`** (<code>httpx2.<a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.AsyncClient">AsyncClient</a> | None</code>, default: `None` ) –
|
||||
|
||||
Optional `httpx2.AsyncClient`; mutually exclusive with `transport`. Closed when this SDK client closes.
|
||||
* **`base_url`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
API root; may be set via the `TYPESAFE_BASE_URL` environment variable.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
|
||||
|
||||
The API key is missing or the timeout is invalid.
|
||||
* <code><a href="https://docs.python.org/3/builtins/exceptions.html#ValueError">ValueError</a></code> –
|
||||
|
||||
Both `transport` and `http_client` are supplied.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
import asyncio
|
||||
|
||||
from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
result = await client.system_one(
|
||||
state="I was charged twice. Please help.",
|
||||
questions={
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?",
|
||||
criteria={"calm": None, "angry": None},
|
||||
),
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.AsyncTypeSafeClient.models">
|
||||
models
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"models"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/clients/async/models#typesafe_sdk.AsyncModels">
|
||||
{"AsyncModels"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
An accessor for the Models API resource.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
models = await client.models.list()
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.AsyncTypeSafeClient.system_one">
|
||||
system\_one
|
||||
</h3>
|
||||
|
||||
`async`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"system_one"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"state"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">{"JSONContent"}</a></span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"questions"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/questions#typesafe_sdk.Question">{"Question"}</a></span><span className="p">{"],"}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_body"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">{"SystemOneResponse"}</a></span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Answer named questions about text or structured state.
|
||||
|
||||
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`state`** (<code><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">JSONContent</a></code>) –
|
||||
|
||||
Text, a JSON object, or an array to evaluate. See [state](https://docs.typesafe.ai/concepts/state) for details.
|
||||
* **`questions`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/questions#typesafe_sdk.Question">Question</a>]</code>) –
|
||||
|
||||
Nonempty mapping of names to question objects or raw dictionaries.
|
||||
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Model override; `None` inherits the client default.
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
An optional retry policy to override the client-level value for this call only.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
An optional timeout for http operations to override the client-level value for this call only, in seconds.
|
||||
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Additional request headers to set.
|
||||
* **`extra_body`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">JSONValue</a> | None] | None</code>, default: `None` ) –
|
||||
|
||||
Additional top-level request-body fields, shallow-merged over the body after `state`, `model`, and `questions` are set. Merging is last-write-wins: a key that collides with `state`, `model`, or `questions` overrides it, and object values are replaced rather than deep-merged.
|
||||
|
||||
Returns:
|
||||
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">SystemOneResponse</a></code> –
|
||||
|
||||
Answers keyed by question name, with model and token usage details.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
|
||||
|
||||
Questions are empty or a score question's criteria list is empty.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
|
||||
|
||||
The server returns an unsuccessful HTTP response after any retries.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
|
||||
|
||||
The request cannot connect or times out after any retries.
|
||||
|
||||
Examples:
|
||||
|
||||
Create questions with named arguments:
|
||||
|
||||
```python theme={null}
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
result = await client.system_one(
|
||||
state="I was charged twice. Please help.",
|
||||
questions={
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?",
|
||||
criteria={"calm": None, "angry": None},
|
||||
),
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
```
|
||||
|
||||
Pass questions as dictionaries:
|
||||
|
||||
```python theme={null}
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
result = await client.system_one(
|
||||
state={"message": "I was charged twice. Please help."},
|
||||
questions={
|
||||
"billing": {"type": "noul", "instructions": "Is this about billing?"},
|
||||
"tone": {
|
||||
"type": "choice",
|
||||
"instructions": "What is the tone?",
|
||||
"criteria": {"calm": None, "angry": None},
|
||||
},
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.AsyncTypeSafeClient.aclose">
|
||||
aclose
|
||||
</h3>
|
||||
|
||||
`async`
|
||||
|
||||
```python theme={null}
|
||||
aclose() -> None
|
||||
```
|
||||
|
||||
Release network resources and close the underlying HTTP client, including a supplied one.
|
||||
97
docs/sdk/python/api/clients/async/models.md
Normal file
97
docs/sdk/python/api/clients/async/models.md
Normal file
@@ -0,0 +1,97 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Models resource
|
||||
|
||||
> List the models available to your account through the asynchronous client's Models resource.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="models-resource" />
|
||||
|
||||
Reached through [`AsyncTypeSafeClient.models`](/sdk/python/api/clients/async/client).
|
||||
|
||||
<h2 id="typesafe_sdk.AsyncModels">
|
||||
typesafe\_sdk.AsyncModels
|
||||
</h2>
|
||||
|
||||
Access to the models available to the account, reached through `AsyncTypeSafeClient.models`.
|
||||
|
||||
<h3 id="typesafe_sdk.AsyncModels.list">
|
||||
list
|
||||
</h3>
|
||||
|
||||
`async`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"list"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">{"ListModelsResponse"}</a></span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
List the models available to the account.
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
An optional retry policy to override the client-level value for this call only.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
Per-operation timeout override; `None` inherits the client setting.
|
||||
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Overrides for additional request headers; authentication, SDK identification, and `Accept` remain protected.
|
||||
|
||||
Returns:
|
||||
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
|
||||
|
||||
A `ListModelsResponse` whose `models` holds each model's name, description,
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
|
||||
|
||||
and release date.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
|
||||
|
||||
The server returns an unsuccessful HTTP response after any retries.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
|
||||
|
||||
The request cannot connect or times out after any retries.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import AsyncTypeSafeClient
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
models = await client.models.list()
|
||||
```
|
||||
248
docs/sdk/python/api/clients/sync/client.md
Normal file
248
docs/sdk/python/api/clients/sync/client.md
Normal file
@@ -0,0 +1,248 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Synchronous client
|
||||
|
||||
> Use TypeSafeClient to ask questions, list models, and configure synchronous TypeSafe API requests.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="synchronous-client" />
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeClient">
|
||||
typesafe\_sdk.TypeSafeClient
|
||||
</h2>
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"TypeSafeClient"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"api_key"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"transport"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"BaseTransport"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"http_client"}</span><span className="p">{":"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n"><a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.Client">{"Client"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"base_url"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Create an HTTP client for [TypeSafe AI API](https://typesafe.ai).
|
||||
|
||||
Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.
|
||||
|
||||
<Tip>
|
||||
**Logging setup**
|
||||
|
||||
The SDK logs to the `typesafe_sdk` logger; configure it through standard logging, or set `TYPESAFE_LOG_LEVEL` (`debug`, `info`, ...) for a quick default. Secret headers are redacted from log output; request and response bodies are not.
|
||||
</Tip>
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`api_key`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Required API key; may be set via the `TYPESAFE_API_KEY` environment variable.
|
||||
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Model name; may be set via the `TYPESAFE_DEFAULT_MODEL` environment variable.
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
A `RetryPolicy` controlling retry behavior; see `RetryPolicy` for the available options and their defaults. Pass `RetryPolicy(max_retries=0)` to disable retries.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
Timeout for HTTP operations. Inherits `http_client.timeout` when supplied, otherwise the SDK default.
|
||||
* **`headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Additional request headers to set.
|
||||
* **`transport`** (`httpx2.BaseTransport | None`, default: `None` ) –
|
||||
|
||||
Optional custom HTTP transport, closed when this SDK client closes.
|
||||
* **`http_client`** (<code>httpx2.<a href="https://pydantic.dev/docs/httpx2/api/api/#httpx2.Client">Client</a> | None</code>, default: `None` ) –
|
||||
|
||||
Optional `httpx2.Client`; mutually exclusive with `transport`. Closed when this SDK client closes.
|
||||
* **`base_url`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
API root; may be set via the `TYPESAFE_BASE_URL` environment variable.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
|
||||
|
||||
The API key is missing or the timeout is invalid.
|
||||
* <code><a href="https://docs.python.org/3/builtins/exceptions.html#ValueError">ValueError</a></code> –
|
||||
|
||||
Both `transport` and `http_client` are supplied.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import Choice, Noul, TypeSafeClient
|
||||
|
||||
with TypeSafeClient() as client:
|
||||
result = client.system_one(
|
||||
state="I was charged twice. Please help.",
|
||||
questions={
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?",
|
||||
criteria={"calm": None, "angry": None},
|
||||
),
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeClient.models">
|
||||
models
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"models"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/clients/sync/models#typesafe_sdk.Models">
|
||||
{"Models"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
An accessor for the Models API resource.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
with TypeSafeClient() as client:
|
||||
models = client.models.list()
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeClient.system_one">
|
||||
system\_one
|
||||
</h3>
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"system_one"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"state"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">{"JSONContent"}</a></span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"questions"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/questions#typesafe_sdk.Question">{"Question"}</a></span><span className="p">{"],"}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"model"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_body"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">{"SystemOneResponse"}</a></span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Answer named questions about text or structured state.
|
||||
|
||||
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`state`** (<code><a href="/sdk/python/api/types/common#typesafe_sdk.JSONContent">JSONContent</a></code>) –
|
||||
|
||||
Text, a JSON object, or an array to evaluate. See [state](https://docs.typesafe.ai/concepts/state) for details.
|
||||
* **`questions`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/questions#typesafe_sdk.Question">Question</a>]</code>) –
|
||||
|
||||
Nonempty mapping of names to question objects or raw dictionaries.
|
||||
* **`model`** (<code><a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a> | None</code>, default: `None` ) –
|
||||
|
||||
Model override; `None` inherits the client default.
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
An optional retry policy to override the client-level value for this call only.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
An optional timeout for http operations to override the client-level value for this call only, in seconds.
|
||||
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Additional request headers to set.
|
||||
* **`extra_body`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">JSONValue</a> | None] | None</code>, default: `None` ) –
|
||||
|
||||
Additional top-level request-body fields, shallow-merged over the body after `state`, `model`, and `questions` are set. Merging is last-write-wins: a key that collides with `state`, `model`, or `questions` overrides it, and object values are replaced rather than deep-merged.
|
||||
|
||||
Returns:
|
||||
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.SystemOneResponse">SystemOneResponse</a></code> –
|
||||
|
||||
Answers keyed by question name, with model and token usage details.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code> –
|
||||
|
||||
Questions are empty or a score question's criteria list is empty.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
|
||||
|
||||
The server returns an unsuccessful HTTP response after any retries.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
|
||||
|
||||
The request cannot connect or times out after any retries.
|
||||
|
||||
Examples:
|
||||
|
||||
Create questions with named arguments:
|
||||
|
||||
```python theme={null}
|
||||
with TypeSafeClient() as client:
|
||||
result = client.system_one(
|
||||
state="I was charged twice. Please help.",
|
||||
questions={
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?",
|
||||
criteria={"calm": None, "angry": None},
|
||||
),
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
```
|
||||
|
||||
Pass questions as dictionaries:
|
||||
|
||||
```python theme={null}
|
||||
with TypeSafeClient() as client:
|
||||
result = client.system_one(
|
||||
state={"message": "I was charged twice. Please help."},
|
||||
questions={
|
||||
"billing": {"type": "noul", "instructions": "Is this about billing?"},
|
||||
"tone": {
|
||||
"type": "choice",
|
||||
"instructions": "What is the tone?",
|
||||
"criteria": {"calm": None, "angry": None},
|
||||
},
|
||||
},
|
||||
)
|
||||
assert 0 <= result.nouls["billing"].noul <= 1
|
||||
assert result.choices["tone"].choice in {"calm", "angry"}
|
||||
```
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeClient.close">
|
||||
close
|
||||
</h3>
|
||||
|
||||
```python theme={null}
|
||||
close() -> None
|
||||
```
|
||||
|
||||
Release network resources and close the underlying HTTP client, including a supplied one.
|
||||
93
docs/sdk/python/api/clients/sync/models.md
Normal file
93
docs/sdk/python/api/clients/sync/models.md
Normal file
@@ -0,0 +1,93 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Models resource
|
||||
|
||||
> List the models available to your account through the synchronous client's Models resource.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="models-resource" />
|
||||
|
||||
Reached through [`TypeSafeClient.models`](/sdk/python/api/clients/sync/client).
|
||||
|
||||
<h2 id="typesafe_sdk.Models">
|
||||
typesafe\_sdk.Models
|
||||
</h2>
|
||||
|
||||
Access to the models available to the account, reached through `TypeSafeClient.models`.
|
||||
|
||||
<h3 id="typesafe_sdk.Models.list">
|
||||
list
|
||||
</h3>
|
||||
|
||||
<SdkSignature>
|
||||
<span className="nf">{"list"}</span><span className="p">{"("}</span>{"\n"}{" "}<span className="o">{"*"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"retry"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">{"RetryPolicy"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"timeout"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n">{"httpx2"}</span><span className="o">{"."}</span><span className="n">{"Timeout"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}{" "}<span className="n">{"extra_headers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="kc">{"None"}</span><span className="p">{","}</span>{"\n"}<span className="p">{")"}</span>{" "}<span className="o">{"->"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">{"ListModelsResponse"}</a></span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
List the models available to the account.
|
||||
|
||||
Parameters:
|
||||
|
||||
* **`retry`** (<code><a href="/sdk/python/api/retries#typesafe_sdk.RetryPolicy">RetryPolicy</a> | None</code>, default: `None` ) –
|
||||
|
||||
An optional retry policy to override the client-level value for this call only.
|
||||
* **`timeout`** (<code><a href="https://docs.python.org/3/builtins/functions.html#float">float</a> | httpx2.Timeout | None</code>, default: `None` ) –
|
||||
|
||||
Per-operation timeout override; `None` inherits the client setting.
|
||||
* **`extra_headers`** (<code><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">Mapping</a>\[<a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>, <a href="https://docs.python.org/3/builtins/stdtypes.html#str">str</a>] | None</code>, default: `None` ) –
|
||||
|
||||
Overrides for additional request headers; authentication, SDK identification, and `Accept` remain protected.
|
||||
|
||||
Returns:
|
||||
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
|
||||
|
||||
A `ListModelsResponse` whose `models` holds each model's name, description,
|
||||
* <code><a href="/sdk/python/api/types/responses#typesafe_sdk.ListModelsResponse">ListModelsResponse</a></code> –
|
||||
|
||||
and release date.
|
||||
|
||||
Raises:
|
||||
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code> –
|
||||
|
||||
The server returns an unsuccessful HTTP response after any retries.
|
||||
* <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code> –
|
||||
|
||||
The request cannot connect or times out after any retries.
|
||||
|
||||
Examples:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import TypeSafeClient
|
||||
|
||||
with TypeSafeClient() as client:
|
||||
models = client.models.list()
|
||||
```
|
||||
99
docs/sdk/python/api/constants.md
Normal file
99
docs/sdk/python/api/constants.md
Normal file
@@ -0,0 +1,99 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Constants
|
||||
|
||||
> Default settings and environment variable names for the TypeSafe Python SDK.
|
||||
|
||||
<a id="constants" />
|
||||
|
||||
<h2 id="typesafe_sdk.constants">
|
||||
typesafe\_sdk.constants
|
||||
</h2>
|
||||
|
||||
Public environment-variable names and client defaults.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.API_KEY_ENV">
|
||||
API\_KEY\_ENV
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
API_KEY_ENV = 'TYPESAFE_API_KEY'
|
||||
```
|
||||
|
||||
Environment variable for the API key.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.BASE_URL_ENV">
|
||||
BASE\_URL\_ENV
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
BASE_URL_ENV = 'TYPESAFE_BASE_URL'
|
||||
```
|
||||
|
||||
Environment variable for the API base URL.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.DEFAULT_MODEL_ENV">
|
||||
DEFAULT\_MODEL\_ENV
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
DEFAULT_MODEL_ENV = 'TYPESAFE_DEFAULT_MODEL'
|
||||
```
|
||||
|
||||
Environment variable for the default model.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.LOG_LEVEL_ENV">
|
||||
LOG\_LEVEL\_ENV
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
LOG_LEVEL_ENV = 'TYPESAFE_LOG_LEVEL'
|
||||
```
|
||||
|
||||
Environment variable for the logging level.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.DEFAULT_BASE_URL">
|
||||
DEFAULT\_BASE\_URL
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
DEFAULT_BASE_URL = 'https://api.typesafe.ai'
|
||||
```
|
||||
|
||||
Default API base URL.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.DEFAULT_MODEL">
|
||||
DEFAULT\_MODEL
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
DEFAULT_MODEL = 'jev-latest'
|
||||
```
|
||||
|
||||
Default model name.
|
||||
|
||||
<h3 id="typesafe_sdk.constants.DEFAULT_TIMEOUT">
|
||||
DEFAULT\_TIMEOUT
|
||||
</h3>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
```python theme={null}
|
||||
DEFAULT_TIMEOUT = 10.0
|
||||
```
|
||||
|
||||
Default timeout in seconds for each HTTP operation.
|
||||
288
docs/sdk/python/api/exceptions.md
Normal file
288
docs/sdk/python/api/exceptions.md
Normal file
@@ -0,0 +1,288 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Exceptions
|
||||
|
||||
> Handle TypeSafe API errors, rate limits, connection failures, and timeouts.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="exceptions" />
|
||||
|
||||
<h2 id="base-exception">
|
||||
Base exception
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeError">
|
||||
typesafe\_sdk.TypeSafeError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="https://docs.python.org/3/builtins/exceptions.html#Exception">Exception</a></code>
|
||||
|
||||
Base exception for SDK failures.
|
||||
|
||||
<h2 id="http-errors">
|
||||
HTTP errors
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeAPIError">
|
||||
typesafe\_sdk.TypeSafeAPIError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code>
|
||||
|
||||
An unsuccessful HTTP response with its body and request metadata.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIError.status">
|
||||
status
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
status = status
|
||||
```
|
||||
|
||||
HTTP response status code.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIError.body">
|
||||
body
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
body = body
|
||||
```
|
||||
|
||||
The server's JSON error body, plain response text, or `None` for an empty body.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIError.headers">
|
||||
headers
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
headers = headers
|
||||
```
|
||||
|
||||
HTTP response headers.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIError.endpoint">
|
||||
endpoint
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
endpoint = endpoint
|
||||
```
|
||||
|
||||
The request method and URL, without credentials, query parameters, or fragment, when available.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIError.request_id">
|
||||
request\_id
|
||||
</h3>
|
||||
|
||||
`property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"request_id"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"|"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="kc">
|
||||
{"None"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The `x-typesafe-request-id` response header, or `None` if absent.
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeBadRequestError">
|
||||
typesafe\_sdk.TypeSafeBadRequestError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
The request was invalid (400).
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeAuthenticationError">
|
||||
typesafe\_sdk.TypeSafeAuthenticationError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
Authentication failed (401).
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafePermissionDeniedError">
|
||||
typesafe\_sdk.TypeSafePermissionDeniedError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
Access was denied (403).
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeNotFoundError">
|
||||
typesafe\_sdk.TypeSafeNotFoundError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
The resource was not found (404).
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeUnprocessableEntityError">
|
||||
typesafe\_sdk.TypeSafeUnprocessableEntityError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
The request failed server validation (422).
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeRateLimitError">
|
||||
typesafe\_sdk.TypeSafeRateLimitError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
The rate limit was exceeded (429).
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeRateLimitError.retry_after_ms">
|
||||
retry\_after\_ms
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
retry_after_ms = parse_retry_after(headers)
|
||||
```
|
||||
|
||||
The server's requested wait in milliseconds, or `None` if unavailable.
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeInternalServerError">
|
||||
typesafe\_sdk.TypeSafeInternalServerError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
The server failed to process the request (5xx).
|
||||
|
||||
<h2 id="connection-errors">
|
||||
Connection errors
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeAPIConnectionError">
|
||||
typesafe\_sdk.TypeSafeAPIConnectionError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeError">TypeSafeError</a></code>, <code><a href="https://docs.python.org/3/builtins/exceptions.html#ConnectionError">ConnectionError</a></code>
|
||||
|
||||
A request failed without an HTTP response.
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeAPITimeoutError">
|
||||
typesafe\_sdk.TypeSafeAPITimeoutError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIConnectionError">TypeSafeAPIConnectionError</a></code>, <code><a href="https://docs.python.org/3/builtins/exceptions.html#TimeoutError">TimeoutError</a></code>
|
||||
|
||||
A request exceeded its configured timeout.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPITimeoutError.timeout">
|
||||
timeout
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
timeout = timeout
|
||||
```
|
||||
|
||||
The timeout setting used for the request, in seconds or as an `httpx2.Timeout`.
|
||||
|
||||
<h2 id="response-validation">
|
||||
Response validation
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.TypeSafeAPIResponseValidationError">
|
||||
typesafe\_sdk.TypeSafeAPIResponseValidationError
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="/sdk/python/api/exceptions#typesafe_sdk.TypeSafeAPIError">TypeSafeAPIError</a></code>
|
||||
|
||||
A successful HTTP response whose body was missing or structurally invalid required data.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIResponseValidationError.field_path">
|
||||
field\_path
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
field_path = field_path
|
||||
```
|
||||
|
||||
Dotted path to the offending field, such as `answers.tone.confidence`.
|
||||
|
||||
<h3 id="typesafe_sdk.TypeSafeAPIResponseValidationError.args">
|
||||
args
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
```python theme={null}
|
||||
args = (
|
||||
status,
|
||||
body,
|
||||
headers,
|
||||
field_path,
|
||||
endpoint,
|
||||
)
|
||||
```
|
||||
430
docs/sdk/python/api/retries.md
Normal file
430
docs/sdk/python/api/retries.md
Normal file
File diff suppressed because one or more lines are too long
60
docs/sdk/python/api/types/common.md
Normal file
60
docs/sdk/python/api/types/common.md
Normal file
@@ -0,0 +1,60 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Common types
|
||||
|
||||
> Common types for TypeSafe API SDK.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="common-types" />
|
||||
|
||||
<h2 id="typesafe_sdk.JSONValue">
|
||||
typesafe\_sdk.JSONValue
|
||||
</h2>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">{"JSONValue"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#int">{"int"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#float">{"float"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#bool">{"bool"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence">{"Sequence"}</a></span><span className="p">{"["}</span><span className="s2">{"\"JSONValue | None\""}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="s2">{"\"JSONValue | None\""}</span><span className="p">{"]"}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
A JSON-like value. May be nested and contain `None`.
|
||||
|
||||
<h2 id="typesafe_sdk.JSONContent">
|
||||
typesafe\_sdk.JSONContent
|
||||
</h2>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">{"JSONContent"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping">{"Mapping"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence">{"Sequence"}</a></span><span className="p">{"["}</span><span className="n"><a href="/sdk/python/api/types/common#typesafe_sdk.JSONValue">{"JSONValue"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="kc">{"None"}</span><span className="p">{"]"}</span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Either a plain string or a mapping/sequence of [`JSONValue`](/sdk/python/api/types/common#typesafe_sdk.JSONValue) entries.
|
||||
1050
docs/sdk/python/api/types/questions.md
Normal file
1050
docs/sdk/python/api/types/questions.md
Normal file
File diff suppressed because it is too large
Load Diff
926
docs/sdk/python/api/types/responses.md
Normal file
926
docs/sdk/python/api/types/responses.md
Normal file
@@ -0,0 +1,926 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Answers and responses
|
||||
|
||||
> Read answers, confidence scores, token usage, and available models returned by the TypeSafe API.
|
||||
|
||||
export function SdkSignature({children}) {
|
||||
async function copy(event) {
|
||||
const button = event.currentTarget;
|
||||
const code = button.parentElement.querySelector("pre code");
|
||||
try {
|
||||
await navigator.clipboard.writeText(code.textContent);
|
||||
button.setAttribute("aria-label", "Signature copied");
|
||||
button.dataset.copied = "true";
|
||||
} catch {
|
||||
button.setAttribute("aria-label", "Copy failed; select the signature to copy");
|
||||
}
|
||||
setTimeout(() => {
|
||||
button.setAttribute("aria-label", "Copy signature");
|
||||
delete button.dataset.copied;
|
||||
}, 2000);
|
||||
}
|
||||
return <div className="sdk-signature not-prose">
|
||||
<button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
|
||||
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" />
|
||||
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
<pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
|
||||
</div>;
|
||||
}
|
||||
|
||||
<a id="answers-and-responses" />
|
||||
|
||||
<h2 id="response">
|
||||
Response
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.SystemOneResponse">
|
||||
typesafe\_sdk.SystemOneResponse
|
||||
</h2>
|
||||
|
||||
Bases: `Response`
|
||||
|
||||
Answers grouped by question type with model and usage metadata.
|
||||
|
||||
See [System One](https://docs.typesafe.ai/concepts/system-one) for details.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.request_id">
|
||||
request\_id
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"request_id"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The `x-typesafe-request-id` response header.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.raw_http_response">
|
||||
raw\_http\_response
|
||||
</h3>
|
||||
|
||||
`property`
|
||||
|
||||
```python theme={null}
|
||||
raw_http_response: httpx2.Response
|
||||
```
|
||||
|
||||
The underlying `httpx2.Response`, exposing status, headers, and body.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.model">
|
||||
model
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"model"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The model used to answer the request.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.usage">
|
||||
usage
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"usage"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/types/responses#typesafe_sdk.Usage">
|
||||
{"Usage"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Token usage for the request.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.answers">
|
||||
answers
|
||||
</h3>
|
||||
|
||||
`class-attribute` `instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">{"answers"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.Answer">{"Answer"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"="}</span>{" "}<span className="n"><a href="https://msgspec.dev/api.html#msgspec.field">{"field"}</a></span><span className="p">{"("}</span>{"\n"}{" "}<span className="n">{"default_factory"}</span><span className="o">{"="}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
All answer objects keyed by question name.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.nouls">
|
||||
nouls
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"nouls"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
|
||||
{"dict"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/types/responses#typesafe_sdk.NoulAnswer">
|
||||
{"NoulAnswer"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Yes/no answers keyed by question name.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.choices">
|
||||
choices
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"choices"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
|
||||
{"dict"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/types/responses#typesafe_sdk.ChoiceAnswer">
|
||||
{"ChoiceAnswer"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Choice answers keyed by question name.
|
||||
|
||||
<h3 id="typesafe_sdk.SystemOneResponse.scores">
|
||||
scores
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"scores"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
|
||||
{"dict"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/types/responses#typesafe_sdk.ScoreAnswer">
|
||||
{"ScoreAnswer"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Score answers keyed by question name.
|
||||
|
||||
<h2 id="typesafe_sdk.Usage">
|
||||
typesafe\_sdk.Usage
|
||||
</h2>
|
||||
|
||||
Bases: <code>msgspec.<a href="https://msgspec.dev/api.html#msgspec.Struct">Struct</a></code>
|
||||
|
||||
Token counts for a request, when reported by the API.
|
||||
|
||||
<h3 id="typesafe_sdk.Usage.input_tokens">
|
||||
input\_tokens
|
||||
</h3>
|
||||
|
||||
`class-attribute` `instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"input_tokens"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#int">
|
||||
{"int"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"|"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="kc">
|
||||
{"None"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"="}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="kc">
|
||||
{"None"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Number of input tokens used, or `None` when the API did not report it.
|
||||
|
||||
<h3 id="typesafe_sdk.Usage.output_tokens">
|
||||
output\_tokens
|
||||
</h3>
|
||||
|
||||
`class-attribute` `instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"output_tokens"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#int">
|
||||
{"int"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"|"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="kc">
|
||||
{"None"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"="}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="kc">
|
||||
{"None"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Number of output tokens used, or `None` when the API did not report it.
|
||||
|
||||
<h2 id="answers">
|
||||
Answers
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.NoulAnswer">
|
||||
typesafe\_sdk.NoulAnswer
|
||||
</h2>
|
||||
|
||||
Bases: `wire.NoulAnswer`
|
||||
|
||||
A yes/no answer.
|
||||
|
||||
See the [noul primitive](https://docs.typesafe.ai/primitives/noul) for details.
|
||||
|
||||
<h3 id="typesafe_sdk.NoulAnswer.noul">
|
||||
noul
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"noul"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Probability of a yes answer, from zero to one.
|
||||
|
||||
<h2 id="typesafe_sdk.ChoiceAnswer">
|
||||
typesafe\_sdk.ChoiceAnswer
|
||||
</h2>
|
||||
|
||||
Bases: `wire.ChoiceAnswer`
|
||||
|
||||
A selected label and its probabilities.
|
||||
|
||||
See the [choice primitive](https://docs.typesafe.ai/primitives/choice) for details.
|
||||
|
||||
<h3 id="typesafe_sdk.ChoiceAnswer.choice">
|
||||
choice
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"choice"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The selected label.
|
||||
|
||||
<h3 id="typesafe_sdk.ChoiceAnswer.confidence">
|
||||
confidence
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"confidence"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Reported confidence in the selected label.
|
||||
|
||||
<h3 id="typesafe_sdk.ChoiceAnswer.probabilities">
|
||||
probabilities
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"probabilities"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
|
||||
{"dict"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Probabilities keyed by label.
|
||||
|
||||
<h2 id="typesafe_sdk.ScoreAnswer">
|
||||
typesafe\_sdk.ScoreAnswer
|
||||
</h2>
|
||||
|
||||
Bases: `wire.ScoreAnswer`
|
||||
|
||||
An expected score with its rubric and probabilities.
|
||||
|
||||
See the [score primitive](https://docs.typesafe.ai/primitives/score) for details.
|
||||
|
||||
<h3 id="typesafe_sdk.ScoreAnswer.score">
|
||||
score
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"score"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Expected score, which may fall between the integer rubric levels.
|
||||
|
||||
<h3 id="typesafe_sdk.ScoreAnswer.confidence">
|
||||
confidence
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"confidence"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Reported confidence in the score.
|
||||
|
||||
<h3 id="typesafe_sdk.ScoreAnswer.legend">
|
||||
legend
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">{"legend"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span>{"\n"}{" "}<span className="n"><a href="https://docs.python.org/3/builtins/functions.html#int">{"int"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#dict">{"dict"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#str">{"str"}</a></span><span className="p">{","}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.Any">{"Any"}</a></span><span className="p">{"]"}</span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/builtins/stdtypes.html#list">{"list"}</a></span><span className="p">{"["}</span><span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.Any">{"Any"}</a></span><span className="p">{"]"}</span>{"\n"}<span className="p">{"]"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Rubric descriptions keyed by integer score.
|
||||
|
||||
<h3 id="typesafe_sdk.ScoreAnswer.probabilities">
|
||||
probabilities
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"probabilities"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#dict">
|
||||
{"dict"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#int">
|
||||
{"int"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/functions.html#float">
|
||||
{"float"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
Probabilities keyed by integer score.
|
||||
|
||||
<h2 id="typesafe_sdk.Answer">
|
||||
typesafe\_sdk.Answer
|
||||
</h2>
|
||||
|
||||
`module-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">{"Answer"}</span><span className="p">{":"}</span>{" "}<span className="n"><a href="https://docs.python.org/3/library/typing.html#typing.TypeAlias">{"TypeAlias"}</a></span>{" "}<span className="o">{"="}</span>{" "}<span className="p">{"("}</span>{"\n"}{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.NoulAnswer">{"NoulAnswer"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ChoiceAnswer">{"ChoiceAnswer"}</a></span>{" "}<span className="o">{"|"}</span>{" "}<span className="n"><a href="/sdk/python/api/types/responses#typesafe_sdk.ScoreAnswer">{"ScoreAnswer"}</a></span>{"\n"}<span className="p">{")"}</span>{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
An answer to a single question, identified by its `type`.
|
||||
|
||||
<h2 id="available-models">
|
||||
Available models
|
||||
</h2>
|
||||
|
||||
<h2 id="typesafe_sdk.ListModelsResponse">
|
||||
typesafe\_sdk.ListModelsResponse
|
||||
</h2>
|
||||
|
||||
Bases: `Response`
|
||||
|
||||
The models available to the account.
|
||||
|
||||
<h3 id="typesafe_sdk.ListModelsResponse.request_id">
|
||||
request\_id
|
||||
</h3>
|
||||
|
||||
`cached` `property`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"request_id"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The `x-typesafe-request-id` response header.
|
||||
|
||||
<h3 id="typesafe_sdk.ListModelsResponse.raw_http_response">
|
||||
raw\_http\_response
|
||||
</h3>
|
||||
|
||||
`property`
|
||||
|
||||
```python theme={null}
|
||||
raw_http_response: httpx2.Response
|
||||
```
|
||||
|
||||
The underlying `httpx2.Response`, exposing status, headers, and body.
|
||||
|
||||
<h3 id="typesafe_sdk.ListModelsResponse.models">
|
||||
models
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"models"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#tuple">
|
||||
{"tuple"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"["}
|
||||
</span>
|
||||
|
||||
<span className="n">
|
||||
<a href="/sdk/python/api/types/responses#typesafe_sdk.ModelMetadata">
|
||||
{"ModelMetadata"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{","}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="o">
|
||||
{"..."}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{"]"}
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
The available models.
|
||||
|
||||
<h2 id="typesafe_sdk.ModelMetadata">
|
||||
typesafe\_sdk.ModelMetadata
|
||||
</h2>
|
||||
|
||||
Bases: <code><a href="https://msgspec.dev/api.html#msgspec.Struct">Struct</a></code>
|
||||
|
||||
<h3 id="typesafe_sdk.ModelMetadata.name">
|
||||
name
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"name"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
<h3 id="typesafe_sdk.ModelMetadata.description">
|
||||
description
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"description"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
|
||||
<h3 id="typesafe_sdk.ModelMetadata.release_date">
|
||||
release\_date
|
||||
</h3>
|
||||
|
||||
`instance-attribute`
|
||||
|
||||
<SdkSignature>
|
||||
<span className="n">
|
||||
{"release_date"}
|
||||
</span>
|
||||
|
||||
<span className="p">
|
||||
{":"}
|
||||
</span>
|
||||
|
||||
{" "}
|
||||
|
||||
<span className="n">
|
||||
<a href="https://docs.python.org/3/builtins/stdtypes.html#str">
|
||||
{"str"}
|
||||
</a>
|
||||
</span>
|
||||
|
||||
{"\n"}
|
||||
</SdkSignature>
|
||||
45
docs/sdk/python/changelog.md
Normal file
45
docs/sdk/python/changelog.md
Normal file
@@ -0,0 +1,45 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Changelog
|
||||
|
||||
> Python clients for the TypeSafe AI API
|
||||
|
||||
<a id="changelog" />
|
||||
|
||||
<h2 id="v060-2026-09-15">
|
||||
v0.6.0 (2026-09-15)
|
||||
</h2>
|
||||
|
||||
<h3 id="breaking-changes">
|
||||
Breaking Changes
|
||||
</h3>
|
||||
|
||||
* accept `Score.criteria` as an ordered sequence instead of a dictionary keyed by integers
|
||||
|
||||
<h3 id="features">
|
||||
Features
|
||||
</h3>
|
||||
|
||||
* improve type annotations on SDK inputs to accept abstract types like `Mapping` and `Sequence`
|
||||
* improve error messages to include http details and metadata
|
||||
|
||||
<h3 id="bug-fixes">
|
||||
Bug fixes
|
||||
</h3>
|
||||
|
||||
* handle invalid values in `RetryPolicy`
|
||||
* make exceptions and responses picklable
|
||||
|
||||
<h3 id="documentation">
|
||||
Documentation
|
||||
</h3>
|
||||
|
||||
* link more concepts from main [docs](https://docs.typesafe.ai/)
|
||||
|
||||
<h2 id="v057-2026-09-14">
|
||||
v0.5.7 (2026-09-14)
|
||||
</h2>
|
||||
|
||||
This is the initial public release of TypeSafe Python SDK. Learn more in the [documentation](https://docs.typesafe.ai/sdk/python).
|
||||
220
docs/sdk/python/usage.md
Normal file
220
docs/sdk/python/usage.md
Normal file
@@ -0,0 +1,220 @@
|
||||
> ## Documentation Index
|
||||
> Fetch the complete documentation index at: https://docs.typesafe.ai/llms.txt
|
||||
> Use this file to discover all available pages before exploring further.
|
||||
|
||||
# Usage
|
||||
|
||||
> Guides and patterns for working with the TypeSafe Python SDK.
|
||||
|
||||
<a id="usage" />
|
||||
|
||||
<h2 id="calling-the-system-one-api">
|
||||
Calling the System One API
|
||||
</h2>
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Async">
|
||||
```python theme={null}
|
||||
import asyncio
|
||||
|
||||
from typesafe_sdk import AsyncTypeSafeClient, Choice, Noul, Score
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with AsyncTypeSafeClient() as client:
|
||||
result = await client.system_one(
|
||||
"I was charged twice. Please help ASAP.",
|
||||
{
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?",
|
||||
criteria={"calm": None, "angry": None},
|
||||
),
|
||||
"urgency": Score(
|
||||
instructions="How urgent is this?",
|
||||
criteria=["low", "medium", "high"],
|
||||
),
|
||||
},
|
||||
)
|
||||
print(
|
||||
result.nouls["billing"].noul,
|
||||
result.choices["tone"].choice,
|
||||
result.scores["urgency"].score,
|
||||
)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Sync">
|
||||
```python theme={null}
|
||||
from typesafe_sdk import Choice, Noul, Score, TypeSafeClient
|
||||
|
||||
client = TypeSafeClient()
|
||||
state = "I was charged twice. Please help ASAP."
|
||||
questions = {
|
||||
"billing": Noul(instructions="Is this about billing?"),
|
||||
"tone": Choice(
|
||||
instructions="What is the tone?", criteria={"calm": None, "angry": None}
|
||||
),
|
||||
"urgency": Score(
|
||||
instructions="How urgent is this?", criteria=["low", "medium", "high"]
|
||||
),
|
||||
}
|
||||
result = client.system_one(state, questions)
|
||||
print(
|
||||
result.nouls["billing"].noul,
|
||||
result.choices["tone"].choice,
|
||||
result.scores["urgency"].score,
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
<h2 id="choosing-a-model">
|
||||
Choosing a model
|
||||
</h2>
|
||||
|
||||
Inspect the available models:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import TypeSafeClient
|
||||
|
||||
print(TypeSafeClient().models.list())
|
||||
```
|
||||
|
||||
Select the model when constructing a client:
|
||||
|
||||
```python theme={null}
|
||||
client = TypeSafeClient(model="jev")
|
||||
```
|
||||
|
||||
See [Models](/models) for available models, pricing, rate limits, and aliases.
|
||||
|
||||
<h2 id="retries">
|
||||
Retries
|
||||
</h2>
|
||||
|
||||
Pass a custom [`RetryPolicy`](/sdk/python/api/retries) as `retry` on the client or per call.
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Client">
|
||||
```python theme={null}
|
||||
from typesafe_sdk import RetryPolicy, TypeSafeClient
|
||||
|
||||
client = TypeSafeClient(retry=RetryPolicy(max_retries=3, backoff_max=0.2, timeout=1.0))
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Per-call">
|
||||
```python theme={null}
|
||||
from typesafe_sdk import RetryPolicy
|
||||
|
||||
client.system_one(
|
||||
state, questions, retry=RetryPolicy(max_retries=3, backoff_max=0.2, timeout=1.0)
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
<h2 id="error-handling">
|
||||
Error handling
|
||||
</h2>
|
||||
|
||||
Handle [exceptions](/sdk/python/api/exceptions) raised by the SDK:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import TypeSafeAPIError
|
||||
|
||||
try:
|
||||
client.system_one(state, questions)
|
||||
except TypeSafeAPIError as error:
|
||||
print(error.status, error.request_id)
|
||||
```
|
||||
|
||||
<h2 id="logging">
|
||||
Logging
|
||||
</h2>
|
||||
|
||||
The SDK logs to the `typesafe_sdk` logger. Configure it according to [standard logging](https://docs.python.org/3/library/logging.html) guide:
|
||||
|
||||
```python theme={null}
|
||||
import logging
|
||||
|
||||
logging.getLogger("typesafe_sdk").setLevel(logging.DEBUG)
|
||||
```
|
||||
|
||||
Or set `TYPESAFE_LOG_LEVEL` to one of `debug`, `info`, `warning`, `error`, or `off` before importing the SDK.
|
||||
|
||||
`info` logs one summary line per request; `debug` also logs request and response headers and bodies. Secret headers — authorization, API keys, cookies, and any header whose name contains `token` or `secret` — are redacted from log output. Request and response bodies are **not** redacted.
|
||||
|
||||
<h2 id="environment-variables">
|
||||
Environment variables
|
||||
</h2>
|
||||
|
||||
The SDK reads and uses the following environment variables:
|
||||
|
||||
| Variable | Configures | Default |
|
||||
| ------------------------ | --------------------------------------------------- | ------------------------- |
|
||||
| `TYPESAFE_API_KEY` | API key (required) | — |
|
||||
| `TYPESAFE_BASE_URL` | API root URL | `https://api.typesafe.ai` |
|
||||
| `TYPESAFE_DEFAULT_MODEL` | Default model | `jev-latest` |
|
||||
| `TYPESAFE_LOG_LEVEL` | `typesafe_sdk` logger level, applied once at import | unset |
|
||||
|
||||
See the [constants reference](/sdk/python/api/constants) for SDK defaults.
|
||||
|
||||
<h2 id="forward-compatibility">
|
||||
Forward compatibility
|
||||
</h2>
|
||||
|
||||
The SDK keeps working as the TypeSafe API evolves, so you can adopt new API features before an SDK release adds first-class support for them.
|
||||
|
||||
<h3 id="extra-request-fields">
|
||||
Extra request fields
|
||||
</h3>
|
||||
|
||||
Send request fields this SDK version predates with [`extra_body`](/sdk/python/api/clients/sync/client):
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import Noul, TypeSafeClient
|
||||
|
||||
with TypeSafeClient() as client:
|
||||
client.system_one(
|
||||
"I was charged twice.",
|
||||
{"billing": Noul(instructions="About billing?")},
|
||||
extra_body={"beam_width": 4},
|
||||
)
|
||||
```
|
||||
|
||||
<h3 id="raw-question-dictionaries">
|
||||
Raw question dictionaries
|
||||
</h3>
|
||||
|
||||
Pass a question as a plain dictionary to include fields this SDK version does not model yet:
|
||||
|
||||
```python theme={null}
|
||||
from typesafe_sdk import TypeSafeClient
|
||||
|
||||
with TypeSafeClient() as client:
|
||||
client.system_one(
|
||||
"I was charged twice.",
|
||||
{"billing": {"type": "noul", "instructions": "About billing?", "weight": 2}},
|
||||
)
|
||||
```
|
||||
|
||||
<h3 id="unknown-answer-kinds">
|
||||
Unknown answer kinds
|
||||
</h3>
|
||||
|
||||
The SDK logs a warning and skips unrecognized answer kinds. Use `raw_http_response` to inspect the complete API response, including those answers:
|
||||
|
||||
```python theme={null}
|
||||
raw_answers = result.raw_http_response.json()["answers"]
|
||||
```
|
||||
|
||||
<h3 id="unknown-response-fields">
|
||||
Unknown response fields
|
||||
</h3>
|
||||
|
||||
Unknown extra fields on recognized responses are ignored.
|
||||
Reference in New Issue
Block a user