-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🚀 add prompt caching support and improve handling
- Loading branch information
Showing
9 changed files
with
155 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
docs/src/content/docs/reference/scripts/prompt-caching.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
|
||
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
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.