Metadata-Version: 2.3
Name: cooksafe
Version: 0.3.0
Summary: Shared helpers for the TypeSafe cookbooks
Requires-Dist: lzstring
Requires-Dist: msgspec>=0.18
Requires-Dist: typesafe-sdk>=0.7.0,<0.8.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# cooksafe

Two helpers the [TypeSafe](https://console.typesafe.ai) cookbooks share.

```bash
pip install 'cooksafe>=0.3.0,<0.4.0'
```

## `JsonCache`

File-backed memoization for the model calls in a notebook, so a re-run replays what the first
run recorded instead of paying for it again.

```python
from pathlib import Path
from cooksafe import JsonCache

cache = JsonCache(Path("json_cache.json"))

@cache
def ask(text: str, questions_json: str) -> dict:
    ...  # a real API call happens once per distinct argument set
```

Results must be JSON-serializable. Keys are the function name plus its arguments; long ones
(a whole input text, say) are stored as a digest so the file stays readable. SDK question objects
are keyed by their API JSON, so the key does not depend on the object's repr. Delete the file to
re-sample everything live.

## `make_playground_link`

Turns a state and a set of questions into a link that opens them in the TypeSafe
playground, for readers who want to try a cookbook's questions against their own text.

```python
from cooksafe import make_playground_link
from typesafe_sdk import Noul, NoulCriteria

questions = {
    "is_greeting": Noul(
        instructions="Is this a greeting?",
        criteria=NoulCriteria(true="it greets the reader", false="it does not"),
    )
}
print(make_playground_link({"text": "hello there"}, questions))
```

The link carries the state and questions in its fragment, so it is generated offline and
nothing is uploaded to build it.
