# pi-apfel

Pi provider extension for [Apfel](https://github.com/Arthur-Ficial/apfel), which exposes Apple's on-device FoundationModels API through a local OpenAI-compatible server.

## Requirements

- macOS 26+ on Apple Silicon
- Apple Intelligence enabled
- `apfel` installed and available on `PATH`

```bash
brew install apfel
```

## Install

From npm:

```bash
pi install npm:pi-apfel
```

For local development from this repository:

```bash
pi -e .
```

Or install this checkout as a Pi package:

```bash
pi install /absolute/path/to/pi-apfel
```

## Usage

The extension registers a new Pi model provider named `apfel` with model `apple-foundationmodel`.

Commands:

- `/apfel-start` — starts `apfel --serve` on `127.0.0.1:11434`
- `/apfel-health` — checks Apfel's `/health` endpoint
- `/apfel-stop` — stops the server if this Pi session started it

Then choose the model in Pi with `/model` and select `apfel/apple-foundationmodel`.

## Configuration

Environment variables:

- `APFEL_BASE_URL` — full OpenAI-compatible base URL, defaults to `http://127.0.0.1:11434/v1`
- `APFEL_HOST` — host used by `/apfel-start`, defaults to `127.0.0.1`
- `APFEL_PORT` — port used by `/apfel-start`, defaults to `11434`
- `APFEL_TOKEN` — token if the Apfel server was started with `--token`

Extra arguments passed to `/apfel-start` are appended to `apfel --serve`, for example:

```text
/apfel-start --permissive
```
