forked from langchain4j/langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Anthropic: caching of system messages and tools (langchain4j#1826)
## Issue Closes langchain4j#1915 ## Change Implemented caching of system messages and tools for Anthropic. ## General checklist - [x] There are no breaking changes - [x] I have added unit and integration tests for my change - [x] I have manually run all the unit and integration tests in the module I have added/changed, and they are all green - [x] I have manually run all the unit and integration tests in the [core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core) and [main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j) modules, and they are all green - [X] I have added/updated the [documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs) - [ ] I have added an example in the [examples repo](https://github.com/langchain4j/langchain4j-examples) (only for "big" features) - [ ] I have added/updated [Spring Boot starter(s)](https://github.com/langchain4j/langchain4j-spring) (if applicable)
- Loading branch information
1 parent
a48bf2c
commit 33ab87d
Showing
22 changed files
with
715 additions
and
279 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
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
45 changes: 45 additions & 0 deletions
45
langchain4j-anthropic/src/main/java/dev/langchain4j/model/anthropic/AnthropicTokenUsage.java
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,45 @@ | ||
package dev.langchain4j.model.anthropic; | ||
|
||
import dev.langchain4j.model.output.TokenUsage; | ||
|
||
public class AnthropicTokenUsage extends TokenUsage { | ||
|
||
private final Integer cacheCreationInputTokens; | ||
private final Integer cacheReadInputTokens; | ||
|
||
/** | ||
* Creates a new {@link AnthropicTokenUsage} instance with the given input, output token counts | ||
* and cache creation/read input tokens. | ||
* | ||
* @param inputTokenCount The input token count, or null if unknown. | ||
* @param outputTokenCount The output token count, or null if unknown. | ||
* @param cacheCreationInputTokens The total cached token created count, or null if unknown. | ||
* @param cacheReadInputTokens The total cached token read count, or null if unknown. | ||
*/ | ||
public AnthropicTokenUsage(Integer inputTokenCount, | ||
Integer outputTokenCount, | ||
Integer cacheCreationInputTokens, | ||
Integer cacheReadInputTokens) { | ||
super(inputTokenCount, outputTokenCount); | ||
this.cacheCreationInputTokens = cacheCreationInputTokens; | ||
this.cacheReadInputTokens = cacheReadInputTokens; | ||
} | ||
|
||
/** | ||
* Returns The total cached token created count, or null if unknown. | ||
* | ||
* @return The total cached token created count, or null if unknown. | ||
*/ | ||
public Integer cacheCreationInputTokens() { | ||
return cacheCreationInputTokens; | ||
} | ||
|
||
/** | ||
* Returns The total cached token read count, or null if unknown. | ||
* | ||
* @return The total cached token read count, or null if unknown. | ||
*/ | ||
public Integer cacheReadInputTokens() { | ||
return cacheReadInputTokens; | ||
} | ||
} |
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.