-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anthropic prompt caching #924
Changes from 4 commits
97e7de6
31ba629
3c324a5
eaf1c54
a0e5594
3fe86d6
aaec8d4
d2a7c52
110200f
3ff69d3
9bcc902
96d47a6
23d851f
7bf07b5
44f113e
2cbd3d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Prompt Caching | ||
sidebar: | ||
order: 80 | ||
--- | ||
|
||
Prompt caching is a feature that can reduce processing time and costs for repetitive prompts. | ||
It is supported by various LLM providers, but the implementation may vary. | ||
|
||
- OpenAI implements an automatic [cache prefix](https://openai.com/index/api-prompt-caching/). | ||
- Anthropic supports settting [cache breakpoints](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching) | ||
|
||
## `ephemeral` | ||
|
||
You can mark `def` section or `$` function with `cacheControl` set as `"ephemeral"` to enable prompt caching optimization. This essentially means that it | ||
is acceptable for the LLM provider to cache the prompt for a short amount of time. | ||
|
||
```js | ||
def("FILE", env.files, { cacheControl: "ephemeral" }) | ||
``` | ||
|
||
```js | ||
$`Some very cool prompt`.cacheControl("ephemeral") | ||
``` | ||
|
||
## LLM provider supporet | ||
Check warning on line 26 in docs/src/content/docs/reference/scripts/prompt-caching.mdx GitHub Actions / build
|
||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In most cases, the `ephemeral` hint is ignored by LLM providers. However, the following are supported | ||
|
||
### OpenAI, Azure OpenAI | ||
|
||
[Prompt caching](https://platform.openai.com/docs/guides/prompt-caching) of the prompt prefix | ||
is automatically enabled by OpenAI. | ||
|
||
### Anthropic | ||
|
||
- Anthropic: it is translated into a `'cache-control': { ... }` field in the message object | ||
Check warning on line 37 in docs/src/content/docs/reference/scripts/prompt-caching.mdx GitHub Actions / build
Check warning on line 37 in docs/src/content/docs/reference/scripts/prompt-caching.mdx GitHub Actions / build
|
||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The frontmatter in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The section on LLM provider support is duplicated between
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,111 @@ | ||
{ | ||
"name": "genaiscript", | ||
"version": "1.82.0", | ||
"main": "built/genaiscript.cjs", | ||
"type": "commonjs", | ||
"bin": { | ||
"genaiscript": "built/genaiscript.cjs" | ||
}, | ||
"files": [ | ||
"built/genaiscript.cjs" | ||
], | ||
"publisher": "Microsoft", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/microsoft/genaiscript.git" | ||
}, | ||
"homepage": "https://microsoft.github.io/genaiscript", | ||
"keywords": [ | ||
"genai", | ||
"ai", | ||
"agentic", | ||
"agent", | ||
"cli", | ||
"prompt", | ||
"llm", | ||
"generative ai", | ||
"gpt4", | ||
"chatgpt", | ||
"ollama", | ||
"llamacpp", | ||
"chatgpt" | ||
], | ||
"description": "A CLI for GenAIScript, a generative AI scripting framework.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@azure/identity": "^4.5.0", | ||
"@inquirer/prompts": "^7.1.0", | ||
"@modelcontextprotocol/sdk": "^1.0.3", | ||
"@octokit/plugin-paginate-rest": "^11.3.6", | ||
"@octokit/plugin-retry": "^7.1.2", | ||
"@octokit/plugin-throttling": "^9.3.2", | ||
"@octokit/rest": "^21.0.2", | ||
"dockerode": "^4.0.2", | ||
"gpt-tokenizer": "^2.7.0", | ||
"html-to-text": "^9.0.5", | ||
"jimp": "^1.6.0", | ||
"mammoth": "^1.8.0", | ||
"mathjs": "^14.0.0", | ||
"tabletojson": "^4.1.5", | ||
"tsx": "^4.19.2", | ||
"turndown": "^7.2.0", | ||
"turndown-plugin-gfm": "^1.0.2", | ||
"typescript": "5.7.2", | ||
"vectra": "^0.9.0", | ||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz" | ||
}, | ||
"optionalDependencies": { | ||
"@huggingface/transformers": "^3.1.1", | ||
"@lvce-editor/ripgrep": "^1.4.0", | ||
"pdfjs-dist": "4.9.124", | ||
"playwright": "^1.49.0", | ||
"skia-canvas": "^2.0.0", | ||
"tree-sitter-wasms": "^0.1.11", | ||
"web-tree-sitter": "0.22.2" | ||
}, | ||
"engines": { | ||
"node": ">=20.0.0" | ||
}, | ||
"peerDependencies": { | ||
"promptfoo": "0.100.3" | ||
}, | ||
"devDependencies": { | ||
"@types/diff": "^6.0.0", | ||
"@types/dockerode": "^3.3.32", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/memorystream": "^0.3.4", | ||
"@types/node": "^22.10.1", | ||
"@types/papaparse": "^5.3.15", | ||
"@types/prompts": "^2.4.9", | ||
"@types/replace-ext": "^2.0.2", | ||
"@types/ws": "^8.5.13", | ||
"commander": "^12.1.0", | ||
"diff": "^7.0.0", | ||
"dotenv": "^16.4.7", | ||
"es-toolkit": "^1.29.0", | ||
"esbuild": "^0.24.0", | ||
"execa": "^9.5.1", | ||
"fs-extra": "^11.2.0", | ||
"glob": "^11.0.0", | ||
"memorystream": "^0.3.1", | ||
"node-sarif-builder": "^3.2.0", | ||
"octokit": "^4.0.2", | ||
"openai": "^4.75.0", | ||
"pretty-bytes": "^6.1.1", | ||
"replace-ext": "^2.0.0", | ||
"ws": "^8.18.0", | ||
"zx": "^8.2.4" | ||
}, | ||
"scripts": { | ||
"compile": "esbuild src/main.ts --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright --external:@inquirer/prompts --external:jimp --external:turndown --external:turndown-plugin-gfm --external:vectra --external:tabletojson --external:html-to-text --external:@octokit/rest --external:@octokit/plugin-throttling --external:@octokit/plugin-retry --external:@octokit/plugin-paginate-rest --external:skia-canvas --external:@huggingface/transformers --external:@modelcontextprotocol/sdk && node ../../scripts/patch-cli.mjs", | ||
"compile-debug": "esbuild src/main.ts --sourcemap --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright --external:@inquirer/prompts --external:jimp --external:turndown --external:turndown-plugin-gfm --external:vectra --external:tabletojson --external:html-to-text --external:@octokit/rest --external:@octokit/plugin-throttling --external:@octokit/plugin-retry --external:@octokit/plugin-paginate-rest --external:skia-canvas --external:@huggingface/transformers --external:@modelcontextprotocol/sdk", | ||
"postcompile": "node built/genaiscript.cjs info help > ../../docs/src/content/docs/reference/cli/commands.md", | ||
"vis:treemap": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.treemap.html", | ||
"vis:network": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.network.html --template network", | ||
"go": "yarn compile && node built/genaiscript.cjs", | ||
"test": "node --import tsx --test src/**.test.ts", | ||
"typecheck": "tsc -p src", | ||
"lint": "npx --yes publint" | ||
} | ||
"name": "genaiscript", | ||
"version": "1.82.0", | ||
"main": "built/genaiscript.cjs", | ||
"type": "commonjs", | ||
"bin": { | ||
"genaiscript": "built/genaiscript.cjs" | ||
}, | ||
"files": [ | ||
"built/genaiscript.cjs" | ||
], | ||
"publisher": "Microsoft", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/microsoft/genaiscript.git" | ||
}, | ||
"homepage": "https://microsoft.github.io/genaiscript", | ||
"keywords": [ | ||
"genai", | ||
"ai", | ||
"agentic", | ||
"agent", | ||
"cli", | ||
"prompt", | ||
"llm", | ||
"generative ai", | ||
"gpt4", | ||
"chatgpt", | ||
"ollama", | ||
"llamacpp", | ||
"chatgpt" | ||
], | ||
"description": "A CLI for GenAIScript, a generative AI scripting framework.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@anthropic-ai/sdk": "^0.32.1", | ||
"@azure/identity": "^4.5.0", | ||
"@inquirer/prompts": "^7.1.0", | ||
"@modelcontextprotocol/sdk": "^1.0.3", | ||
"@octokit/plugin-paginate-rest": "^11.3.6", | ||
"@octokit/plugin-retry": "^7.1.2", | ||
"@octokit/plugin-throttling": "^9.3.2", | ||
"@octokit/rest": "^21.0.2", | ||
"dockerode": "^4.0.2", | ||
"gpt-tokenizer": "^2.7.0", | ||
"html-to-text": "^9.0.5", | ||
"jimp": "^1.6.0", | ||
"mammoth": "^1.8.0", | ||
"mathjs": "^14.0.0", | ||
"tabletojson": "^4.1.5", | ||
"tsx": "^4.19.2", | ||
"turndown": "^7.2.0", | ||
"turndown-plugin-gfm": "^1.0.2", | ||
"typescript": "5.7.2", | ||
"vectra": "^0.9.0", | ||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz" | ||
}, | ||
"optionalDependencies": { | ||
"@huggingface/transformers": "^3.1.2", | ||
"@lvce-editor/ripgrep": "^1.4.0", | ||
"pdfjs-dist": "4.9.124", | ||
"playwright": "^1.49.0", | ||
"skia-canvas": "^2.0.0", | ||
"tree-sitter-wasms": "^0.1.11", | ||
"web-tree-sitter": "0.22.2" | ||
}, | ||
"engines": { | ||
"node": ">=20.0.0" | ||
}, | ||
"peerDependencies": { | ||
"promptfoo": "0.100.3" | ||
}, | ||
"devDependencies": { | ||
"@types/diff": "^6.0.0", | ||
"@types/dockerode": "^3.3.32", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/memorystream": "^0.3.4", | ||
"@types/node": "^22.10.1", | ||
"@types/papaparse": "^5.3.15", | ||
"@types/prompts": "^2.4.9", | ||
"@types/replace-ext": "^2.0.2", | ||
"@types/ws": "^8.5.13", | ||
"commander": "^12.1.0", | ||
"diff": "^7.0.0", | ||
"dotenv": "^16.4.7", | ||
"es-toolkit": "^1.29.0", | ||
"esbuild": "^0.24.0", | ||
"execa": "^9.5.1", | ||
"fs-extra": "^11.2.0", | ||
"glob": "^11.0.0", | ||
"memorystream": "^0.3.1", | ||
"node-sarif-builder": "^3.2.0", | ||
"octokit": "^4.0.2", | ||
"openai": "^4.76.0", | ||
"pretty-bytes": "^6.1.1", | ||
"replace-ext": "^2.0.0", | ||
"ws": "^8.18.0", | ||
"zx": "^8.2.4" | ||
}, | ||
"scripts": { | ||
"compile": "esbuild src/main.ts --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright --external:@inquirer/prompts --external:jimp --external:turndown --external:turndown-plugin-gfm --external:vectra --external:tabletojson --external:html-to-text --external:@octokit/rest --external:@octokit/plugin-throttling --external:@octokit/plugin-retry --external:@octokit/plugin-paginate-rest --external:skia-canvas --external:@huggingface/transformers --external:@modelcontextprotocol/sdk --external:@anthropic-ai/sdk && node ../../scripts/patch-cli.mjs", | ||
"compile-debug": "esbuild src/main.ts --sourcemap --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright --external:@inquirer/prompts --external:jimp --external:turndown --external:turndown-plugin-gfm --external:vectra --external:tabletojson --external:html-to-text --external:@octokit/rest --external:@octokit/plugin-throttling --external:@octokit/plugin-retry --external:@octokit/plugin-paginate-rest --external:skia-canvas --external:@huggingface/transformers --external:@modelcontextprotocol/sdk --external:@anthropic-ai/sdk", | ||
"postcompile": "node built/genaiscript.cjs info help > ../../docs/src/content/docs/reference/cli/commands.md", | ||
"vis:treemap": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.treemap.html", | ||
"vis:network": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.network.html --template network", | ||
"go": "yarn compile && node built/genaiscript.cjs", | ||
"test": "node --import tsx --test src/**.test.ts", | ||
"typecheck": "tsc -p src", | ||
"lint": "npx --yes publint" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for prompt caching is duplicated between
context.md
and a new fileprompt-caching.mdx
. This redundancy can be avoided by linking to the existing content or consolidating it in one place.