@wbline/pi-dynamic-models0.2.1
Dynamic model discovery for Pi coding agent — fetches models from any configured API server at startup
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-dynamic-models
pi install npm:@wbline/pi-dynamic-models
Pi 会把包记录到 ~/.pi/agent/settings.json,并自动启用其中声明的扩展。仅 npm install -g 不会激活 Pi 扩展。
为 pi 提供动态模型发现能力。启动时从配置的 OpenAI 兼容服务器拉取模型列表(含元数据),自动注册为可选 provider——无需手动维护模型清单。
配置
1. 安装包
在 Pi agent 设置(~/.pi/agent/settings.json)中添加:
{
"packages": [
"local:/path/to/playbook/packages/pi-dynamic-models"
]
}
2. 创建配置文件
创建 ~/.pi/agent/pi-dynamic-models.json:
[
{
"provider": "my-provider",
"baseUrl": "https://your-server.com/v1",
"apiKey": "your-api-key",
"api": "openai-completions"
}
]
字段说明
| 字段 | 必填 | 说明 |
|---|---|---|
provider |
✓ | 在模型选择器中显示的名称 |
baseUrl |
✓ | 服务器地址,如需要请包含 /v1 |
apiKey |
字面量密钥、环境变量名或 $ENV_VAR。开放服务器可省略或设为 "none"。 |
|
api |
Pi API 类型(默认:openai-completions)。 |
支持的 API 类型
| 值 | 适用场景 |
|---|---|
openai-completions |
Ollama、vLLM、LM Studio、llama.cpp 及大多数本地服务器 |
openai-responses |
兼容 OpenAI Responses API 的服务器 |
anthropic-messages |
兼容 Anthropic 的代理 |
google-generative-ai |
兼容 Google AI 的服务器 |
azure-openai-responses |
Azure OpenAI |
工作原理
启动时对每个 provider 请求一次:
GET {baseUrl}/models— 模型列表(每个条目自带元数据)
/models 支持如下响应格式:
{
"object": "list",
"data": [
{
"id": "example-model",
"object": "meta",
"owned_by": "relay",
"context_window": 524288,
"max_tokens": 65536,
"input": ["text", "image"]
}
]
}
字段映射:
| models 字段 | 模型字段 | 缺省 |
|---|---|---|
id |
id |
— |
name |
name |
回退为 id |
context_window |
contextWindow |
128000 |
max_tokens |
maxTokens |
16384 |
input |
input |
["text"] |
reasoning |
reasoning |
false |
thinking_level_map |
thinkingLevelMap |
不传 |
cost |
cost(cache_read→cacheRead 等) |
全 0 |
/models 是唯一数据源:仅当其成功且返回至少一个模型时才注册该 provider;条目中元数据字段缺失或无效时使用默认值。
故障排查
模型列表为空:确认配置文件位于 ~/.pi/agent/pi-dynamic-models.json,且 {baseUrl}/models 可访问。
API 行为异常:为服务器类型设置正确的 api 字段。
API key 未解析:支持裸环境变量名(如 CLINE_API_KEY)与 $CLINE_API_KEY / ${CLINE_API_KEY} 写法;也可直接写字面量密钥。
contextWindow 始终为 128000:确认 /models 中对应模型带有非空的 context_window。