# ai-app

> An app that sends support tickets to a model API over HTTP for one-sentence summaries, against a local stand-in, and its recording.

An app that sends each support ticket of `tickets.json` to a model API and keeps a one-sentence summary of it in `summaries.json`. The model API is `model_server.py`, a stand-in that runs on `127.0.0.1` on a free port and is started by the app, so nothing leaves the machine and no key is needed. It has two models, `small-1` and `large-1`, behind `POST /v1/models/<model>/generate`. Standard library only.

- Source: [`ormaos-examples/use-cases/ai-app`](https://github.com/ormaos/ormaos-examples/tree/6e27be59220856263a6a5905400d8630dafe73dd/use-cases/ai-app)
- Guide: [LLM app](/python/guides/llm-app.md)

## Run it

```bash
python app.py
```

```console
$ python app.py
8 tickets summarized, summaries.json written
```

## Recorded

```bash
ormaos run -- python app.py
```

```console
$ ormaos run -- python app.py
8 tickets summarized, summaries.json written
ormaos: r1 exit 0 in …: 1 Python process, 70 calls, 3 exceptions (3 swallowed), 112 io
ormaos: swallowed 3x urllib.error.HTTPError at app.py:28, raised at /tmp/ormaos-docs-python/cpython-3.14.4-linux-x86_64-gnu/lib/python3.14/urllib/request.py:611 [r1:e1]
ormaos: not collected: io: sockets, at model_server.py:51 (once): a socket was connected or bound there; sockets are not recorded, only HTTP made through http.client or httpx is
ormaos: saved in .ormaos/r1, next: ormaos exceptions r1:e1 | ormaos tree r1:c1
```

```console
$ ormaos show
r1 exit 0 in …: 1 Python process, 70 calls, 3 exceptions (3 swallowed, 0 uncaught)
command: python app.py
code: git commit not read (the working directory is not inside a git repository)
swallowed 3x urllib.error.HTTPError at app.py:28 in summarize, raised at /tmp/ormaos-docs-python/cpython-3.14.4-linux-x86_64-gnu/lib/python3.14/urllib/request.py:611  [r1:e1]
io: 112 events (file 101, http 11)
io: 98x file write summaries.json from app.py:38  [r1:i15]
io: 5x http POST http://127.0.0.1:…/v1/models/small-1/generate -> 200 from app.py:20  [r1:i3]
io: 3x http POST http://127.0.0.1:…/v1/models/small-1/generate -> 503 from app.py:20  [r1:i5]
io: 3x http POST http://127.0.0.1:…/v1/models/large-1/generate -> 200 from app.py:20  [r1:i6]
not collected: io: sockets, at model_server.py:51 (once): a socket was connected or bound there; sockets are not recorded, only HTTP made through http.client or httpx is
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos exceptions r1:e1 | ormaos tree r1:c1 | ormaos io r1 | ormaos io r1:i15
```

---

Source: https://docs.ormaos.com/examples/ai-app/ · ormaos 0.0.1 · ormaos-python 968f69776c · ormaos-examples 6e27be5922
