UniGPT provider for pi

Native /login with a verified API key, automatic model discovery from
UniGPT's /models endpoint, per-deployment deployment-id headers, and
model metadata from pi's bundled catalog.
This commit is contained in:
Benjamin Hackl 2026-11-03 20:01:28 +01:00
commit 4e854ba8c2

126
README.md Normal file
View file

@ -0,0 +1,126 @@
# pi-unigpt
Use [UniGPT](https://unigpt.uni-graz.at), the University of Graz's MyGPT
platform, as a model provider in [pi](https://pi.dev).
- Log in with **`/login unigpt`**; your key is checked before pi saves it.
- Models are discovered automatically. No model list to maintain.
- Context size, output limit, and image support come from pi's own model
catalog, so they stay current as pi updates.
- Tool calling, streaming, and image input work through pi's built-in
OpenAI Responses support.
Requires pi **1.5.x** and Node.js **22.19+**.
## Install
```sh
pi install git:github.com/behackl/pi-unigpt
```
Then start pi (or run `/reload` in a running session) and log in:
```text
/login unigpt
```
Paste your UniGPT API key into the masked dialog, **not into the chat**. Pi
confirms how many models your key can use. Pick one with `/model`; UniGPT
models are listed under `unigpt`.
To try the extension without installing it:
```sh
pi -e git:github.com/behackl/pi-unigpt
```
## Commands
| Command | What it does |
| --- | --- |
| `/login unigpt` | Save and verify your API key |
| `/logout` | Remove the saved key from pi (it stays valid at UniGPT) |
| `/model` | Pick a model; also reloads the model list |
| `/unigpt-refresh` | Reload the UniGPT model list now and show how many models you have |
## How models are described
UniGPT's API only lists deployment IDs such as `gpt-5.4`. Those IDs are
OpenAI model names, so the extension looks each one up in pi's bundled model
catalog and uses its name, context window, output limit, and image support.
Where OpenAI and Azure list different limits, the smaller one is used.
IDs that pi does not know get pi's standard defaults for custom models:
128k context, 16k output, text only. Update pi to pick up newer models.
Two things are deliberately not taken from the catalog:
- **Thinking levels are off for every model.** UniGPT ignores the requested
reasoning effort and uses a fixed one per deployment, so pi's thinking
levels would have no effect. Reasoning models still reason.
- **Costs are shown as zero.** That means "not tracked", not "free".
You can override any value in `~/.pi/agent/models.json`:
```json
{
"providers": {
"unigpt": {
"modelOverrides": {
"gpt-5.4": { "contextWindow": 200000 }
}
}
}
}
```
## Your API key
Pi stores the key under `unigpt` in `~/.pi/agent/auth.json`. That file is
private to your user account but **not encrypted**. To keep the key out of
it, replace the stored value with an environment variable or a password
manager command; pi resolves either when it needs the key:
```json
{
"unigpt": { "type": "api_key", "key": "${UNIGPT_API_KEY}" }
}
```
```json
{
"unigpt": { "type": "api_key", "key": "!op read op://Private/UniGPT/credential" }
}
```
## Upgrading from a models.json setup
If you configured UniGPT by hand before, delete the `unigpt` entry under
`providers` in `~/.pi/agent/models.json` (overrides as shown above are
fine). Otherwise your old model list and key take precedence over the
extension. Then run `/reload` and `/login unigpt`.
## Troubleshooting
- **No UniGPT models in `/model`:** run `/unigpt-refresh`; it reports the
exact problem (rejected key, unreachable server, empty model list).
- **`pi -p` says a UniGPT model was not found:** print mode only reads the
saved model list and never fetches it. Start pi interactively once after
logging in; later print runs reuse that list.
- **A specific model fails with HTTP 500:** some deployments are
misconfigured on the server side; try another model and tell the UniGPT
team.
## Development
```sh
pnpm install
pnpm run ci # type check + tests
```
Tests use fake keys and a local HTTP server; they never contact UniGPT or
read your pi configuration.
## License
MIT