Custom Models(自定义模型)

本页面是 Pi 官方文档 的中文翻译。仅供学习参考。

通过 ~/.pi/agent/models.json 添加自定义模型配置。该文件在每次打开 /model 时重新加载,无需重启。

最小示例

对于 Ollama、LM Studio 或 vLLM 等本地模型,只需提供 id

{
  "providers": [
    {
      "name": "ollama",
      "baseUrl": "http://localhost:11434/v1",
      "api": "openai-completions",
      "apiKey": "ollama",
      "models": [
        { "id": "llama3.1:8b" },
        { "id": "qwen2.5-coder:7b" }
      ]
    }
  ]
}

某些 OpenAI 兼容服务器不支持 developer 角色。设置 compat.supportsDeveloperRolefalse。如果不支持 reasoning_effort,设置 compat.supportsReasoningEffortfalse

完整示例

{
  "providers": [
    {
      "name": "ollama",
      "baseUrl": "http://localhost:11434/v1",
      "api": "openai-completions",
      "apiKey": "ollama",
      "models": [
        {
          "id": "llama3.1:8b",
          "name": "Llama 3.1 8B",
          "reasoning": false,
          "input": ["text"],
          "contextWindow": 128000,
          "maxTokens": 32000,
          "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }
        }
      ]
    }
  ]
}

支持的 API 类型

API说明
openai-completionsOpenAI Chat Completions(最兼容)
openai-responsesOpenAI Responses API
anthropic-messagesAnthropic Messages API
google-generative-aiGoogle Generative AI

Provider 配置

字段说明
baseUrlAPI 端点 URL
apiAPI 类型
apiKeyAPI Key(支持值解析)
headers自定义头(支持值解析)
authHeader设为 true 自动添加 Authorization: Bearer <apiKey>
models模型配置数组
modelOverrides内置模型的逐模型覆盖

值解析

apiKeyheaders 字段支持三种格式:

  1. Shell 命令"!op read 'op://vault/item/credential'"
  2. 环境变量"MY_API_KEY"
  3. 字面值"sk-..."

模型配置

字段必需默认值说明
id-传递给 API 的模型标识符
nameid人类可读标签
apiProvider 的 api覆盖 Provider API 类型
reasoningfalse是否支持 extended thinking
thinkingLevelMap-将 Pi thinking level 映射到 Provider 值
input["text"]输入类型
contextWindow128000上下文窗口(Token)
maxTokens16384最大输出 Token
cost全零每百万 Token 费用

覆盖内置 Provider

{
  "providers": [
    {
      "name": "anthropic",
      "baseUrl": "https://proxy.example.com"
    }
  ]
}

所有内置 Anthropic 模型保持可用,现有 OAuth 或 API Key 认证继续有效。

OpenAI 兼容性

对于部分 OpenAI 兼容的 Provider,使用 compat 字段:

字段说明
supportsDeveloperRole使用 developer 角色而非 system
supportsReasoningEffort支持 reasoning_effort 参数
supportsUsageInStreaming支持流式使用统计
maxTokensField"max_completion_tokens""max_tokens"
requiresToolResultName在工具结果消息中包含 name
thinkingFormatthinking 参数格式:"openrouter""deepseek""together""qwen""qwen-chat-template"
cacheControlFormat缓存控制格式:"anthropic"
openRouterRoutingOpenRouter 路由偏好设置

法律声明:本页面是 pi.dev 官方文档的中文翻译版本,仅供学习参考。本网站与 pi.dev 及 Earendil Inc. 无任何法律关系。