返回顶部
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
安全检测
已通过
421
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

prompt-cache

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

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部