← 返回
开发者工具 中文

3-Layer Token Compressor — Cut AI API Costs 40-60%

Pre-process prompts through 3 compression layers before sending to paid APIs. Uses a local Ollama model to intelligently compress messages and summarize hist...
在发送至付费API前,通过三层压缩预处理提示词;利用本地Ollama模型智能压缩消息并生成历史摘要。
theshadowrose theshadowrose 来源
开发者工具 clawhub v1.1.0 1 版本 99899.4 Key: 无需
★ 0
Stars
📥 993
下载
💾 14
安装
1
版本
#api-costs#budget#compression#cost-reduction#latest#ollama#prompt-optimization#token-optimization

概述

3-Layer Token Compressor — Cut AI API Costs 40-60%

Pre-process prompts through 3 compression layers before sending to paid APIs. Uses a free local Ollama model to do the compression work — your paid API only sees the condensed result.

Runtime Requirements

RequirementDetails
----------------------
OllamaMust be running locally (default: localhost:11434)
Local modelA small model for compression (e.g. llama3.1:8b). Configurable via compressionModel option.
Node.js14+

Ollama is required at runtime. The compressor sends prompts to your local model — not to any external API.

What This Skill Sends to the Local Model

This skill sends the following to your local Ollama model:

OperationSystem promptUser prompt
--------------------------------------
Message compressionYou are a text compression tool. Output only what is asked, nothing else.Your message + instruction to compress
History summarizationSameOld conversation turns + instruction to summarize

No data is sent to external APIs. All compression happens locally.

Side Effects

TypeDescription
-------------------
NETWORKHTTP to localhost:11434 only — your local Ollama instance
MEMORYResponse cache stored in-memory (Map, configurable size/TTL)
DISKNone — cache is not persisted to disk

Setup

const TokenCompressor = require('./src/token-compressor');

const compressor = new TokenCompressor({
  ollamaHost: 'localhost',      // default
  ollamaPort: 11434,            // default
  compressionModel: 'llama3.1:8b',  // default — any Ollama model works
  maxUncompressedTurns: 10,     // keep last N turns verbatim
  cacheMaxSize: 100,
  cacheTTL: 3600000             // 1 hour
});

See README.md for full API documentation and usage examples.

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-03-29 12:13 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

suspicious
查看报告

🔗 相关推荐

ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,086 📥 814,889
ai-agent

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,232 📥 268,321
content-creation

SocialPack Multi-Platform Social Media Generator

theshadowrose
通过单一简报生成多平台社交媒体帖子。支持Twitter话题串、LinkedIn、Instagram和Reddit。一次输入,覆盖所有平台。
★ 0 📥 2,008