Skip to content

GH-1403: Implements Anthropic's prompt caching feature to improve tok… #4199

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sobychacko
Copy link
Contributor

…en efficiency

  • Adds cache control support in AnthropicApi and AnthropicChatModel
  • Creates AnthropicCacheType enum with EPHEMERAL cache type
  • Extends AbstractMessage and UserMessage to support cache parameters
  • Updates Usage tracking to include cache-related token metrics (cacheCreationInputTokens, cacheReadInputTokens)
  • Adds integration test to verify prompt caching functionality and token usage patterns
  • Updates ContentBlock to support CacheControl parameter for low-level API usage
  • Adds comprehensive reference documentation with usage examples and best practices

This implementation follows Anthropic's prompt caching API which allows for more efficient token usage by caching frequently used prompts.

Original implementation provided by @Claudio-code (Claudio Silva Junior) See 15e5026

Fixes #1403

… to improve token efficiency

- Adds cache control support in AnthropicApi and AnthropicChatModel
- Creates AnthropicCacheType enum with EPHEMERAL cache type
- Extends AbstractMessage and UserMessage to support cache parameters
- Updates Usage tracking to include cache-related token metrics (cacheCreationInputTokens, cacheReadInputTokens)
- Adds integration test to verify prompt caching functionality and token usage patterns
- Updates ContentBlock to support CacheControl parameter for low-level API usage
- Adds comprehensive reference documentation with usage examples and best practices

This implementation follows Anthropic's prompt caching API which allows for more efficient
token usage by caching frequently used prompts.

Original implementation provided by @Claudio-code (Claudio Silva Junior)
See spring-projects@15e5026

Fixes spring-projects#1403

Signed-off-by: Soby Chacko <[email protected]>
@markpollack
Copy link
Member

Why add this to usermessage/abstract message? I though a chatoption would be sufficient. I'm concerned about having functionality in the message hiearchy that isn't universal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add suport to anthropic prompt caching
2 participants