返回顶部
🇺🇸 English
🇨🇳 简体中文
🇨🇳 繁體中文
🇺🇸 English
🇯🇵 日本語
🇰🇷 한국어
🇫🇷 Français
🇩🇪 Deutsch
🇪🇸 Español
🇷🇺 Русский
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
安全检测
已通过
405
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

prompt-cache

# Prompt Cache A lightweight caching layer that prevents regenerating identical content. Saved approximately 60% of API quota in production by catching duplicate prompts before they hit the API. ## How It Works 1. Normalize the prompt (lowercase, collapse whitespace) 2. Combine with context keys (user name, language, model) 3. SHA-256 hash the combined key 4. Check cache table for existing result 5. On miss: call API, store result. On hit: return cached result instantly. ## Usage ```python import prompt_cache # Check before calling expensive API cached = await prompt_cache.get_cached( prompt="Tell me a story about clouds", child_name="Sophie", language="fr" ) if cached: return cached # Free! No API call needed. # Cache miss — call the API result = await generate_story(prompt, child_name, language) # Store for next time await prompt_cache.set_cached(prompt, child_name, language, result) ``` ## Schema ```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, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (prompt_hash, child_name, language) ); ``` ## Adapt the Keys The default implementation uses `(prompt, child_name, language)` as the cache key. Adapt to your domain: - **Chat completions:** `(system_prompt, user_message, model)` - **TTS:** `(text, voice_id, model_id)` - **Image gen:** `(prompt, seed, model, size)` ## Files - `scripts/prompt_cache.py` — Cache implementation (35 lines)

标签

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-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部