Metadata-Version: 2.3
Name: cooksafe
Version: 0.1.0
Summary: Shared helpers for the TypeSafe cookbooks
Requires-Dist: lzstring
Requires-Dist: typesafe-client>=1.0.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 --extra-index-url https://pypi.typesafe.ai/
```

The extra index is where TypeSafe serves this package and `typesafe_client`.

## `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(model: str, question: 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 document, say) are stored as a digest so the file stays readable. Delete the file to
re-sample everything live.

## `make_playground_link`

Turns a document 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
import typesafe_client.api.models as tsm
from cooksafe import make_playground_link

questions = {
    "is_greeting": tsm.NoulQuestion(
        instructions="Is this a greeting?",
        criteria=tsm.NoulCriteria(true="it greets the reader", false="it does not"),
    )
}
print(make_playground_link({"doc": "hello there"}, questions, models=["speed_latest"]))
```

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