|
| 1 | +# Hello Jev: Getting Started With Jev in Python |
| 2 | + |
| 3 | +This folder provides the code examples for *Get Started With Jev in Python*, |
| 4 | +a video on the [Real Python YouTube channel](https://www.youtube.com/@realpython). |
| 5 | + |
| 6 | +Both scripts run the same train-station info desk. The desk asks a visitor |
| 7 | +whether they lost something and then points them at the lost-and-found counter |
| 8 | +or asks what else it can help with. The difference is how the answer is read: |
| 9 | + |
| 10 | +- **`plain_python.py`** handles the input by hand. It only accepts an uppercase |
| 11 | + `Y` or `N`, so anything else sends the visitor back around the loop. |
| 12 | +- **`jev_noul.py`** replaces that branching with a single `Noul` question. Jev |
| 13 | + scores how affirmative the answer is on a scale from `0` to `1`, so the script |
| 14 | + compares thresholds instead of strings and understands replies like |
| 15 | + `yeah, I've lost something`. |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +Install [uv](https://docs.astral.sh/uv/), then create the virtual environment. |
| 20 | +Because `pyproject.toml` pins `requires-python = ">=3.14"`, uv downloads |
| 21 | +CPython 3.14 for you if you don't have it yet: |
| 22 | + |
| 23 | +```sh |
| 24 | +$ uv sync |
| 25 | +``` |
| 26 | + |
| 27 | +`jev_noul.py` reaches Jev through [OpenRouter](https://openrouter.ai/), which |
| 28 | +lets you try the model without opening an account with TypeSafe AI. Grab an |
| 29 | +OpenRouter API key, then create a `.env` file next to the scripts and add it: |
| 30 | + |
| 31 | +```dotenv |
| 32 | +OPENROUTER_API_KEY=<YOUR-OPENROUTER-KEY> |
| 33 | +``` |
| 34 | + |
| 35 | +Keep `.env` out of version control. An API key belongs in your environment, not |
| 36 | +in your repository. |
| 37 | + |
| 38 | +## Running the Examples |
| 39 | + |
| 40 | +Start with the plain script to see where hand-written input handling gives up: |
| 41 | + |
| 42 | +```sh |
| 43 | +$ uv run plain_python.py |
| 44 | +Did you lose something? (Y/N) |
| 45 | +``` |
| 46 | + |
| 47 | +Only an uppercase `Y` or `N` gets you past the prompt. Try `yes` or `y` and the |
| 48 | +script asks again. |
| 49 | + |
| 50 | +Now run the Jev version. The `--env-file` flag tells uv to load your API key |
| 51 | +from `.env` before it starts the script: |
| 52 | + |
| 53 | +```sh |
| 54 | +$ uv run --env-file .env jev_noul.py |
| 55 | +Did you lose something? |
| 56 | +``` |
| 57 | + |
| 58 | +Answer in your own words. `jev_noul.py` treats a Noul above `0.8` as a yes and |
| 59 | +below `0.2` as a no, and asks again for anything in between. |
| 60 | + |
| 61 | +## Where to Go Next |
| 62 | + |
| 63 | +`Noul` is one of three Jev primitives. `Score` rates something on a scale, and |
| 64 | +`Choice` picks from a list of options. The |
| 65 | +[TypeSafe SDK on PyPI](https://pypi.org/project/typesafe-sdk/) documents all |
| 66 | +three, and the TypeSafe AI blog explains the idea behind them in |
| 67 | +[Introducing System One Models and Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev). |
0 commit comments