Skip to content

OpenRouter

特点

  • 基于OpenAI兼容接口扩展,可连接各种模型服务
  • 支持多种大语言模型,如Llama、Claude等
  • 支持OpenRouter官方服务或其他兼容服务
  • 默认使用OpenRouter官方API地址

使用代码配置

typescript
const ppagent = new PPAgent({
  bots: [
    {
      name: "openrouter-bot",
      options: {
        instanceName: "myopenrouter", // 实例名称,需要全局唯一
        apiKey: "your-api-key", // 必填,OpenRouter的API密钥
        apiBase: "", // 可选,服务URL,使用OpenRouter官方服务可留空,默认为https://openrouter.ai/api/v1
        onlyText: false, // 可选,是否为纯文本模型,默认false表示支持多模态
        historyExipresInSeconds: 1800, // 可选,历史消息过期时间(秒),默认1800秒
        attachSendMode: "later", // 可选,附件发送模式,默认"later"
        maxAttachCount: 3, // 可选,最大附件数量,默认3
        systemPrompt: "", // 可选,系统提示词
        chatOptions: {
          model: "meta-llama/llama-3.1-70b-instruct:free", // 必填,模型名称,从OpenRouter平台获取
          // 其他OpenAI兼容的参数可在此配置
        }
      }
    }
  ],
  source: { ... }, // 消息源配置
  agent: { ... }, // 代理配置
  // ...其他配置
});

服务器运行请参考 install_code 文件。

配置注意事项

  • 当未设置apiBase或设置为空字符串时,将默认使用OpenRouter官方服务地址:https://openrouter.ai/api/v1
  • 需要在OpenRouter官网注册并获取API密钥才能使用服务
  • 模型名称需要按照OpenRouter支持的格式填写,例如meta-llama/llama-3.1-70b-instruct:free
  • 该模型支持的所有OpenAI兼容参数都可以在chatOptions中配置