npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@holic512/plugin-llm-base

v1.0.1

Published

Base OpenAI-compatible LLM capability layer for SlothTool plugins

Downloads

87

Readme

@holic512/plugin-llm-base

llm-base 是 SlothTool 的基础 LLM 能力插件,专注提供三件事:

  1. 配置管理(profile)
  2. OpenAI 协议兼容调用
  3. 调用日志

设计边界:不承载业务逻辑、不内置行业提示词、不直接产出最终业务结论。


1. 安装与入口

slothtool install @holic512/plugin-llm-base

安装后可用命令:

slothtool llm-base --help
# 或直接执行插件命令
llm-base --help

2. 配置文件与数据文件

2.1 主配置

路径:~/.slothtool/plugin-configs/llm-base.json

结构示例:

{
  "default_profile": "local",
  "profiles": {
    "local": {
      "base_url": "https://api.openai.com/v1",
      "api_key": "sk-xxxx",
      "low_model": "gpt-4o-mini",
      "high_model": "gpt-4o",
      "timeout": 60000
    }
  }
}

2.2 调用日志

路径:~/.slothtool/plugin-configs/llm-base.logs.json

每条记录字段:

  • call_id
  • timestamp
  • profile
  • model
  • duration_ms
  • success
  • usage

保留策略:仅保留最近 500 条。


3. CLI 使用

3.1 配置管理

# 创建 profile
llm-base config create <name>

# 更新 profile
llm-base config update <name>

# 删除 profile
llm-base config delete <name>

# 查看 profile 列表
llm-base config list

# 设置默认 profile
llm-base config set-default <name>

# 查看 profile 详情(默认脱敏)
llm-base config show <name>

# 导出配置(默认脱敏)
llm-base config export

# 交互式配置
llm-base -i
# 或
llm-base config -i

3.2 调用接口

chat 调用(自动 low/high 模型,严格 JSON 输出)

# 默认 low 模式
llm-base chat "你好"

# high 模式
llm-base chat "请总结以下文本" --mode high

# 指定 profile
llm-base chat "hello" --mode low --profile local

说明:

  • chat 已内置“严格 JSON 模式”系统提示词。
  • 返回结构中的 data 字段始终为 JSON 对象。
  • 若模型未按要求返回合法 JSON,会自动落入兜底对象:
    • {"result":"原始文本","_fallback":true,"_reason":"model_output_was_not_valid_json"}

raw 透传调用

llm-base raw '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"hello"}]}'

# 指定 profile
llm-base raw '{"model":"gpt-4o","messages":[{"role":"user","content":"hello"}]}' --profile local

4. 模块调用(供其他插件依附)

const llmBase = require('@holic512/plugin-llm-base/lib/index');

// 配置管理
llmBase.create_profile(name, config);
llmBase.update_profile(profile_id, patch);
llmBase.delete_profile(profile_id);
llmBase.list_profiles();
llmBase.set_default_profile(profile_id);

// LLM 调用
await llmBase.llm_chat(messages, mode, profile);
await llmBase.llm_raw(payload, profile);

// 日志
llmBase.list_calls();
llmBase.get_call(call_id);

5. 返回结构约定

5.1 成功结构

{
  "success": true,
  "model": "实际使用模型名",
  "data": {
    "result": "结构化结果"
  },
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "call_id": "uuid"
}

5.2 失败结构

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "错误说明"
  },
  "call_id": "uuid"
}

6. 错误码说明

  • NO_PROFILE:默认 profile 不存在,或指定 profile 不存在
  • NETWORK_ERROR:网络异常、连接失败、超时
  • AUTH_ERROR:401/403
  • RATE_LIMIT:429
  • PROVIDER_ERROR:其余 provider 错误

7. 安全与隐私规则

  • config show/export 默认脱敏(api_key 不明文)
  • 日志不记录完整用户输入正文
  • 不记录敏感 header(如 Authorization)
  • 错误信息中不回显 api_key

8. 典型流程示例

  1. 创建 profile 并设为默认
llm-base config create local
llm-base config set-default local
  1. 发起 low/high 调用
llm-base chat "简要介绍 SlothTool" --mode low
llm-base chat "请做详细技术分析" --mode high
  1. 检查调用日志
node -e "const api=require('./lib/index'); console.log(api.list_calls())"