-
Notifications
You must be signed in to change notification settings - Fork 15
Test prompt caching with DeepSeek V4 Flash #139
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7253008
chore: files changed vendor/tinyinference
senamakel 330c21f
test: cover live Anthropic prompt caching
senamakel c9cea89
chore: update TinyInference prompt cache provider
senamakel 6b45ee8
chore: update redacted TinyInference dependency
senamakel 667e8ff
chore: update corrected TinyInference dependency
senamakel 3a5f120
chore: update fixed TinyInference dependency
senamakel a2c3eeb
chore: update TinyInference provider contracts
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
crates/tinyagents-integration-tests/tests/live_prompt_cache.rs
This file contains hidden or 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,82 @@ | ||
| //! LIVE end-to-end proof for Anthropic prompt caching through the local ladder. | ||
| //! | ||
| //! The test is opt-in (`PROMPT_CACHE_LIVE=1`) and uses the loopback ladder's | ||
| //! Anthropic Messages-compatible endpoint. It sends two different user turns | ||
| //! under the same large cacheable system prefix, then requires the second | ||
| //! response to report provider cache-read tokens. No credential is logged. | ||
|
|
||
| use tinyinference::cache::CachePolicy; | ||
| use tinyinference::message::Message; | ||
| use tinyinference::model::{ChatModel, ModelRequest, PromptSegment, SegmentRole}; | ||
| use tinyinference::providers::anthropic::AnthropicModel; | ||
|
|
||
| const LADDER_URL: &str = "http://127.0.0.1:6969/v1"; | ||
|
|
||
| #[tokio::test] | ||
| async fn live_ladder_reuses_an_anthropic_prompt_cache_breakpoint() { | ||
| if std::env::var("PROMPT_CACHE_LIVE").as_deref() != Ok("1") { | ||
| eprintln!("skipping live prompt-cache check: set PROMPT_CACHE_LIVE=1"); | ||
| return; | ||
| } | ||
| let Ok(api_key) = std::env::var("LADDER_API_KEY") else { | ||
| eprintln!("skipping live prompt-cache check: LADDER_API_KEY is not set"); | ||
| return; | ||
| }; | ||
|
|
||
| let model = AnthropicModel::with_base_url(api_key, LADDER_URL).with_model("flash"); | ||
| // Anthropic caches only prefixes above its provider-specific minimum. This | ||
| // deliberately stays comfortably above the common 1,024-token floor while | ||
| // remaining bounded and deterministic. | ||
| let stable_prefix = format!( | ||
| "cache-test-run-{} ", | ||
| std::time::SystemTime::now() | ||
| .duration_since(std::time::UNIX_EPOCH) | ||
| .expect("system clock after Unix epoch") | ||
| .as_nanos() | ||
| ) + &std::iter::repeat_n( | ||
| "You are a precise test assistant. Preserve these operating rules exactly. ", | ||
| 180, | ||
| ) | ||
| .collect::<String>(); | ||
|
senamakel marked this conversation as resolved.
|
||
| let request = |question: &str| { | ||
| ModelRequest::new(vec![ | ||
| Message::system(stable_prefix.clone()), | ||
| Message::user(question), | ||
| ]) | ||
| .with_cache_segments(vec![ | ||
| PromptSegment { | ||
| id: "system".into(), | ||
| role: SegmentRole::System, | ||
| cacheable: true, | ||
| }, | ||
| PromptSegment { | ||
| id: "turn".into(), | ||
| role: SegmentRole::Volatile, | ||
| cacheable: false, | ||
| }, | ||
| ]) | ||
| .with_cache_policy(CachePolicy { | ||
| protect_prompt_prefix: true, | ||
| ..CachePolicy::default() | ||
| }) | ||
| .with_timeout_ms(90_000) | ||
| .with_max_tokens(8) | ||
| }; | ||
|
|
||
| let first = model | ||
| .invoke(&(), request("Reply with exactly: one")) | ||
| .await | ||
| .expect("first cached-prefix request succeeds"); | ||
| let second = model | ||
| .invoke(&(), request("Reply with exactly: two")) | ||
| .await | ||
| .expect("second cached-prefix request succeeds"); | ||
|
|
||
| let _first_usage = first.usage.expect("first response reports usage"); | ||
| let second_usage = second.usage.expect("second response reports usage"); | ||
| assert!( | ||
| second_usage.cache_read_tokens > 0, | ||
| "second request did not reuse the stable prefix (cache read tokens: {})", | ||
| second_usage.cache_read_tokens | ||
| ); | ||
| } | ||
Submodule tinyinference
updated
5 files
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fail the live test when the live gate is enabled without credentials.
When
PROMPT_CACHE_LIVE=1, a missingLADDER_API_KEYreturns success without sending either request. The live validation can therefore pass without testing prompt caching. Treat the missing key as a test failure after the live gate is enabled.Proposed fix
As described in the PR objectives, validation runs the live test with
PROMPT_CACHE_LIVE=1.📝 Committable suggestion
🤖 Prompt for AI Agents