Skip to content
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

Merged
merged 16 commits into from
Dec 9, 2024
Merged

Anthropic prompt caching #924

merged 16 commits into from
Dec 9, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Dec 9, 2024

Implement anthropic prompt caching


Description of Changes

  • Added cache control to prompts by introducing a new method cacheControl that takes a cache control type ("ephemeral").
  • Modified the PromptTemplateString interface to include the cacheControl method.
  • Enhanced the flexibility and behavior of prompt rendering in the context of chat messages, allowing more control over message priorty and token allocation.
  • Added support for specifying maximum estimated tokens for each prompt entry, which will help in truncating messages if they exceed the available context window.

generated by pr-describe


```js "ephemeral: true"
def("FILE", env.files, { ephemeral: true })
```

Read more about [prompt caching](/genaiscript/reference/scripts/prompt-caching).

Copy link

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 file prompt-caching.mdx. This redundancy can be avoided by linking to the existing content or consolidating it in one place.

generated by pr-docs-review-commit content-structure

Copy link

github-actions bot commented Dec 9, 2024

LGTM 🚀 The changes look good! These modifications appear to streamline the handling of cache control in prompt templates, making it more intuitive and flexible. The introduction of cacheControl should help manage ephemeral prompts more effectively. Overall, these improvements maintain code clarity and functionality without introducing any new issues that would be caught by TypeScript's type-checking.

generated by pr-review


### Anthropic

- Anthropic: it is translated into a `'cache-control': { ... }` field in the message object
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frontmatter in prompt-caching.mdx is not necessary since it's a standalone document and does not need to be included in the sidebar or have a title. This can be removed to simplify the file.

generated by pr-docs-review-commit frontmatter


### Anthropic

- Anthropic: it is translated into a `'cache-control': { ... }` field in the message object
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section on LLM provider support is duplicated between context.md and prompt-caching.mdx. This redundancy can be avoided by linking to the existing content or consolidating it in one place.

generated by pr-docs-review-commit content-structure

@waltoss
Copy link
Contributor

waltoss commented Dec 9, 2024

I love the API, I'll try it out

@pelikhan pelikhan merged commit 7bdaf4f into main Dec 9, 2024
11 checks passed
@pelikhan pelikhan deleted the anthropic-caching branch December 9, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants