闲社服务运行正常AI智能体自动化平台
p

提示缓存

技能标识:prompt-cache

SHA-256 prompt deduplication for LLM and TTS calls — hash normalize prompts, check cache before calling APIs, store results for instant replay. Use when making repeated or similar API calls to avoid redundant spending. Works with any database backend (SQLite, Turso, Postgres).

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

提示缓存

Prompt Cache

一个轻量级缓存层,可防止重复生成相同内容。通过在生产环境中拦截重复提示词,节省了约60%的API配额。

工作原理

  1. 1. 标准化提示词(转为小写、合并空白字符)
  2. 与上下文键(用户名、语言、模型)组合
  3. 对组合后的键进行SHA-256哈希处理
  4. 在缓存表中检查已有结果
  5. 未命中:调用API,存储结果。命中:立即返回缓存结果。

使用方法

python
import prompt_cache

在调用昂贵API前进行检查

cached = await promptcache.getcached( prompt=给我讲一个关于云的故事, child_name=苏菲, language=fr )

if cached:
return cached # 免费!无需调用API。

缓存未命中 — 调用API

result = await generatestory(prompt, childname, language)

为下次使用存储结果

await promptcache.setcached(prompt, child_name, language, result)

数据表结构

sql
CREATE TABLE IF NOT EXISTS prompt_cache (
prompt_hash TEXT NOT NULL,
child_name TEXT NOT NULL,
language TEXT NOT NULL,
story_json TEXT,
createdat DATETIME DEFAULT CURRENTTIMESTAMP,
PRIMARY KEY (prompthash, childname, language)
);

自定义键

默认实现使用(prompt, child_name, language)作为缓存键。可根据您的领域进行调整:

  • - 聊天补全: (systemprompt, usermessage, model)
  • 文本转语音: (text, voiceid, modelid)
  • 图像生成: (prompt, seed, model, size)

文件

  • - scripts/prompt_cache.py — 缓存实现(35行)

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 prompt-cache-1776285001 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 prompt-cache-1776285001 技能

通过命令行安装

skillhub install prompt-cache-1776285001

下载

⬇ 下载 prompt-cache v1.0.0(免费)

文件大小: 2.5 KB | 发布时间: 2026-4-16 18:19

v1.0.0 最新 2026-4-16 18:19
Initial release — extracted from Sandman Tales v2 hackathon
返回顶部